EventSourceAnalyzer test does not fail

Topics: General, Using
May 25, 2015 at 8:34 AM
Edited May 25, 2015 at 8:36 AM
Hi,

i am using EventSource and would like to test for eventId using eg,:
[Event(301, Message = "Critical: {0}", Level = EventLevel.Critical)]
public void Critical(string message)
{
    WriteEvent(301, message);
}

[Event(302, Message = "Error: {0}", Level = EventLevel.Error)]
public void Error(string message)
{
    WriteEvent(301, message);
}
Also test for them:
[TestClass]
public sealed class EventsTest
{
    [TestMethod]
    public void InspectTraceEvents()
    {
        EventSourceAnalyzer.InspectAll(Events.Current);
    }
}
This test does not fail, if i have WriteEvent(301, message); twice. But if eventId is less then 128
it will fail as it should:
[Event(101, Message = "Critical: {0}", Level = EventLevel.Critical)]
public void Critical(string message)
{
    WriteEvent(101, message);
}

[Event(102, Message = "Error: {0}", Level = EventLevel.Error)]
public void Error(string message)
{
    WriteEvent(101, message);
}
Test method InspectTraceEvents threw exception:
System.ArgumentException: Event is givien event ID 102 but 101 was passed to WriteEvent.


How to fix that test? It should fail for every eventId.