PageRenderTime 26ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/Test/Mono.Cecil.Tests/EventTests.cs

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