Welcome to mirror list, hosted at ThFree Co, Russian Federation.

InvalidEnumArgumentExceptionTest.cs « System.ComponentModel « Test « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7e212891af6dd5873a31866373838628459f5e3 (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
//
// System.ComponentModel.InvalidEnumArgumentException test cases
//
// Authors:
// 	Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2007 Gert Driesen
//

using System;
using System.ComponentModel;
using System.Globalization;

using NUnit.Framework;

namespace MonoTests.System.ComponentModel
{
	[TestFixture]
	public class InvalidEnumArgumentExceptionTest
	{
		[Test] // ctor ()
		public void Constructor0 ()
		{
			InvalidEnumArgumentException iea = new InvalidEnumArgumentException ();
			Assert.IsNull (iea.InnerException, "#1");
			Assert.IsNotNull (iea.Message, "#2");
			Assert.IsTrue (iea.Message.IndexOf (typeof (InvalidEnumArgumentException).FullName) != -1, "#3");
			Assert.IsNull (iea.ParamName, "#4");
		}

		[Test] // ctor (string)
		public void Constructor1 ()
		{
			InvalidEnumArgumentException iea;

			iea = new InvalidEnumArgumentException ("msg");
			Assert.IsNull (iea.InnerException, "#A1");
			Assert.IsNotNull (iea.Message, "#A2");
			Assert.AreEqual ("msg", iea.Message, "#A3");
			Assert.IsNull (iea.ParamName, "#A4");

			iea = new InvalidEnumArgumentException (string.Empty);
			Assert.IsNull (iea.InnerException, "#B1");
			Assert.IsNotNull (iea.Message, "#B2");
			Assert.AreEqual (string.Empty, iea.Message, "#B3");
			Assert.IsNull (iea.ParamName, "#B4");

			iea = new InvalidEnumArgumentException ((string) null);
			Assert.IsNull (iea.InnerException, "#C1");
			Assert.IsNotNull (iea.Message, "#C2");
			Assert.IsTrue (iea.Message.IndexOf (typeof (InvalidEnumArgumentException).FullName) != -1, "#C3");
			Assert.IsNull (iea.ParamName, "#C4");
		}

		// TODO: ctor (SerializationInfo, StreamingContext)

#if NET_2_0
		[Test] // ctor (string, Exception)
		public void Constructor3 ()
		{
			InvalidEnumArgumentException iea;
			Exception inner = new Exception ("INNER");

			iea = new InvalidEnumArgumentException ("msg", (Exception) null);
			Assert.IsNull (iea.InnerException, "#A1");
			Assert.IsNotNull (iea.Message, "#A2");
			Assert.AreEqual ("msg", iea.Message, "#A3");
			Assert.IsNull (iea.ParamName, "#A4");

			iea = new InvalidEnumArgumentException (string.Empty, inner);
			Assert.AreSame (inner, iea.InnerException, "#B1");
			Assert.IsNotNull (iea.Message, "#B2");
			Assert.AreEqual (string.Empty, iea.Message, "#B3");
			Assert.IsNull (iea.ParamName, "#B4");

			iea = new InvalidEnumArgumentException ((string) null, inner);
			Assert.AreSame (inner, iea.InnerException, "#C1");
			Assert.IsNotNull (iea.Message, "#C2");
			Assert.IsTrue (iea.Message.IndexOf (typeof (InvalidEnumArgumentException).FullName) != -1, "#C3");
			Assert.IsNull (iea.ParamName, "#C4");
		}
#endif

		[Test] // ctor (string, int, System.Type)
		public void Constructor4 ()
		{
			InvalidEnumArgumentException iea;
			Type enumClass = typeof (AttributeTargets);

			// The value of argument 'value' (667666) is invalid for
			// Enum type 'AttributeTargets'
			iea = new InvalidEnumArgumentException ("arg", 667666, enumClass);
			Assert.IsNull (iea.InnerException, "#A1");
			Assert.IsNotNull (iea.Message, "#A2");
#if NET_2_0
			Assert.IsTrue (iea.Message.IndexOf ("'arg'") != -1, "#A3");
			Assert.IsTrue (iea.Message.IndexOf ("(" + 667666.ToString (CultureInfo.CurrentCulture) + ")") != -1, "#A4");
			Assert.IsTrue (iea.Message.IndexOf ("'" + enumClass.Name + "'") != -1, "#A5");
#else
			Assert.IsTrue (iea.Message.IndexOf ("arg") != -1, "#A3");
			Assert.IsTrue (iea.Message.IndexOf (667666.ToString (CultureInfo.CurrentCulture)) != -1, "#A4");
			Assert.IsTrue (iea.Message.IndexOf (enumClass.Name) != -1, "#A5");
#endif
			Assert.IsNotNull (iea.ParamName, "#A6");
			Assert.AreEqual ("arg", iea.ParamName, "#A7");

			// The value of argument '' (0) is invalid for
			// Enum type 'AttributeTargets'
			iea = new InvalidEnumArgumentException (string.Empty, 0, enumClass);
			Assert.IsNull (iea.InnerException, "#B1");
			Assert.IsNotNull (iea.Message, "#B2");
#if NET_2_0
			Assert.IsTrue (iea.Message.IndexOf ("''") != -1, "#B3");
			Assert.IsTrue (iea.Message.IndexOf ("(" + 0.ToString (CultureInfo.CurrentCulture) + ")") != -1, "#B4");
			Assert.IsTrue (iea.Message.IndexOf ("'" + enumClass.Name + "'") != -1, "#B5");
#else
			Assert.IsTrue (iea.Message.IndexOf ("  ") != -1, "#B3");
			Assert.IsTrue (iea.Message.IndexOf (0.ToString (CultureInfo.CurrentCulture)) != -1, "#B4");
			Assert.IsTrue (iea.Message.IndexOf (enumClass.Name) != -1, "#B5");
#endif
			Assert.IsNotNull (iea.ParamName, "#B6");
			Assert.AreEqual (string.Empty, iea.ParamName, "#B7");

			// The value of argument '' (-56776) is invalid for Enum type
			// 'AttributeTargets'
			iea = new InvalidEnumArgumentException ((string) null, -56776, enumClass);
			Assert.IsNull (iea.InnerException, "#C1");
			Assert.IsNotNull (iea.Message, "#C2");
#if NET_2_0
			Assert.IsTrue (iea.Message.IndexOf ("''") != -1, "#C3");
			Assert.IsTrue (iea.Message.IndexOf ("(" + (-56776).ToString (CultureInfo.CurrentCulture) + ")") != -1, "#C4");
			Assert.IsTrue (iea.Message.IndexOf ("'" + enumClass.Name + "'") != -1, "#C5");
#else
			Assert.IsTrue (iea.Message.IndexOf ("  ") != -1, "#C3");
			Assert.IsTrue (iea.Message.IndexOf ((-56776).ToString (CultureInfo.CurrentCulture)) != -1, "#C4");
			Assert.IsTrue (iea.Message.IndexOf (enumClass.Name) != -1, "#C5");
#endif
			Assert.IsNull (iea.ParamName, "#C6");

			// The value of argument '' (0) is invalid for Enum type
			// 'AttributeTargets'
			iea = new InvalidEnumArgumentException ((string) null, 0, enumClass);
			Assert.IsNull (iea.InnerException, "#D1");
			Assert.IsNotNull (iea.Message, "#D2");
#if NET_2_0
			Assert.IsTrue (iea.Message.IndexOf ("''") != -1, "#D3");
			Assert.IsTrue (iea.Message.IndexOf ("(" + 0.ToString (CultureInfo.CurrentCulture) + ")") != -1, "#D4");
			Assert.IsTrue (iea.Message.IndexOf ("'" + enumClass.Name + "'") != -1, "#D5");
#else
			Assert.IsTrue (iea.Message.IndexOf ("  ") != -1, "#D3");
			Assert.IsTrue (iea.Message.IndexOf (0.ToString (CultureInfo.CurrentCulture)) != -1, "#D4");
			Assert.IsTrue (iea.Message.IndexOf (enumClass.Name) != -1, "#D5");
#endif
			Assert.IsNull (iea.ParamName, "#D6");
		}

		[Test] // ctor (string, int, System.Type)
		[ExpectedException (typeof (NullReferenceException))]
		public void Constructor4_EnumClass_Null ()
		{
			new InvalidEnumArgumentException ("param", 55, (Type) null);
		}
	}
}