Skip to content

Commit

Permalink
Finalize unit tests (#25)
Browse files Browse the repository at this point in the history
* Tests for ObservableConsumer
* Moved ConfigurationException to Abstractions and added tests
* Extracted test utils
* Version bump to 1.0.0-alpha0002
* Skip coveralls when building PRs
  • Loading branch information
Kralizek committed Jan 5, 2019
1 parent 8b775f5 commit 979de72
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 211 deletions.
15 changes: 15 additions & 0 deletions Nybus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Types", "samples\RabbitMQ\T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Integration.Nybus", "tests\Tests.Integration.Nybus\Tests.Integration.Nybus.csproj", "{C498B46D-26EF-4AAE-ADFA-5763609A688B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils", "tests\TestUtils\TestUtils.csproj", "{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -235,6 +237,18 @@ Global
{C498B46D-26EF-4AAE-ADFA-5763609A688B}.Release|x64.Build.0 = Release|Any CPU
{C498B46D-26EF-4AAE-ADFA-5763609A688B}.Release|x86.ActiveCfg = Release|Any CPU
{C498B46D-26EF-4AAE-ADFA-5763609A688B}.Release|x86.Build.0 = Release|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Debug|x64.ActiveCfg = Debug|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Debug|x64.Build.0 = Debug|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Debug|x86.ActiveCfg = Debug|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Debug|x86.Build.0 = Debug|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Release|Any CPU.Build.0 = Release|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Release|x64.ActiveCfg = Release|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Release|x64.Build.0 = Release|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Release|x86.ActiveCfg = Release|Any CPU
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -258,6 +272,7 @@ Global
{E2016F0E-AEB0-4D33-9456-33DCCBD41F09} = {18B7CFF6-C18A-48FF-ADB2-557333ABCD6D}
{5EADDCA9-0316-4596-85B1-6C91EDFE8460} = {18B7CFF6-C18A-48FF-ADB2-557333ABCD6D}
{C498B46D-26EF-4AAE-ADFA-5763609A688B} = {3566B926-8E32-4B0D-8DC0-6DB1EB82D2CB}
{6DAC88A4-9DCF-490B-81D3-B0AA72993EA4} = {3566B926-8E32-4B0D-8DC0-6DB1EB82D2CB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {087BE4A7-5329-4F83-84DF-7AA56A3944EE}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ build_script:
- cmd: dotnet cake --target=Full

after_build:
- ps: .\tools\csmacnz.coveralls.exe --reportgenerator -i .\outputs\tests\report --repoToken $env:COVERALLS_REPO_TOKEN --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_JOB_ID
- ps: if ($env:COVERALLS_REPO_TOKEN -ne $null) { .\tools\csmacnz.coveralls.exe --reportgenerator -i .\outputs\tests\report --repoToken $env:COVERALLS_REPO_TOKEN --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_JOB_ID }
5 changes: 3 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Task("RunTests")
.IsDependentOn("Build")
.Does<BuildState>(state =>
{
var projectFiles = GetFiles($"{state.Paths.TestFolder}/**/*.csproj");
var projectFiles = GetFiles($"{state.Paths.TestFolder}/**/Tests.*.csproj");
bool success = true;
Expand All @@ -68,7 +68,8 @@ Task("RunTests")
var dotCoverSettings = new DotCoverCoverSettings()
.WithFilter("+:Nybus*")
.WithFilter("-:Tests*");
.WithFilter("-:Tests*")
.WithFilter("-:TestUtils");
var settings = new DotNetCoreTestSettings
{
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Authors>Renato Golia</Authors>
<Version>1.0.0-alpha001</Version>
<Version>1.0.0-alpha002</Version>
<Company>Nybus Project</Company>
<Product>Nybus</Product>
<license>https://github.com/Nybus-project/Nybus/blob/master/LICENSE</license>
Expand Down
4 changes: 2 additions & 2 deletions src/engines/Nybus.Engine.RabbitMq/ObservableConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public void HandleBasicCancel(string consumerTag)
{
_consumerTags.Remove(consumerTag);
}

ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));
}
}

Expand All @@ -69,8 +71,6 @@ public void HandleBasicConsumeOk(string consumerTag)
{
_consumerTags.Add(consumerTag);
}

ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));
}
}

Expand Down
23 changes: 23 additions & 0 deletions tests/TestUtils/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Nybus;

namespace Tests
{
public class FirstTestCommand : ICommand
{
public string Message { get; set; }
}

public class SecondTestCommand : ICommand { }

public class FirstTestCommandHandler : ICommandHandler<FirstTestCommand>
{
public Task HandleAsync(IDispatcher dispatcher, ICommandContext<FirstTestCommand> incomingCommand)
{
throw new NotImplementedException();
}
}
}
21 changes: 21 additions & 0 deletions tests/TestUtils/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Nybus;
using Nybus.Utils;

