* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System / Test / System.ComponentModel.Design.Serialization / InstanceDescriptorTest.cs
1 //
2 // InstanceDescriptorTest.cs - Unit tests for 
3 //      System.ComponentModel.Design.Serialization.InstanceDescriptor
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31
32 using System;
33 using System.ComponentModel;
34 using System.ComponentModel.Design.Serialization;
35 using System.Globalization;
36 using System.Reflection;
37
38 namespace MonoTests.System.ComponentModel.Design.Serialization {
39
40         [TestFixture]
41         public class InstanceDescriptorTest {
42
43                 private const string url = "http://www.mono-project.com/";
44                 private ConstructorInfo ci;
45
46                 [TestFixtureSetUp]
47                 public void FixtureSetUp ()
48                 {
49                         ci = typeof (Uri).GetConstructor (new Type[1] { typeof (string) });
50                 }
51
52                 [Test]
53                 public void Constructor_Null_ICollection ()
54                 {
55                         InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
56                         Assert.AreEqual (0, id.Arguments.Count, "Arguments");
57                         Assert.IsTrue (id.IsComplete, "IsComplete");
58                         Assert.IsNull (id.MemberInfo, "MemberInfo");
59                 }
60
61                 [Test]
62                 [ExpectedException (typeof (ArgumentException))]
63                 public void Constructor_MemberInfo_Null ()
64                 {
65                         new InstanceDescriptor (ci, null);
66                         // mismatch for required parameters
67                 }
68
69                 [Test]
70                 public void Constructor_MemberInfo_ICollection ()
71                 {
72                         InstanceDescriptor id = new InstanceDescriptor (ci, new object[] { url });
73                         Assert.AreEqual (1, id.Arguments.Count, "Arguments");
74                         Assert.IsTrue (id.IsComplete, "IsComplete");
75                         Assert.AreSame (ci, id.MemberInfo, "MemberInfo");
76                         Uri uri = (Uri) id.Invoke ();
77                         Assert.AreEqual (url, uri.AbsoluteUri, "Invoke");
78                 }
79
80                 [Test]
81                 public void Constructor_Null_ICollection_Boolean ()
82                 {
83                         InstanceDescriptor id = new InstanceDescriptor (null, new object[] { }, true);
84                         Assert.AreEqual (0, id.Arguments.Count, "Arguments");
85                         Assert.IsTrue (id.IsComplete, "IsComplete");
86                         Assert.IsNull (id.MemberInfo, "MemberInfo");
87                 }
88
89                 [Test]
90                 [ExpectedException (typeof (ArgumentException))]
91                 public void Constructor_MemberInfo_Null_Boolean ()
92                 {
93                         new InstanceDescriptor (ci, null, false);
94                         // mismatch for required parameters
95                 }
96
97                 [Test]
98                 public void Constructor_MemberInfo_ICollection_Boolean ()
99                 {
100                         InstanceDescriptor id = new InstanceDescriptor (ci, new object[] { url }, false);
101                         Assert.AreEqual (1, id.Arguments.Count, "Arguments");
102                         Assert.IsFalse (id.IsComplete, "IsComplete");
103                         Assert.AreSame (ci, id.MemberInfo, "MemberInfo");
104                         Uri uri = (Uri) id.Invoke ();
105                         Assert.AreEqual (url, uri.AbsoluteUri, "Invoke");
106                 }
107         }
108 }