You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -7,106 +7,122 @@ namespace Mono.Cecil.Tests {
|
||||
[TestFixture]
|
||||
public class PropertyTests : BaseTestFixture {
|
||||
|
||||
[TestCSharp ("Properties.cs")]
|
||||
public void AbstractMethod (ModuleDefinition module)
|
||||
[Test]
|
||||
public void AbstractMethod ()
|
||||
{
|
||||
var type = module.GetType ("Foo");
|
||||
TestCSharp ("Properties.cs", module => {
|
||||
var type = module.GetType ("Foo");
|
||||
|
||||
Assert.IsTrue (type.HasProperties);
|
||||
Assert.IsTrue (type.HasProperties);
|
||||
|
||||
var properties = type.Properties;
|
||||
var properties = type.Properties;
|
||||
|
||||
Assert.AreEqual (3, properties.Count);
|
||||
Assert.AreEqual (3, properties.Count);
|
||||
|
||||
var property = properties [0];
|
||||
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);
|
||||
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);
|
||||
Assert.IsNotNull (property.GetMethod);
|
||||
Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
|
||||
Assert.IsNull (property.SetMethod);
|
||||
|
||||
property = properties [1];
|
||||
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);
|
||||
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);
|
||||
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];
|
||||
property = properties [2];
|
||||
|
||||
Assert.IsNotNull (property);
|
||||
Assert.AreEqual ("Gazonk", property.Name);
|
||||
Assert.IsNotNull (property.PropertyType);
|
||||
Assert.AreEqual ("System.String", property.PropertyType.FullName);
|
||||
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);
|
||||
Assert.IsNotNull (property.SetMethod);
|
||||
Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);
|
||||
}
|
||||
|
||||
[TestIL ("others.il")]
|
||||
public void OtherMethod (ModuleDefinition 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);
|
||||
}
|
||||
|
||||
[TestCSharp ("Properties.cs")]
|
||||
public void SetOnlyIndexer (ModuleDefinition 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);
|
||||
}
|
||||
|
||||
[TestCSharp ("Properties.cs")]
|
||||
public void ReadSemanticsFirst (ModuleDefinition 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user