namespace Tests
{
public class FirstTestEvent : IEvent { }

public class SecondTestEvent : IEvent { }

public class FirstTestEventHandler : IEventHandler<FirstTestEvent>
{
public Task HandleAsync(IDispatcher dispatcher, IEventContext<FirstTestEvent> incomingEvent)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,4 @@ public Task NotifyFail(Message message)
}
}


public class FirstTestCommand : ICommand
{
public string Message { get; set; }
}

public class SecondTestCommand : ICommand { }

public class FirstTestEvent : IEvent { }

public class SecondTestEvent : IEvent { }
}
32 changes: 32 additions & 0 deletions tests/TestUtils/TestClock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
using Nybus.Utils;

namespace Tests
{
public class TestClock : IClock
{
public TestClock(DateTimeOffset initialTime)
{
Now = initialTime;
}

public TestClock() : this(DateTimeOffset.UtcNow)
{

}

public DateTimeOffset Now { get; private set; }

public void AdvanceBy(TimeSpan interval)
{
Now += interval;
}

public void SetTo(DateTimeOffset newValue)
{
Now = newValue;
}
}
}
48 changes: 48 additions & 0 deletions tests/TestUtils/TestNybusConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Nybus.Configuration;

namespace Tests
{
public class TestNybusConfigurator : INybusConfigurator
{
public void UseConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration, string sectionName = "Nybus")
{
Configuration = configuration.GetSection(sectionName);
}

private readonly List<Action<IServiceCollection>> _serviceConfigurations = new List<Action<IServiceCollection>>();

public void AddServiceConfiguration(Action<IServiceCollection> configurator)
{
_serviceConfigurations.Add(configurator);
}

public void ApplyServiceConfigurations(IServiceCollection services)
{
foreach (var sc in _serviceConfigurations)
sc(services);
}

private readonly List<Action<ISubscriptionBuilder>> _subscriptionBuilders = new List<Action<ISubscriptionBuilder>>();

public void AddSubscription(Action<ISubscriptionBuilder> configurator)
{
_subscriptionBuilders.Add(configurator);
}

public void ApplySubscriptions(ISubscriptionBuilder builder)
{
foreach (var sb in _subscriptionBuilders)
sb(builder);
}

public Microsoft.Extensions.Configuration.IConfiguration Configuration { get; private set; }

public void Configure(Action<INybusConfiguration> configuration)
{
throw new NotImplementedException();
}
}
}
12 changes: 12 additions & 0 deletions tests/TestUtils/TestUtils.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Nybus.Abstractions\Nybus.Abstractions.csproj" />
</ItemGroup>

</Project>
18 changes: 0 additions & 18 deletions tests/Tests.Integration.Nybus/TestTypes.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Nybus\Nybus.csproj" />
<ProjectReference Include="..\TestUtils\TestUtils.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Nybus.Configuration;

namespace Tests.Configuration
{
[TestFixture]
public class ConfigurationExceptionTests
{
[Test, AutoMoqData]
public void ConfigurationException_can_be_built_with_message(string message)
{
var sut = new ConfigurationException(message);

Assert.That(sut.Message, Is.EqualTo(message));
}

[Test, AutoMoqData]
public void ConfigurationException_can_be_built_with_message_and_innerException(string message, Exception innerException)
{
var sut = new ConfigurationException(message, innerException);

Assert.That(sut.Message, Is.EqualTo(message));

Assert.That(sut.InnerException, Is.SameAs(innerException));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Nybus.Abstractions\Nybus.Abstractions.csproj" />
<ProjectReference Include="..\TestUtils\TestUtils.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Nybus.Configuration;
using RabbitMQ.Client;

namespace Tests.Configuration
{

[TestFixture]
public class RabbitMqConfigurationTests
{
[Test, AutoMoqData]
public void Serializer_can_be_assigned(RabbitMqConfiguration sut, ISerializer serializer)
{
sut.Serializer = serializer;

Assert.That(sut.Serializer, Is.SameAs(serializer));
}

[Test, AutoMoqData]
public void Serializer_can_be_accessed(RabbitMqConfiguration sut)
{
Assert.That(sut.Serializer, Is.Not.Null);
}

[Test, AutoMoqData]
public void ConnectionFactory_can_be_assigned(RabbitMqConfiguration sut, IConnectionFactory connectionFactory)
{
sut.ConnectionFactory = connectionFactory;

Assert.That(sut.ConnectionFactory, Is.SameAs(connectionFactory));
}

[Test, AutoMoqData]
public void ConnectionFactory_can_be_accessed(RabbitMqConfiguration sut)
{
Assert.That(sut.ConnectionFactory, Is.Not.Null);
}
}
}
Loading

0 comments on commit 979de72

Please sign in to comment.