Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PropertyTests.cs « Mono.Cecil.Tests « Test - github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 587868ff78610eaef512dd72d48318b395073263 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System.Linq;

using NUnit.Framework;

namespace Mono.Cecil.Tests {

	[TestFixture]
	public class PropertyTests : BaseTestFixture {

		[Test]
		public void AbstractMethod ()
		{
			TestCSharp ("Properties.cs", module => {
				var type = module.GetType ("Foo");

				Assert.IsTrue (type.HasProperties);

				var properties = type.Properties;

				Assert.AreEqual (3, properties.Count);

				var property = properties [0];

				Assert.IsNotNull (property);
				Assert.AreEqual ("Bar", property.Name);
				Assert.IsNotNull (property.PropertyType);
				Assert.AreEqual ("System.Int32", property.PropertyType.FullName);

				Assert.IsNotNull (property.GetMethod);
				Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
				Assert.IsNull (property.SetMethod);

				property = properties [1];

				Assert.IsNotNull (property);
				Assert.AreEqual ("Baz", property.Name);
				Assert.IsNotNull (property.PropertyType);
				Assert.AreEqual ("System.String", property.PropertyType.FullName);

				Assert.IsNotNull (property.GetMethod);
				Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
				Assert.IsNotNull (property.SetMethod);
				Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);

				property = properties [2];

				Assert.IsNotNull (property);
				Assert.AreEqual ("Gazonk", property.Name);
				Assert.IsNotNull (property.PropertyType);
				Assert.AreEqual ("System.String", property.PropertyType.FullName);

				Assert.IsNull (property.GetMethod);
				Assert.IsNotNull (property.SetMethod);
				Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);
			});
		}

		[Test]
		public void OtherMethod ()
		{
			TestIL ("others.il", module => {
				var type = module.GetType ("Others");

				Assert.IsTrue (type.HasProperties);

				var properties = type.Properties;

				Assert.AreEqual (1, properties.Count);

				var property = properties [0];

				Assert.IsNotNull (property);
				Assert.AreEqual ("Context", property.Name);
				Assert.IsNotNull (property.PropertyType);
				Assert.AreEqual ("System.String", property.PropertyType.FullName);

				Assert.IsTrue (property.HasOtherMethods);

				Assert.AreEqual (2, property.OtherMethods.Count);

				var other = property.OtherMethods [0];
				Assert.AreEqual ("let_Context", other.Name);

				other = property.OtherMethods [1];
				Assert.AreEqual ("bet_Context", other.Name);
			});
		}

		[Test]
		public void SetOnlyIndexer ()
		{
			TestCSharp ("Properties.cs", module => {
				var type = module.GetType ("Bar");
				var indexer = type.Properties.Where (property => property.Name == "Item").First ();

				var parameters = indexer.Parameters;

				Assert.AreEqual (2, parameters.Count);
				Assert.AreEqual ("System.Int32", parameters [0].ParameterType.FullName);
				Assert.AreEqual ("System.String", parameters [1].ParameterType.FullName);
			});
		}

		[Test]
		public void ReadSemanticsFirst ()
		{
			TestCSharp ("Properties.cs", module => {
				var type = module.GetType ("Baz");
				var setter = type.GetMethod ("set_Bingo");

				Assert.AreEqual (MethodSemanticsAttributes.Setter, setter.SemanticsAttributes);

				var property = type.Properties.Where (p => p.Name == "Bingo").First ();

				Assert.AreEqual (setter, property.SetMethod);
				Assert.AreEqual (type.GetMethod ("get_Bingo"), property.GetMethod);
			});
		}

		[Test]
		public void UnattachedProperty ()
		{
			var property = new PropertyDefinition ("Property", PropertyAttributes.None, typeof (int).ToDefinition ());

			Assert.IsNull (property.GetMethod);
		}
	}
}