using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
+using System.Threading;
namespace MonoTests.System.ComponentModel.Design.Serialization {
}
[Test]
- public void Constructor_Null_ICollection ()
+ public void Constructor0_Arguments_Mismatch ()
{
- InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
- Assert.AreEqual (0, id.Arguments.Count, "Arguments");
- Assert.IsTrue (id.IsComplete, "IsComplete");
- Assert.IsNull (id.MemberInfo, "MemberInfo");
+ try {
+ new InstanceDescriptor (ci, null);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Length mismatch
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ Assert.IsNull (ex.ParamName, "#B5");
+ }
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
- public void Constructor_MemberInfo_Null ()
+ public void Constructor0_MemberInfo_Type ()
{
- new InstanceDescriptor (ci, null);
- // mismatch for required parameters
+ Type type = typeof (Uri);
+ InstanceDescriptor id = new InstanceDescriptor (type,
+ new object [] { url });
+ Assert.AreEqual (1, id.Arguments.Count, "#1");
+ Assert.IsTrue (id.IsComplete, "#2");
+ Assert.AreSame (type, id.MemberInfo, "#3");
+ Assert.IsNull (id.Invoke (), "#4");
+ }
+
+ [Test]
+ public void Constructor_Null_ICollection ()
+ {
+ InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
+ Assert.AreEqual (0, id.Arguments.Count, "#1");
+ Assert.IsTrue (id.IsComplete, "#2");
+ Assert.IsNull (id.MemberInfo, "#3");
+ Assert.IsNull (id.Invoke (), "#4");
}
[Test]
public void Constructor_Null_ICollection_Boolean ()
{
InstanceDescriptor id = new InstanceDescriptor (null, new object[] { }, true);
- Assert.AreEqual (0, id.Arguments.Count, "Arguments");
- Assert.IsTrue (id.IsComplete, "IsComplete");
- Assert.IsNull (id.MemberInfo, "MemberInfo");
+ Assert.AreEqual (0, id.Arguments.Count, "#1");
+ Assert.IsTrue (id.IsComplete, "#2");
+ Assert.IsNull (id.MemberInfo, "#3");
+ Assert.IsNull (id.Invoke (), "#4");
}
[Test]
Uri uri = (Uri) id.Invoke ();
Assert.AreEqual (url, uri.AbsoluteUri, "Invoke");
}
+
+ [Test]
+ public void Field_Arguments_Empty ()
+ {
+ FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");
+
+ InstanceDescriptor id = new InstanceDescriptor (fi, new object [0]);
+ Assert.AreEqual (0, id.Arguments.Count, "#1");
+ Assert.IsTrue (id.IsComplete, "#2");
+ Assert.AreSame (fi, id.MemberInfo, "#3");
+ Assert.IsNotNull (id.Invoke (), "#4");
+ }
+
+ [Test]
+ public void Field_Arguments_Mismatch ()
+ {
+ FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");
+
+ try {
+ new InstanceDescriptor (fi, new object [] { url });
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Parameter must be static
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
+ }
+
+ [Test]
+ public void Field_Arguments_Null ()
+ {
+ FieldInfo fi = typeof (Uri).GetField ("SchemeDelimiter");
+
+ InstanceDescriptor id = new InstanceDescriptor (fi, null);
+ Assert.AreEqual (0, id.Arguments.Count, "#1");
+ Assert.IsTrue (id.IsComplete, "#2");
+ Assert.AreSame (fi, id.MemberInfo, "#3");
+ Assert.IsNotNull (id.Invoke (), "#4");
+ }
+
+ [Test]
+ public void Field_MemberInfo_NonStatic ()
+ {
+ FieldInfo fi = typeof (InstanceField).GetField ("Name");
+
+ try {
+ new InstanceDescriptor (fi, null);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Parameter must be static
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
+ }
+
+ [Test]
+ public void Property_Arguments_Mismatch ()
+ {
+#if MOBILE
+ // ensure the property is not linked out of the application since it make the test fails
+ Assert.IsNotNull (Thread.CurrentPrincipal, "pre-test");
+#endif
+ PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");
+
+ InstanceDescriptor id = new InstanceDescriptor (pi, new object [] { url });
+ Assert.AreEqual (1, id.Arguments.Count, "#1");
+ object [] arguments = new object [id.Arguments.Count];
+ id.Arguments.CopyTo (arguments, 0);
+ Assert.AreSame (url, arguments [0], "#2");
+ Assert.IsTrue (id.IsComplete, "#3");
+ Assert.AreSame (pi, id.MemberInfo, "#4");
+ try {
+ id.Invoke ();
+ Assert.Fail ("#5");
+ } catch (TargetParameterCountException) {
+ }
+ }
+
+ [Test]
+ public void Property_Arguments_Null ()
+ {
+#if MOBILE
+ // ensure the property is not linked out of the application since it make the test fails
+ Assert.IsNotNull (Thread.CurrentPrincipal, "pre-test");
+#endif
+ PropertyInfo pi = typeof (Thread).GetProperty ("CurrentPrincipal");
+
+ InstanceDescriptor id = new InstanceDescriptor (pi, null);
+ Assert.AreEqual (0, id.Arguments.Count, "#1");
+ Assert.IsTrue (id.IsComplete, "#2");
+ Assert.AreSame (pi, id.MemberInfo, "#3");
+ Assert.IsNotNull (id.Invoke (), "#4");
+ }
+
+ [Test]
+ public void Property_MemberInfo_NonStatic ()
+ {
+ PropertyInfo pi = typeof (Uri).GetProperty ("Host");
+
+ try {
+ new InstanceDescriptor (pi, null);
+ Assert.Fail ("#A1");
+ } catch (ArgumentException ex) {
+ // Parameter must be static
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ Assert.IsNull (ex.ParamName, "#A5");
+ }
+
+ try {
+ new InstanceDescriptor (pi, null, false);
+ Assert.Fail ("#B1");
+ } catch (ArgumentException ex) {
+ // Parameter must be static
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ Assert.IsNull (ex.ParamName, "#B5");
+ }
+ }
+
+ [Test]
+ public void Property_MemberInfo_WriteOnly ()
+ {
+ PropertyInfo pi = typeof (WriteOnlyProperty).GetProperty ("Name");
+
+ try {
+ new InstanceDescriptor (pi, null);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Parameter must be readable
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
+ }
+
+ class WriteOnlyProperty
+ {
+ public static string Name {
+ set {
+ }
+ }
+ }
+
+ public class InstanceField
+ {
+ public string Name;
+ }
}
}