-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for TopShelf hosting (#71)
- Loading branch information
Showing
6 changed files
with
185 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
tests/Tests.Nybus.Extensions.Hosting.TopShelf/HostConfiguratorExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus; | ||
using Topshelf.HostConfigurators; | ||
using Topshelf.Runtime; | ||
// ReSharper disable InvokeAsExtensionMethod | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class HostConfiguratorExtensionsTests | ||
{ | ||
[Test, AutoMoqData] | ||
public void UseStartup_sets_up_service_builder(HostConfigurator configurator) | ||
{ | ||
HostConfiguratorExtensions.UseStartup<TestStartup>(configurator); | ||
|
||
Mock.Get(configurator).Verify(p => p.UseServiceBuilder(It.IsAny<ServiceBuilderFactory>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void UseStartup_sets_up_service_start(HostConfigurator configurator) | ||
{ | ||
HostConfiguratorExtensions.UseStartup<TestStartup>(configurator); | ||
|
||
Assert.Inconclusive("The test is not able to assert whether the desired action happened"); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void UseStartup_sets_up_service_stop(HostConfigurator configurator) | ||
{ | ||
HostConfiguratorExtensions.UseStartup<TestStartup>(configurator); | ||
|
||
Assert.Inconclusive("The test is not able to assert whether the desired action happened"); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void BuildHost_uses_ConfigureAppConfiguration(Mock<Startup> mockStartup, HostSettings settings) | ||
{ | ||
HostConfiguratorExtensions.BuildHost(mockStartup.Object, settings); | ||
|
||
mockStartup.Verify(p => p.ConfigureAppConfiguration(It.IsAny<IConfigurationBuilder>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void BuildHost_uses_ConstructService(Mock<Startup> mockStartup, HostSettings settings) | ||
{ | ||
HostConfiguratorExtensions.BuildHost(mockStartup.Object, settings); | ||
|
||
mockStartup.Verify(p => p.ConstructService(It.IsAny<StartupContext>(), It.IsAny<IServiceProvider>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void BuildHost_uses_ConfigureServices(Mock<Startup> mockStartup, HostSettings settings) | ||
{ | ||
HostConfiguratorExtensions.BuildHost(mockStartup.Object, settings); | ||
|
||
mockStartup.Verify(p => p.ConfigureServices(It.IsAny<StartupContext>(), It.IsAny<IServiceCollection>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void BuildHost_uses_ConfigureLogging(Mock<Startup> mockStartup, HostSettings settings) | ||
{ | ||
HostConfiguratorExtensions.BuildHost(mockStartup.Object, settings); | ||
|
||
mockStartup.Verify(p => p.ConfigureLogging(It.IsAny<StartupContext>(), It.IsAny<ILoggingBuilder>())); | ||
} | ||
} | ||
|
||
public class TestStartup : Startup | ||
{ | ||
public override IBusHost ConstructService(StartupContext context, IServiceProvider serviceProvider) | ||
{ | ||
return Mock.Of<IBusHost>(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Tests.Nybus.Extensions.Hosting.TopShelf/StartupContextTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using AutoFixture.NUnit3; | ||
using Microsoft.Extensions.Configuration; | ||
using NUnit.Framework; | ||
using Nybus; | ||
using Topshelf.Runtime; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class StartupContextTests | ||
{ | ||
[Test, AutoMoqData] | ||
public void Context_returns_given_configuration([Frozen] IConfigurationRoot configuration, StartupContext sut) | ||
{ | ||
Assert.That(sut.Configuration, Is.SameAs(configuration)); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void Context_returns_given_settings([Frozen] HostSettings settings, StartupContext sut) | ||
{ | ||
Assert.That(sut.Settings, Is.SameAs(settings)); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/Tests.Nybus.Extensions.Hosting.TopShelf/StartupTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus; | ||
using Topshelf; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class StartupTests | ||
{ | ||
[Test, AutoMoqData] | ||
public void OnStart_starts_the_host(TestStartup sut, IBusHost busHost, HostControl control) | ||
{ | ||
sut.OnStart(busHost, control); | ||
|
||
Mock.Get(busHost).Verify(p => p.StartAsync(), Times.Once); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void OnStop_stops_the_host(TestStartup sut, IBusHost busHost, HostControl control) | ||
{ | ||
sut.OnStop(busHost, control); | ||
|
||
Mock.Get(busHost).Verify(p => p.StopAsync(), Times.Once); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Tests.Nybus.Extensions.Hosting.TopShelf/Tests.Nybus.Extensions.Hosting.TopShelf.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.11.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TestUtils\TestUtils.csproj" /> | ||
<ProjectReference Include="..\..\src\extensions\hosting\Nybus.Extensions.TopShelf\Nybus.Extensions.Hosting.TopShelf.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |