2 // EventInstanceTest.cs -
3 // NUnit Test Cases for System.Diagnostics.EvenInstance
6 // Gert Driesen <driesen@users.sourceforge.net>
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
34 using System.ComponentModel;
35 using System.Diagnostics;
37 using NUnit.Framework;
39 namespace MonoTests.System.Diagnostics
42 public class EventInstanceTest
45 public void Constructor1 ()
47 EventInstance ei = null;
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");
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");
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");
66 public void Constructor1_InstanceId_Invalid ()
69 new EventInstance (-1, 10);
71 } catch (ArgumentOutOfRangeException ex) {
72 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
73 Assert.IsNotNull (ex.Message, "#A3");
74 Assert.IsNull (ex.InnerException, "#A4");
78 new EventInstance ((long) uint.MaxValue + 1, 10);
80 } catch (ArgumentOutOfRangeException ex) {
81 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
82 Assert.IsNotNull (ex.Message, "#B3");
83 Assert.IsNull (ex.InnerException, "#B4");
88 public void Constructor1_CategoryId_Invalid ()
91 new EventInstance (5, -1);
93 } catch (ArgumentOutOfRangeException ex) {
94 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
95 Assert.IsNotNull (ex.Message, "#A3");
96 Assert.IsNull (ex.InnerException, "#A4");
100 new EventInstance (5, ushort.MaxValue + 1);
102 } catch (ArgumentOutOfRangeException ex) {
103 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
104 Assert.IsNotNull (ex.Message, "#A3");
105 Assert.IsNull (ex.InnerException, "#A4");
110 public void Constructor2 ()
112 EventInstance ei = null;
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");
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");
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");
132 public void Constructor2_InstanceId_Invalid ()
135 new EventInstance (-1, 10, EventLogEntryType.Error);
137 } catch (ArgumentOutOfRangeException ex) {
138 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
139 Assert.IsNotNull (ex.Message, "#A3");
140 Assert.IsNull (ex.InnerException, "#A4");
144 new EventInstance ((long) uint.MaxValue + 1, 10,
145 EventLogEntryType.Error);
147 } catch (ArgumentOutOfRangeException ex) {
148 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
149 Assert.IsNotNull (ex.Message, "#B3");
150 Assert.IsNull (ex.InnerException, "#B4");
155 public void Constructor2_CategoryId_Invalid ()
158 new EventInstance (5, -1, EventLogEntryType.Error);
160 } catch (ArgumentOutOfRangeException ex) {
161 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
162 Assert.IsNotNull (ex.Message, "#A3");
163 Assert.IsNull (ex.InnerException, "#A4");
167 new EventInstance (5, (int) ushort.MaxValue + 1, EventLogEntryType.Error);
169 } catch (ArgumentOutOfRangeException ex) {
170 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
171 Assert.IsNotNull (ex.Message, "#A3");
172 Assert.IsNull (ex.InnerException, "#A4");
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 ()
180 new EventInstance (5, 5, (EventLogEntryType) 666);
184 public void CategoryId ()
186 EventInstance ei = new EventInstance (5, 10);
188 Assert.AreEqual (0, ei.CategoryId, "#1");
190 Assert.AreEqual (5, ei.CategoryId, "#2");
191 ei.CategoryId = ushort.MaxValue;
192 Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#3");
194 Assert.AreEqual (0, ei.CategoryId, "#4");
195 Assert.AreEqual (5, ei.InstanceId, "#5");
199 public void CategoryId_Invalid ()
201 EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
205 } catch (ArgumentOutOfRangeException ex) {
206 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
207 Assert.IsNotNull (ex.Message, "#A3");
208 Assert.IsNull (ex.InnerException, "#A4");
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");
219 Assert.AreEqual (10, ei.CategoryId, "#C1");
220 Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
221 Assert.AreEqual (5, ei.InstanceId, "#C2");
225 public void InstanceId ()
227 EventInstance ei = new EventInstance (5, 10);
229 Assert.AreEqual (0, ei.InstanceId, "#1");
231 Assert.AreEqual (5, ei.InstanceId, "#2");
232 ei.InstanceId = uint.MaxValue;
233 Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#3");
235 Assert.AreEqual (0, ei.InstanceId, "#4");
236 Assert.AreEqual (10, ei.CategoryId, "#5");
240 public void InstanceId_Invalid ()
242 EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
247 } catch (ArgumentOutOfRangeException ex) {
248 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
249 Assert.IsNotNull (ex.Message, "#A3");
250 Assert.IsNull (ex.InnerException, "#A4");
254 ei.InstanceId = (long) uint.MaxValue + 1;
256 } catch (ArgumentOutOfRangeException ex) {
257 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
258 Assert.IsNotNull (ex.Message, "#B3");
259 Assert.IsNull (ex.InnerException, "#B4");
262 Assert.AreEqual (10, ei.CategoryId, "#C1");
263 Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
264 Assert.AreEqual (5, ei.InstanceId, "#C3");
268 public void EntryType ()
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");
284 public void EntryType_Invalid ()
286 EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
289 ei.EntryType = (EventLogEntryType) 666;
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");
303 ei.EntryType = new EventLogEntryType ();
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");
316 Assert.AreEqual (10, ei.CategoryId, "#C1");
317 Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
318 Assert.AreEqual (5, ei.InstanceId, "#C3");