| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- //
- // EventInstanceTest.cs -
- // NUnit Test Cases for System.Diagnostics.EvenInstance
- //
- // Author:
- // Gert Driesen <[email protected]>
- //
- // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- #if !MOBILE
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using NUnit.Framework;
- namespace MonoTests.System.Diagnostics
- {
- [TestFixture]
- public class EventInstanceTest
- {
- [Test]
- public void Constructor1 ()
- {
- EventInstance ei = null;
- ei = new EventInstance (5, 10);
- Assert.AreEqual (10, ei.CategoryId, "#A1");
- Assert.AreEqual (5, ei.InstanceId, "#A2");
- Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
- ei = new EventInstance (0, 0);
- Assert.AreEqual (0, ei.CategoryId, "#B1");
- Assert.AreEqual (0, ei.InstanceId, "#B2");
- Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#B3");
- ei = new EventInstance (uint.MaxValue, ushort.MaxValue);
- Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
- Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
- Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#C3");
- }
- [Test]
- public void Constructor1_InstanceId_Invalid ()
- {
- try {
- new EventInstance (-1, 10);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- try {
- new EventInstance ((long) uint.MaxValue + 1, 10);
- Assert.Fail ("#B1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
- Assert.IsNotNull (ex.Message, "#B3");
- Assert.IsNull (ex.InnerException, "#B4");
- }
- }
- [Test]
- public void Constructor1_CategoryId_Invalid ()
- {
- try {
- new EventInstance (5, -1);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- try {
- new EventInstance (5, ushort.MaxValue + 1);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- }
- [Test]
- public void Constructor2 ()
- {
- EventInstance ei = null;
- ei = new EventInstance (5, 10, EventLogEntryType.Information);
- Assert.AreEqual (10, ei.CategoryId, "#A1");
- Assert.AreEqual (5, ei.InstanceId, "#A2");
- Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#A3");
- ei = new EventInstance (0, 0, EventLogEntryType.Error);
- Assert.AreEqual (0, ei.CategoryId, "#B1");
- Assert.AreEqual (0, ei.InstanceId, "#B2");
- Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#B3");
- ei = new EventInstance (uint.MaxValue, ushort.MaxValue,
- EventLogEntryType.Warning);
- Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#C1");
- Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#C2");
- Assert.AreEqual (EventLogEntryType.Warning, ei.EntryType, "#C3");
- }
- [Test]
- public void Constructor2_InstanceId_Invalid ()
- {
- try {
- new EventInstance (-1, 10, EventLogEntryType.Error);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- try {
- new EventInstance ((long) uint.MaxValue + 1, 10,
- EventLogEntryType.Error);
- Assert.Fail ("#B1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
- Assert.IsNotNull (ex.Message, "#B3");
- Assert.IsNull (ex.InnerException, "#B4");
- }
- }
- [Test]
- public void Constructor2_CategoryId_Invalid ()
- {
- try {
- new EventInstance (5, -1, EventLogEntryType.Error);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- try {
- new EventInstance (5, (int) ushort.MaxValue + 1, EventLogEntryType.Error);
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- }
- [Test]
- [ExpectedException (typeof (InvalidEnumArgumentException))] // Enum argument value 666 is not valid for type. type should be a value from EventLogEntryType.
- public void Constructor2_EntryType_Invalid ()
- {
- new EventInstance (5, 5, (EventLogEntryType) 666);
- }
- [Test]
- public void CategoryId ()
- {
- EventInstance ei = new EventInstance (5, 10);
- ei.CategoryId = 0;
- Assert.AreEqual (0, ei.CategoryId, "#1");
- ei.CategoryId = 5;
- Assert.AreEqual (5, ei.CategoryId, "#2");
- ei.CategoryId = ushort.MaxValue;
- Assert.AreEqual (ushort.MaxValue, ei.CategoryId, "#3");
- ei.CategoryId = 0;
- Assert.AreEqual (0, ei.CategoryId, "#4");
- Assert.AreEqual (5, ei.InstanceId, "#5");
- }
- [Test]
- public void CategoryId_Invalid ()
- {
- EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
- try {
- ei.CategoryId = -1;
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- try {
- ei.CategoryId = (int) ushort.MaxValue + 1;
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- Assert.AreEqual (10, ei.CategoryId, "#C1");
- Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
- Assert.AreEqual (5, ei.InstanceId, "#C2");
- }
- [Test]
- public void InstanceId ()
- {
- EventInstance ei = new EventInstance (5, 10);
- ei.InstanceId = 0;
- Assert.AreEqual (0, ei.InstanceId, "#1");
- ei.InstanceId = 5;
- Assert.AreEqual (5, ei.InstanceId, "#2");
- ei.InstanceId = uint.MaxValue;
- Assert.AreEqual (uint.MaxValue, ei.InstanceId, "#3");
- ei.InstanceId = 0;
- Assert.AreEqual (0, ei.InstanceId, "#4");
- Assert.AreEqual (10, ei.CategoryId, "#5");
- }
- [Test]
- public void InstanceId_Invalid ()
- {
- EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
- try {
- ei.InstanceId = -1;
- Assert.Fail ("#A1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsNull (ex.InnerException, "#A4");
- }
- try {
- ei.InstanceId = (long) uint.MaxValue + 1;
- Assert.Fail ("#B1");
- } catch (ArgumentOutOfRangeException ex) {
- Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
- Assert.IsNotNull (ex.Message, "#B3");
- Assert.IsNull (ex.InnerException, "#B4");
- }
- Assert.AreEqual (10, ei.CategoryId, "#C1");
- Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
- Assert.AreEqual (5, ei.InstanceId, "#C3");
- }
- [Test]
- public void EntryType ()
- {
- EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
- ei.EntryType = EventLogEntryType.Warning;
- Assert.AreEqual (EventLogEntryType.Warning, ei.EntryType, "#1");
- ei.EntryType = EventLogEntryType.FailureAudit;
- Assert.AreEqual (EventLogEntryType.FailureAudit, ei.EntryType, "#2");
- ei.EntryType = EventLogEntryType.SuccessAudit;
- Assert.AreEqual (EventLogEntryType.SuccessAudit, ei.EntryType, "#3");
- ei.EntryType = EventLogEntryType.Information;
- Assert.AreEqual (EventLogEntryType.Information, ei.EntryType, "#4");
- Assert.AreEqual (5, ei.InstanceId, "#5");
- Assert.AreEqual (10, ei.CategoryId, "#6");
- }
- [Test]
- public void EntryType_Invalid ()
- {
- EventInstance ei = new EventInstance (5, 10, EventLogEntryType.Error);
- try {
- ei.EntryType = (EventLogEntryType) 666;
- Assert.Fail ("#A1");
- } catch (InvalidEnumArgumentException ex) {
- // The value of argument 'value' (666) is invalid for Enum type
- // 'EventLogEntryType'
- Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#A2");
- Assert.IsNotNull (ex.Message, "#A3");
- Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#A4");
- Assert.IsTrue (ex.Message.IndexOf ("value") != -1, "#A5");
- Assert.IsTrue (ex.Message.IndexOf ("EventLogEntryType") != -1, "#A6");
- Assert.IsNull (ex.InnerException, "#A7");
- }
- try {
- ei.EntryType = new EventLogEntryType ();
- Assert.Fail ("#B1");
- } catch (InvalidEnumArgumentException ex) {
- // The value of argument 'value' (0) is invalid for Enum type
- // 'EventLogEntryType'
- Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#B2");
- Assert.IsNotNull (ex.Message, "#B3");
- Assert.IsTrue (ex.Message.IndexOf ("0") != -1, "#B4");
- Assert.IsTrue (ex.Message.IndexOf ("value") != -1, "#B5");
- Assert.IsTrue (ex.Message.IndexOf ("EventLogEntryType") != -1, "#B6");
- Assert.IsNull (ex.InnerException, "#B7");
- }
- Assert.AreEqual (10, ei.CategoryId, "#C1");
- Assert.AreEqual (EventLogEntryType.Error, ei.EntryType, "#C2");
- Assert.AreEqual (5, ei.InstanceId, "#C3");
- }
- }
- }
- #endif
|