PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Mono.Cecil/Test/Mono.Cecil.Tests/PropertyTests.cs

http://github.com/icsharpcode/ILSpy
C# | 112 lines | 79 code | 33 blank | 0 comment | 2 complexity | e1002736bb8b2dd65a659e5d54e77947 MD5 | raw file
  1using System.Linq;
  2
  3using NUnit.Framework;
  4
  5namespace Mono.Cecil.Tests {
  6
  7	[TestFixture]
  8	public class PropertyTests : BaseTestFixture {
  9
 10		[TestCSharp ("Properties.cs")]
 11		public void AbstractMethod (ModuleDefinition module)
 12		{
 13			var type = module.GetType ("Foo");
 14
 15			Assert.IsTrue (type.HasProperties);
 16
 17			var properties = type.Properties;
 18
 19			Assert.AreEqual (3, properties.Count);
 20
 21			var property = properties [0];
 22
 23			Assert.IsNotNull (property);
 24			Assert.AreEqual ("Bar", property.Name);
 25			Assert.IsNotNull (property.PropertyType);
 26			Assert.AreEqual ("System.Int32", property.PropertyType.FullName);
 27
 28			Assert.IsNotNull (property.GetMethod);
 29			Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
 30			Assert.IsNull (property.SetMethod);
 31
 32			property = properties [1];
 33
 34			Assert.IsNotNull (property);
 35			Assert.AreEqual ("Baz", property.Name);
 36			Assert.IsNotNull (property.PropertyType);
 37			Assert.AreEqual ("System.String", property.PropertyType.FullName);
 38
 39			Assert.IsNotNull (property.GetMethod);
 40			Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
 41			Assert.IsNotNull (property.SetMethod);
 42			Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);
 43
 44			property = properties [2];
 45
 46			Assert.IsNotNull (property);
 47			Assert.AreEqual ("Gazonk", property.Name);
 48			Assert.IsNotNull (property.PropertyType);
 49			Assert.AreEqual ("System.String", property.PropertyType.FullName);
 50
 51			Assert.IsNull (property.GetMethod);
 52			Assert.IsNotNull (property.SetMethod);
 53			Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);
 54		}
 55
 56		[TestIL ("others.il")]
 57		public void OtherMethod (ModuleDefinition module)
 58		{
 59			var type = module.GetType ("Others");
 60
 61			Assert.IsTrue (type.HasProperties);
 62
 63			var properties = type.Properties;
 64
 65			Assert.AreEqual (1, properties.Count);
 66
 67			var property = properties [0];
 68
 69			Assert.IsNotNull (property);
 70			Assert.AreEqual ("Context", property.Name);
 71			Assert.IsNotNull (property.PropertyType);
 72			Assert.AreEqual ("System.String", property.PropertyType.FullName);
 73
 74			Assert.IsTrue (property.HasOtherMethods);
 75
 76			Assert.AreEqual (2, property.OtherMethods.Count);
 77
 78			var other = property.OtherMethods [0];
 79			Assert.AreEqual ("let_Context", other.Name);
 80
 81			other = property.OtherMethods [1];
 82			Assert.AreEqual ("bet_Context", other.Name);
 83		}
 84
 85		[TestCSharp ("Properties.cs")]
 86		public void SetOnlyIndexer (ModuleDefinition module)
 87		{
 88			var type = module.GetType ("Bar");
 89			var indexer = type.Properties.Where (property => property.Name == "Item").First ();
 90
 91			var parameters = indexer.Parameters;
 92
 93			Assert.AreEqual (2, parameters.Count);
 94			Assert.AreEqual ("System.Int32", parameters [0].ParameterType.FullName);
 95			Assert.AreEqual ("System.String", parameters [1].ParameterType.FullName);
 96		}
 97
 98		[TestCSharp ("Properties.cs")]
 99		public void ReadSemanticsFirst (ModuleDefinition module)
100		{
101			var type = module.GetType ("Baz");
102			var setter = type.GetMethod ("set_Bingo");
103
104			Assert.AreEqual (MethodSemanticsAttributes.Setter, setter.SemanticsAttributes);
105
106			var property = type.Properties.Where (p => p.Name == "Bingo").First ();
107
108			Assert.AreEqual (setter, property.SetMethod);
109			Assert.AreEqual (type.GetMethod ("get_Bingo"), property.GetMethod);
110		}
111	}
112}