forked from jbevain/cecil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventTests.cs
79 lines (56 loc) · 1.81 KB
/
EventTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using Mono.Cecil;
using Mono.Cecil.Metadata;
using NUnit.Framework;
namespace Mono.Cecil.Tests {
[TestFixture]
public class EventTests : BaseTestFixture {
[Test]
public void AbstractMethod ()
{
TestCSharp ("Events.cs", module => {
var type = module.GetType ("Foo");
Assert.IsTrue (type.HasEvents);
var events = type.Events;
Assert.AreEqual (1, events.Count);
var @event = events [0];
Assert.IsNotNull (@event);
Assert.AreEqual ("Bar", @event.Name);
Assert.IsNotNull (@event.EventType);
Assert.AreEqual ("Pan", @event.EventType.FullName);
Assert.IsNotNull (@event.AddMethod);
Assert.AreEqual (MethodSemanticsAttributes.AddOn, @event.AddMethod.SemanticsAttributes);
Assert.IsNotNull (@event.RemoveMethod);
Assert.AreEqual (MethodSemanticsAttributes.RemoveOn, @event.RemoveMethod.SemanticsAttributes);
});
}
[Test]
public void OtherMethod ()
{
TestIL ("others.il", module => {
var type = module.GetType ("Others");
Assert.IsTrue (type.HasEvents);
var events = type.Events;
Assert.AreEqual (1, events.Count);
var @event = events [0];
Assert.IsNotNull (@event);
Assert.AreEqual ("Handler", @event.Name);
Assert.IsNotNull (@event.EventType);
Assert.AreEqual ("System.EventHandler", @event.EventType.FullName);
Assert.IsTrue (@event.HasOtherMethods);
Assert.AreEqual (2, @event.OtherMethods.Count);
var other = @event.OtherMethods [0];
Assert.AreEqual ("dang_Handler", other.Name);
other = @event.OtherMethods [1];
Assert.AreEqual ("fang_Handler", other.Name);
});
}
[Test]
public void UnattachedEvent ()
{
var int32 = typeof (int).ToDefinition ();
var evt = new EventDefinition ("Event", EventAttributes.None, int32);
Assert.AreEqual (null, evt.AddMethod);
}
}
}