fm.Extensions.Testing.DependencyInjection 1.0.0

Provides a base class for tests based on Microsoft.Extensions.DependencyInjection. Use common Startup.cs patterns like ConfigureServices(...) and Configure(...) to setup your tests.

Commonly used types:
ServiceTestsBase

Example:
[TestClass]
public class DatabaseCleanupBackgroundServiceTests : ServiceTestsBase
{
   protected override void ConfigureServices([NotNull] IServiceCollection services)
   {
       base.ConfigureServices(services);

       services.AddSingleton<DatabaseCleanupBackgroundService>();
       services.AddSingleton(sp => A.Fake<IDatabaseCleanupService>());
       services.AddSingleton<ILogRecorder, LogRecorderProvider>();
   }

   protected override void Configure([NotNull] IServiceProvider services, [NotNull] ILoggerFactory loggerFactory)
   {
       base.Configure(services, loggerFactory);
       loggerFactory.AddLogRecorder(services);
   }

   [TestMethod]
   public void CleanupSuggestedFailTest()
   {
       IDatabaseCleanupService databaseCleanupService = this.GetRequiredService<IDatabaseCleanupService>();
       A.CallTo(() => databaseCleanupService.RemoveObsoleteProjectsAsync(A<CancellationToken>.Ignored)).Throws(new InvalidOperationException(nameof(this.CleanupSuggestedFailTest)));

       DatabaseCleanupBackgroundService service = this.GetRequiredService<DatabaseCleanupBackgroundService>();
       service.CleanupSuggested();

       service.WaitAll();

       ILogRecorder logRecorder = this.GetRequiredService<ILogRecorder>();
       logRecorder.Messages.Single(m => m.LogLevel == LogLevel.Error).Exception.ShouldBeOfType<InvalidOperationException>().Message.ShouldBe(nameof(this.CleanupSuggestedFailTest));
   }
}

There is a newer version of this package available.
See the version list below for details.
Install-Package fm.Extensions.Testing.DependencyInjection -Version 1.0.0
dotnet add package fm.Extensions.Testing.DependencyInjection --version 1.0.0
<PackageReference Include="fm.Extensions.Testing.DependencyInjection" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add fm.Extensions.Testing.DependencyInjection --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Release Notes

Initial release.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
4.2.1 147 2/26/2019
4.2.0 119 2/26/2019
4.0.0 3,840 10/11/2017
3.0.0 209 10/9/2017
2.0.0 431 2/27/2017
1.0.0 465 6/29/2016
Show less