summaryrefslogtreecommitdiff
path: root/mcs/class/System/Test/System.ComponentModel/DesignerAttributeTest.cs
blob: e2998dbf68c65574734c100397a2eb81d73dfecf (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// System.ComponentModel.DesignerAttribute test cases
//
// Authors:
//      Gert Driesen (drieseng@users.sourceforge.net
//
// (c) 2008 Gert Driesen
//

using System;
using System.ComponentModel;
using System.ComponentModel.Design;

using NUnit.Framework;

namespace MonoTests.System.ComponentModel 
{
	[TestFixture]
	public class DesignerAttributeTest
	{
		[Test] // ctor (String)
		public void Constructor1 ()
		{
			DesignerAttribute da;

			da = new DesignerAttribute ("CategoryType");
			Assert.AreEqual (typeof (IDesigner).FullName, da.DesignerBaseTypeName, "#A1");
			Assert.AreEqual ("CategoryType", da.DesignerTypeName, "#A2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + da.DesignerBaseTypeName, da.TypeId, "#A3");

			da = new DesignerAttribute ("Mono.Components.CategoryType");
			Assert.AreEqual (typeof (IDesigner).FullName, da.DesignerBaseTypeName, "#B1");
			Assert.AreEqual ("Mono.Components.CategoryType", da.DesignerTypeName, "#B2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + da.DesignerBaseTypeName, da.TypeId, "#B3");

			da = new DesignerAttribute (string.Empty);
			Assert.AreEqual (typeof (IDesigner).FullName, da.DesignerBaseTypeName, "#C1");
			Assert.AreEqual (string.Empty, da.DesignerTypeName, "#C2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + da.DesignerBaseTypeName, da.TypeId, "#C3");
		}

		[Test]
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor1_DesignerTypeName_Null ()
		{
			new DesignerAttribute ((string) null);
		}

		[Test] // ctor (Type)
		public void Constructor2 ()
		{
			DesignerAttribute da = new DesignerAttribute (typeof (string));
			Assert.AreEqual (typeof (IDesigner).FullName, da.DesignerBaseTypeName, "#1");
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, da.DesignerTypeName, "#2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + da.DesignerBaseTypeName, da.TypeId, "#3");
		}

		[Test]
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor2_DesignerType_Null ()
		{
			new DesignerAttribute ((Type) null);
		}

		[Test] // ctor (String, String)
		public void Constructor3 ()
		{
			DesignerAttribute da;

			da = new DesignerAttribute ("Mono.Components.CategoryType", "Mono.Design.CompositeAttribute");
			Assert.AreEqual ("Mono.Design.CompositeAttribute", da.DesignerBaseTypeName, "#A1");
			Assert.AreEqual ("Mono.Components.CategoryType", da.DesignerTypeName, "#A2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + da.DesignerBaseTypeName, da.TypeId, "#A3");

			da = new DesignerAttribute ("CategoryType", "CompositeAttribute");
			Assert.AreEqual ("CompositeAttribute", da.DesignerBaseTypeName, "#B1");
			Assert.AreEqual ("CategoryType", da.DesignerTypeName, "#B2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + da.DesignerBaseTypeName, da.TypeId, "#B3");

			da = new DesignerAttribute (string.Empty, string.Empty);
			Assert.AreEqual (string.Empty, da.DesignerBaseTypeName, "#C1");
			Assert.AreEqual (string.Empty, da.DesignerTypeName, "#C2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName, da.TypeId, "#C3");
		}

		[Test]
		public void Constructor3_DesignerBaseType_Null ()
		{
			DesignerAttribute da = new DesignerAttribute (
				"CategoryType", (string) null);
			Assert.IsNull (da.DesignerBaseTypeName, "#1");
			Assert.AreEqual ("CategoryType", da.DesignerTypeName, "#2");
			try {
				object typeId = da.TypeId;
				Assert.Fail ("#3: " + typeId);
			} catch (NullReferenceException) {
			}
		}

		[Test]
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor3_DesignerTypeName_Null ()
		{
			new DesignerAttribute ((string) null, "Mono.Design.CompositeAttribute");
		}

		[Test] // ctor (String, Type)
		public void Constructor4 ()
		{
			DesignerAttribute da;

			da = new DesignerAttribute ("Mono.Components.CategoryType", typeof (string));
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, da.DesignerBaseTypeName, "#A1");
			Assert.AreEqual ("Mono.Components.CategoryType", da.DesignerTypeName, "#A2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + typeof (string).FullName, da.TypeId, "#A3");

			da = new DesignerAttribute ("CategoryType", typeof (int));
			Assert.AreEqual (typeof (int).AssemblyQualifiedName, da.DesignerBaseTypeName, "#B1");
			Assert.AreEqual ("CategoryType", da.DesignerTypeName, "#B2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + typeof (int).FullName, da.TypeId, "#B3");

			da = new DesignerAttribute (string.Empty, typeof (string));
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, da.DesignerBaseTypeName, "#C1");
			Assert.AreEqual (string.Empty, da.DesignerTypeName, "#C2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + typeof (string).FullName, da.TypeId, "#C3");
		}

		[Test]
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor4_DesignerBaseTypeName_Null ()
		{
			new DesignerAttribute ("CategoryType", (Type) null);
		}

		[Test]
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor4_DesignerTypeName_Null ()
		{
			new DesignerAttribute ((string) null, typeof (string));
		}

		[Test] // ctor (Type, Type)
		public void Constructor5 ()
		{
			DesignerAttribute da;

			da = new DesignerAttribute (typeof (int), typeof (string));
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, da.DesignerBaseTypeName, "#A1");
			Assert.AreEqual (typeof (int).AssemblyQualifiedName, da.DesignerTypeName, "#A2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + typeof (string).FullName, da.TypeId, "#A3");

			da = new DesignerAttribute (typeof (string), typeof (int));
			Assert.AreEqual (typeof (int).AssemblyQualifiedName, da.DesignerBaseTypeName, "#B1");
			Assert.AreEqual (typeof (string).AssemblyQualifiedName, da.DesignerTypeName, "#B2");
			Assert.AreEqual (typeof (DesignerAttribute).FullName + typeof (int).FullName, da.TypeId, "#B3");
		}

		[Test] // ctor (Type, Type)
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor5_DesignerBaseTypeName_Null ()
		{
			new DesignerAttribute (typeof (string), (Type) null);
		}

		[Test] // ctor (Type, Type)
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor5_DesignerTypeName_Null ()
		{
			new DesignerAttribute ((Type) null, typeof (string));
		}
	}
}