Fixed HttpWebRequestTest to compile with mobile NUnit.
[mono.git] / mcs / class / System / Test / System.Diagnostics / EventInstanceTest.cs
1 //
2 // EventInstanceTest.cs -
3 // NUnit Test Cases for System.Diagnostics.EvenInstance
4 //
5 // Author:
6 //      Gert Driesen <driesen@users.sourceforge.net>
7 //
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 //
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if !MOBILE
32
33 using System;
34 using System.ComponentModel;
35 using System.Diagnostics;
36
37 using NUnit.Framework;
38
39 namespace MonoTests.System.Diagnostics
40 {
41         [TestFixture]
42         public class EventInstanceTest
43         {
44                 [Test]
45                 public void Constructor1 ()
46                 {
47                         EventInstance ei = null;
48
49                         ei = new EventInstance (5, 10);
50                         Assert.AreEqual (10, ei.CategoryId, "#A1");
51                         Assert.AreEqual (5, ei.InstanceId, "#A2");
52                         Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
53
54                         ei = new EventInstance (0, 0);
55                         Assert.AreEqual (0, ei.CategoryId, "#B1");
56                         Assert.AreEqual (0, ei.InstanceId, "#B2");
57                         Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#B3");
58
59                         ei = new EventInstance (uint.MaxValue, ushort.MaxValue);
60                         Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
61                         Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
62                         Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#C3");
63                 }
64
65                 [Test]
66                 public void Constructor1_InstanceId_Invalid ()
67                 {
68                         try {
69                                 new EventInstance (-1, 10);
70                                 Assert.Fail ("#A1");
71                         } catch (ArgumentOutOfRangeException ex) {
72                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
73                                 Assert.IsNotNull (ex.Message, "#A3");
74                                 Assert.IsNull (ex.InnerException, "#A4");
75                         }
76
77                         try {
78                                 new EventInstance ((long) uint.MaxValue + 1, 10);
79                                 Assert.Fail ("#B1");
80                         } catch (ArgumentOutOfRangeException ex) {
81                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
82                                 Assert.IsNotNull (ex.Message, "#B3");
83                                 Assert.IsNull (ex.InnerException, "#B4");
84                         }
85                 }
86
87                 [Test]
88                 public void Constructor1_CategoryId_Invalid ()
89                 {
90                         try {
91                                 new EventInstance (5, -1);
92                                 Assert.Fail ("#A1");
93                         } catch (ArgumentOutOfRangeException ex) {
94                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
95                                 Assert.IsNotNull (ex.Message, "#A3");
96                                 Assert.IsNull (ex.InnerException, "#A4");
97                         }
98
99                         try {
100                                 new EventInstance (5, ushort.MaxValue + 1);
101                                 Assert.Fail ("#A1");
102                         } catch (ArgumentOutOfRangeException ex) {
103                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
104                                 Assert.IsNotNull (ex.Message, "#A3");
105                                 Assert.IsNull (ex.InnerException, "#A4");
106                         }
107                 }
108
109                 [Test]
110                 public void Constructor2 ()
111                 {
112                         EventInstance ei = null;
113
114                         ei = new EventInstance (5, 10, EventLogEntryType.Information);
115                         Assert.AreEqual (10, ei.CategoryId, "#A1");
116                         Assert.AreEqual (5, ei.InstanceId, "#A2");
117                         Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
118
119                         ei = new EventInstance (0, 0, EventLogEntryType.Error);
120                         Assert.AreEqual (0, ei.CategoryId, "#B1");
121                         Assert.AreEqual (0, ei.InstanceId, "#B2");
122                         Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#B3");
123
124                         ei = new EventInstance (uint.MaxValue, ushort.MaxValue,
125                                 EventLogEntryType.Warning);
126                         Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
127                         Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
128                         Assert.AreEqual (EventLogEntryType.Warning, ei.EntryType, "#C3");
129                 }
130
131                 [Test]
132                 public void Constructor2_InstanceId_Invalid ()
133                 {
134                         try {
135                                 new EventInstance (-1, 10, EventLogEntryType.Error);
136                                 Assert.Fail ("#A1");
137                         } catch (ArgumentOutOfRangeException ex) {
138                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
139                                 Assert.IsNotNull (ex.Message, "#A3");
140                                 Assert.IsNull (ex.InnerException, "#A4");
141                         }
142
143                         try {
144                                 new EventInstance ((long) uint.MaxValue + 1, 10,
145                                         EventLogEntryType.Error);
146                                 Assert.Fail ("#B1");
147                         } catch (ArgumentOutOfRangeException ex) {
148                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
149                                 Assert.IsNotNull (ex.Message, "#B3");
150                                 Assert.IsNull (ex.InnerException, "#B4");
151                         }
152                 }
153
154                 [Test]
155                 public void Constructor2_CategoryId_Invalid ()
156                 {
157                         try {
158                                 new EventInstance (5, -1, EventLogEntryType.Error);
159                                 Assert.Fail ("#A1");
160                         } catch (ArgumentOutOfRangeException ex) {
161                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
162                                 Assert.IsNotNull (ex.Message, "#A3");
163                                 Assert.IsNull (ex.InnerException, "#A4");
164                         }
165
166                         try {
167                                 new EventInstance (5, (int) ushort.MaxValue + 1, EventLogEntryType.Error);
168                                 Assert.Fail ("#A1");
169                         } catch (ArgumentOutOfRangeException ex) {
170                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
171                                 Assert.IsNotNull (ex.Message, "#A3");
172                                 Assert.IsNull (ex.InnerException, "#A4");
173                         }
174                 }
175
176                 [Test]
177                 [ExpectedException (typeof (InvalidEnumArgumentException))] // Enum argument value 666 is not valid for type. type should be a value from EventLogEntryType.
178                 public void Constructor2_EntryType_Invalid ()
179                 {
180                         new EventInstance (5, 5, (EventLogEntryType) 666);
181                 }
182
183                 [Test]
184                 public void CategoryId ()
185                 {
186                         EventInstance ei = new EventInstance (5, 10);
187                         ei.CategoryId = 0;
188                         Assert.AreEqual (0, ei.CategoryId, "#1");
189                         ei.CategoryId = 5;
190                         Assert.AreEqual (5, ei.CategoryId, "#2");
191                         ei.CategoryId = ushort.MaxValue;
192                         Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#3");
193                         ei.CategoryId = 0;
194                         Assert.AreEqual (0, ei.CategoryId, "#4");
195                         Assert.AreEqual (5, ei.InstanceId, "#5");
196                 }
197
198                 [Test]
199                 public void CategoryId_Invalid ()
200                 {
201                         EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
202
203                         try {
204                                 ei.CategoryId = -1;
205                         } catch (ArgumentOutOfRangeException ex) {
206                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
207                                 Assert.IsNotNull (ex.Message, "#A3");
208                                 Assert.IsNull (ex.InnerException, "#A4");
209                         }
210
211                         try {
212                                 ei.CategoryId = (int) ushort.MaxValue + 1;
213                         } catch (ArgumentOutOfRangeException ex) {
214                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
215                                 Assert.IsNotNull (ex.Message, "#A3");
216                                 Assert.IsNull (ex.InnerException, "#A4");
217                         }
218
219                         Assert.AreEqual (10, ei.CategoryId, "#C1");
220                         Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
221                         Assert.AreEqual (5, ei.InstanceId, "#C2");
222                 }
223
224                 [Test]
225                 public void InstanceId ()
226                 {
227                         EventInstance ei = new EventInstance (5, 10);
228                         ei.InstanceId = 0;
229                         Assert.AreEqual (0, ei.InstanceId, "#1");
230                         ei.InstanceId = 5;
231                         Assert.AreEqual (5, ei.InstanceId, "#2");
232                         ei.InstanceId = uint.MaxValue;
233                         Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#3");
234                         ei.InstanceId = 0;
235                         Assert.AreEqual (0, ei.InstanceId, "#4");
236                         Assert.AreEqual (10, ei.CategoryId, "#5");
237                 }
238
239                 [Test]
240                 public void InstanceId_Invalid ()
241                 {
242                         EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
243
244                         try {
245                                 ei.InstanceId = -1;
246                                 Assert.Fail ("#A1");
247                         } catch (ArgumentOutOfRangeException ex) {
248                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
249                                 Assert.IsNotNull (ex.Message, "#A3");
250                                 Assert.IsNull (ex.InnerException, "#A4");
251                         }
252
253                         try {
254                                 ei.InstanceId = (long) uint.MaxValue + 1;
255                                 Assert.Fail ("#B1");
256                         } catch (ArgumentOutOfRangeException ex) {
257                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
258                                 Assert.IsNotNull (ex.Message, "#B3");
259                                 Assert.IsNull (ex.InnerException, "#B4");
260                         }
261
262                         Assert.AreEqual (10, ei.CategoryId, "#C1");
263                         Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
264                         Assert.AreEqual (5, ei.InstanceId, "#C3");
265                 }
266
267                 [Test]
268                 public void EntryType ()
269                 {
270                         EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
271                         ei.EntryType = EventLogEntryType.Warning;
272                         Assert.AreEqual (EventLogEntryType.Warning, ei.EntryType, "#1");
273                         ei.EntryType = EventLogEntryType.FailureAudit;
274                         Assert.AreEqual (EventLogEntryType.FailureAudit, ei.EntryType, "#2");
275                         ei.EntryType = EventLogEntryType.SuccessAudit;
276                         Assert.AreEqual (EventLogEntryType.SuccessAudit, ei.EntryType, "#3");
277                         ei.EntryType = EventLogEntryType.Information;
278                         Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#4");
279                         Assert.AreEqual (5, ei.InstanceId, "#5");
280                         Assert.AreEqual (10, ei.CategoryId, "#6");
281                 }
282
283                 [Test]
284                 public void EntryType_Invalid ()
285                 {
286                         EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
287
288                         try {
289                                 ei.EntryType = (EventLogEntryType) 666;
290                                 Assert.Fail ("#A1");
291                         } catch (InvalidEnumArgumentException ex) {
292                                 // The value of argument 'value' (666) is invalid for Enum type
293                                 // 'EventLogEntryType'
294                                 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#A2");
295                                 Assert.IsNotNull (ex.Message, "#A3");
296                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#A4");
297                                 Assert.IsTrue (ex.Message.IndexOf ("value") != -1, "#A5");
298                                 Assert.IsTrue (ex.Message.IndexOf ("EventLogEntryType") != -1, "#A6");
299                                 Assert.IsNull (ex.InnerException, "#A7");
300                         }
301
302                         try {
303                                 ei.EntryType = new EventLogEntryType ();
304                                 Assert.Fail ("#B1");
305                         } catch (InvalidEnumArgumentException ex) {
306                                 // The value of argument 'value' (0) is invalid for Enum type
307                                 // 'EventLogEntryType'
308                                 Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#B2");
309                                 Assert.IsNotNull (ex.Message, "#B3");
310                                 Assert.IsTrue (ex.Message.IndexOf ("0") != -1, "#B4");
311                                 Assert.IsTrue (ex.Message.IndexOf ("value") != -1, "#B5");
312                                 Assert.IsTrue (ex.Message.IndexOf ("EventLogEntryType") != -1, "#B6");
313                                 Assert.IsNull (ex.InnerException, "#B7");
314                         }
315
316                         Assert.AreEqual (10, ei.CategoryId, "#C1");
317                         Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
318                         Assert.AreEqual (5, ei.InstanceId, "#C3");
319                 }
320         }
321 }
322 #endif