-
Notifications
You must be signed in to change notification settings - Fork 0
Unit Testing an Event Source
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.
Happily, Microsoft has provided a package for just this purpose. Here is a shot of the NuGet Package Manager for the Unit Test project.
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);
}
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.
Succeed: incrementally, based on user engagement, and driven by data.