Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Unit Testing an Event Source

jeff starkey edited this page Apr 3, 2017 · 3 revisions

Quick Nav


Testing of your application is critical to success. A key part of this is automated unit testing, part of the larger, over-arching Continuous Integration / Continuous Delivery.

How do I unit test an Event Source?

Happily, Microsoft has provided a package for just this purpose. Here is a shot of the NuGet Package Manager for the Unit Test project.

NuGet

It is NuGet package: EnterpriseLibrary.SemanticLogging.EventSourceAnalyzer. Install this within your unit test project. After that, simply implement the test as shown below.

    /// <summary>
    /// Confirm the quality of the Event Source
    /// </summary>
    [TestMethod]
    public void ValidateEventSource()
    {
        //// see https://msdn.microsoft.com/en-us/library/dn774985(v=pandp.20).aspx
        //// for details about the EventSourceAnalyzer, its coverage and validation checks
        EventSourceAnalyzer.InspectAll(Logger.Log);
    }

How do I unit test an internal, sealed class?

This was a puzzle for a little while. The answer is that you need to tell the referenced project that it is okay to do the unit testing. This was something new to me, but what you end up doing is placing a special attribute in the AssemblyInfo.cs file for the class project. "InternalsVisibleTo" grants access to the project specified. This allows the unit tests to function. Without it, the internal keyword keeps prying eyes away!

[assembly: InternalsVisibleTo("SemanticLogging.UnitTest")]

Find the specific code here.

Clone this wiki locally