/// </summary>
[TestFixture]
- public class CustomAttributeBuilderTest : Assertion
+ public class CustomAttributeBuilderTest
{
// the CustomAttribute class is used for testing and it has to be public
//check the validity of the attribute associated with Print method
object [] methodAttrs = myType.GetMember ("Print") [0].GetCustomAttributes (true);
- AssertEquals ("#method Print has exactly one attribute", methodAttrs.Length, 1);
+ Assert.AreEqual (methodAttrs.Length, 1, "#1");
CustomAttribute methodAttr = methodAttrs [0] as CustomAttribute;
- AssertEquals ("#AttributeOne", methodAttr.AttributeOne, "hello");
- AssertEquals ("#AttributeTwo", methodAttr.AttributeTwo, "world");
+ Assert.AreEqual (methodAttr.AttributeOne, "hello", "#2");
+ Assert.AreEqual (methodAttr.AttributeTwo, "world", "#3");
//check the validity of the attribute associated with Str feild
object [] fieldAttrs = myType.GetField ("Str").GetCustomAttributes (true);
- AssertEquals("#feild Str has exactly one attribute", fieldAttrs.Length, 1);
+ Assert.AreEqual(fieldAttrs.Length, 1, "#4");
CustomAttribute fieldAttr = fieldAttrs [0] as CustomAttribute;
- AssertEquals("#AttributeOne", fieldAttr.AttributeOne, "one");
- AssertEquals("#AttributeTwo", fieldAttr.AttributeTwo, "two");
+ Assert.AreEqual(fieldAttr.AttributeOne, "one", "#5");
+ Assert.AreEqual(fieldAttr.AttributeTwo, "two", "#6");
}
[Test]
//check the validity of the attribute associated with Print method
object [] customAttrs = myType.GetCustomAttributes (false);
- AssertEquals ("#TestType has exactly one attribute", customAttrs.Length, 1);
+ Assert.AreEqual (customAttrs.Length, 1, "1");
//Custom Attributes of TestType
CustomAttribute attr = customAttrs [0] as CustomAttribute;
- AssertEquals ("#AttributeOne", attr.AttributeOne, "Test");
- AssertEquals ("#AttributeTwo", attr.AttributeTwo, "Type");
- AssertEquals ("#CustomAttribute.Feild",attr.Feild, "TestCase");
+ Assert.AreEqual (attr.AttributeOne, "Test", "#2");
+ Assert.AreEqual (attr.AttributeTwo, "Type", "#3");
+ Assert.AreEqual (attr.Feild, "TestCase", "#4");
}
//check the validity of the attribute associated with Print method
object [] customAttrs = myType.GetCustomAttributes (false);
- AssertEquals ("#TestType has exactly one attribute", customAttrs.Length , 1);
+ Assert.AreEqual (customAttrs.Length , 1, "#1");
//Custom Attributes of TestType
CustomAttribute attr = customAttrs [0] as CustomAttribute;
- AssertEquals("#AttributeOne", attr.AttributeOne, "TestCase");
+ Assert.AreEqual(attr.AttributeOne, "TestCase", "#2");
}
[Test]
//check the validity of the attribute associated with Print method
object [] customAttrs = myType.GetCustomAttributes (false);
- AssertEquals("#TestType has exactly one attribute",customAttrs.Length , 1);
+ Assert.AreEqual(customAttrs.Length , 1, "#1");
//Custom Attributes of TestType
CustomAttribute attr = customAttrs [0] as CustomAttribute;
- AssertEquals ("#AttributeOne", attr.AttributeOne, "TestCase");
- AssertEquals ("#Field ", attr.Feild, "FieldValue");
+ Assert.AreEqual (attr.AttributeOne, "TestCase", "#2");
+ Assert.AreEqual (attr.Feild, "FieldValue", "#3");
}
typeof (CustomAttribute).GetConstructor (BindingFlags.Instance |
BindingFlags.NonPublic, null, ctorParams, null);
- Assert ("#Custom Attribute has private constuctor ", classCtorInfo != null);
+ Assert.IsNotNull (classCtorInfo);
CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
classCtorInfo,
ConstructorInfo classCtorInfo =
typeof (CustomAttribute).GetConstructor (ctorParams);
- Assert ("#ctor not null", classCtorInfo != null);
+ Assert.IsNotNull (classCtorInfo);
CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
classCtorInfo,
new object [] { "1","2" },
ConstructorInfo classCtorInfo =
typeof (CustomAttribute).GetConstructor (ctorParams);
- Assert ("#ctor not null", classCtorInfo != null);
+ Assert.IsNotNull (classCtorInfo);
CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
classCtorInfo,
null, //<-- here is the error
ConstructorInfo classCtorInfo =
typeof (CustomAttribute).GetConstructor (ctorParams);
- Assert ("#ctor not null", classCtorInfo != null);
+ Assert.IsNotNull (classCtorInfo);
CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
classCtorInfo,
new object [] { "one","two" },
ConstructorInfo classCtorInfo =
typeof (CustomAttribute).GetConstructor (ctorParams);
- Assert ("#ctor not null", classCtorInfo != null);
+ Assert.IsNotNull (classCtorInfo);
CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
classCtorInfo,
new object [] { "one","two" },
null // <-- here is the error
);
}
+
+ class C {
+ public C (object i) {
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ObjectParam_UserDefinedClass ()
+ {
+ var cab = new CustomAttributeBuilder(
+ typeof (C).GetConstructors ()[0],
+ new object[] { new C (1) });
+ }
}
}