Skip to content

Commit

Permalink
Added integration test for MassTransit adapter package (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kralizek authored May 13, 2019
1 parent 2241b78 commit 8528a23
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using AutoFixture;
using AutoFixture.AutoMoq;
using AutoFixture.NUnit3;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Nybus.Logging;
using Nybus.MassTransit;

namespace Tests
{
Expand All @@ -26,6 +29,18 @@ private static IFixture CreateFixture()

fixture.Customize<NybusLoggerFactoryAdapter>(o => o.Without(p => p.MinimumLevel));

fixture.Customize<IConfiguration>(o => o.FromFactory((ConfigurationBuilder configurationBuilder, MassTransitConnectionDescriptor connectionDescriptor, string connectionStringName) =>
{
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
[$"ConnectionStrings:{connectionStringName}"] = connectionDescriptor.ToConnectionString()
});

var configuration = configurationBuilder.Build() as IConfiguration;

return configuration;
}));

return fixture;
}
}
Expand All @@ -48,5 +63,10 @@ public static bool For<TService>(this ServiceDescriptor descriptor)
{
return descriptor.ServiceType == typeof(TService);
}

public static string ToConnectionString(this MassTransitConnectionDescriptor connectionDescriptor)
{
return $"host={connectionDescriptor.Host};username={connectionDescriptor.UserName};password={connectionDescriptor.Password}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using AutoFixture.NUnit3;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Nybus;

namespace Tests
{
[TestFixture]
public class NybusLegacyServiceCollectionExtensionsIntegrationTests
{
[Test, AutoMoqData]
public void Bus_can_be_built([Frozen] string connectionStringName, IConfiguration configuration, ServiceCollection services, NybusLegacyConfiguration nybusConfiguration)
{
services.AddSingleton(configuration);

services.AddLogging();

services.AddNybusWithMassTransit(nybusConfiguration);

var serviceProvider = services.BuildServiceProvider();

var bus = serviceProvider.GetRequiredService<IBus>();

Assert.That(bus, Is.Not.Null);
}
}
}

0 comments on commit 8528a23

Please sign in to comment.