phatboyg/Topshelf — pull request #25 by ErikSchierboom (2013-09-18 14:24:13+00:00)
Title: Improved testability of several host configurators

Recently, I wanted to test if my `HostConfigurator` set-up method would correctly set-up the host configurator to run as a local system account (by calling `RunAsLocalSystem` on it). I tried to write a unit test for this, but this failed due to not being able to access the actual account type passed to the `RunAsServiceAccountHostConfigurator` instance created when the `RunAsLocalSystem` extension method was called on my `HostConfigurator`.

The solution was simple: replace the read-only private field `_accountType` with a read-only public property. This now allowed me to write the desired unit test:

[Fact]
public void RunAsLocalSystemAddsRunAsServiceAccountHostConfiguratorWithLocalSystemAsServiceAccount()
{
// Arrange
var hostConfiguratorMock = new Mock();

// Act
hostConfiguratorMock.Object.RunAsLocalSystem();

// Assert
hostConfiguratorMock.Verify(h => h.AddConfigurator(It.Is(c => c.AccountType == ServiceAccount.LocalSystem)), Times.Once);
}

I have also gone through the other configurator classes and done the same thing. This will also make them testable.