PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/rocks/Test/Mono.Cecil.Tests/TypeDefinitionRocksTests.cs

http://github.com/jbevain/cecil
C# | 97 lines | 75 code | 22 blank | 0 comment | 0 complexity | b7fb2c7316b569eecd8a1d2dfebfb5e2 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Mono.Cecil.Rocks;
 5
 6using NUnit.Framework;
 7
 8namespace Mono.Cecil.Tests {
 9
10	[TestFixture]
11	public class TypeDefinitionRocksTests {
12
13		class Foo {
14
15			static Foo ()
16			{
17			}
18
19			public Foo (int a)
20			{
21			}
22
23			public Foo (int a, string s)
24			{
25			}
26
27			public static void Bar ()
28			{
29			}
30
31			void Baz ()
32			{
33			}
34		}
35
36		[Test]
37		public void GetConstructors ()
38		{
39			var foo = typeof (Foo).ToDefinition ();
40			var ctors = foo.GetConstructors ().Select (ctor => ctor.FullName);
41
42			var expected = new [] {
43				"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.cctor()",
44				"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.ctor(System.Int32)",
45				"System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.ctor(System.Int32,System.String)",
46			};
47
48			AssertSet (expected, ctors);
49		}
50
51		static void AssertSet<T> (IEnumerable<T> expected, IEnumerable<T> actual)
52		{
53			Assert.IsFalse (expected.Except (actual).Any ());
54			Assert.IsTrue (expected.Intersect (actual).SequenceEqual (expected));
55		}
56
57		[Test]
58		public void GetStaticConstructor ()
59		{
60			var foo = typeof (Foo).ToDefinition ();
61			var cctor = foo.GetStaticConstructor ();
62
63			Assert.IsNotNull (cctor);
64			Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::.cctor()", cctor.FullName);
65		}
66
67		[Test]
68		public void GetMethods ()
69		{
70			var foo = typeof (Foo).ToDefinition ();
71			var methods = foo.GetMethods ().ToArray ();
72
73			Assert.AreEqual (2, methods.Length);
74			Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::Bar()", methods [0].FullName);
75			Assert.AreEqual ("System.Void Mono.Cecil.Tests.TypeDefinitionRocksTests/Foo::Baz()", methods [1].FullName);
76		}
77
78		enum Pan : byte {
79			Pin,
80			Pon,
81		}
82
83		[Test]
84		public void GetEnumUnderlyingType ()
85		{
86			var pan = typeof (Pan).ToDefinition ();
87
88			Assert.IsNotNull (pan);
89			Assert.IsTrue (pan.IsEnum);
90
91			var underlying_type = pan.GetEnumUnderlyingType ();
92			Assert.IsNotNull (underlying_type);
93
94			Assert.AreEqual ("System.Byte", underlying_type.FullName);
95		}
96	}
97}