Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
1.3 KiB

using System;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
namespace Volo.DependencyInjection.Tests
{
public static class ServiceCollectionShouldlyExtensions
{
public static void ShouldContainTransient(this IServiceCollection services, Type type)
{
var serviceDescriptor = services.FirstOrDefault(s => s.ServiceType == type);
serviceDescriptor.ImplementationType.ShouldBe(type);
serviceDescriptor.ShouldNotBeNull();
serviceDescriptor.ImplementationFactory.ShouldBeNull();
serviceDescriptor.ImplementationInstance.ShouldBeNull();
serviceDescriptor.Lifetime.ShouldBe(ServiceLifetime.Transient);
}
public static void ShouldContainSingleton(this IServiceCollection services, Type type)
{
var serviceDescriptor = services.FirstOrDefault(s => s.ServiceType == type);
serviceDescriptor.ImplementationType.ShouldBe(type);
serviceDescriptor.ShouldNotBeNull();
serviceDescriptor.ImplementationFactory.ShouldBeNull();
serviceDescriptor.ImplementationInstance.ShouldBeNull();
serviceDescriptor.Lifetime.ShouldBe(ServiceLifetime.Singleton);
}
}
}