Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
5bf33919
Commit
5bf33919
authored
Dec 02, 2019
by
Vinicius Jarina
Browse files
[Test] Added `RemoveEventAction` unit test
parent
508d813c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Method/RegisterEventHandler.cs
View file @
5bf33919
...
...
@@ -22,6 +22,11 @@ namespace NLua.Method
public
Delegate
Add
(
LuaFunction
function
)
{
Delegate
handlerDelegate
=
CodeGeneration
.
Instance
.
GetDelegate
(
_eventInfo
.
EventHandlerType
,
function
);
return
Add
(
handlerDelegate
);
}
public
Delegate
Add
(
Delegate
handlerDelegate
)
{
_eventInfo
.
AddEventHandler
(
_target
,
handlerDelegate
);
_pendingEvents
.
Add
(
handlerDelegate
,
this
);
...
...
tests/src/LuaTests.cs
View file @
5bf33919
...
...
@@ -2613,6 +2613,52 @@ namespace NLuaTest
}
}
Entity
myEntity
;
void
OnMyClicked
(
object
sender
,
EventArgs
args
)
{
Console
.
WriteLine
(
"MyClicked"
);
myEntity
.
Property
=
myEntity
.
Property
+
"B"
;
}
[
Test
]
public
void
RemoveEventAction
()
{
using
(
var
lua
=
new
Lua
())
{
myEntity
=
new
Entity
();
myEntity
.
Property
=
"A"
;
lua
[
"obj"
]
=
myEntity
;
lua
[
"myClicked"
]
=
(
EventHandler
<
EventArgs
>)
OnMyClicked
;
lua
.
DoString
(
@"
obj.Clicked:Add(myClicked);
obj:Click();
obj.Clicked:Remove(myClicked);
obj:Click();
"
);
Assert
.
AreEqual
(
"AB"
,
myEntity
.
Property
,
"#1"
);
lua
.
DoString
(
@"
local f = function()
obj.Property = obj.Property .. 'C'
end
local del = obj.Clicked:Add(f);
obj:Click();
obj.Clicked:Remove(del);
obj:Click();
"
);
Assert
.
AreEqual
(
"ABC"
,
myEntity
.
Property
,
"#1"
);
}
}
private
void
WriteBinary
(
byte
[]
buffer
)
{
byte
[]
expected
=
{
1
,
2
,
3
,
0x3f
,
0x40
,
0xff
,
0xf3
,
0x9f
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment