public void AreDependenciesRegistered() { PushToAzureDevOpsArtifacts task = new PushToAzureDevOpsArtifacts(); var collection = new ServiceCollection(); task.ConfigureServices(collection); var provider = collection.BuildServiceProvider(); foreach (var dependency in task.GetExecuteParameterTypes()) { var service = provider.GetRequiredService(dependency); service.Should().NotBeNull(); } DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { task.ConfigureServices(s); }, out string message ) .Should() .BeTrue(message); }
public void AreDependenciesRegistered() { var config = new ConfigurationBuilder(); var collection = new ServiceCollection(); Mock <IWebHostEnvironment> env = new Mock <IWebHostEnvironment>(); env.SetupGet(e => e.EnvironmentName).Returns(Environments.Development); collection.AddSingleton <IConfiguration>(config.Build()); collection.AddSingleton <Startup>(); collection.AddSingleton(env.Object); collection.AddSingleton(env.As <IHostEnvironment>().Object); using ServiceProvider provider = collection.BuildServiceProvider(); var startup = provider.GetRequiredService <Startup>(); IEnumerable <Type> controllerTypes = typeof(Startup).Assembly.ExportedTypes .Where(t => typeof(ControllerBase).IsAssignableFrom(t)); DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { foreach (ServiceDescriptor descriptor in collection) { s.Add(descriptor); } s.AddLogging(); s.AddOptions(); startup.ConfigureServices(s); }, out string message, additionalScopedTypes: controllerTypes).Should().BeTrue(message); }
public void AreDependenciesRegistered() { Environment.SetEnvironmentVariable("ENVIRONMENT", Environments.Development); var config = new ConfigurationBuilder(); var collection = new ServiceCollection(); // The only scenario we are worried about is when running in the ServiceHost ServiceHost.ConfigureDefaultServices(collection); collection.AddSingleton <IConfiguration>(config.Build()); collection.AddSingleton <Startup>(); using ServiceProvider provider = collection.BuildServiceProvider(); var startup = provider.GetRequiredService <Startup>(); IEnumerable <Type> controllerTypes = typeof(Startup).Assembly.ExportedTypes .Where(t => typeof(ControllerBase).IsAssignableFrom(t)); Assert.True(DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { foreach (ServiceDescriptor descriptor in collection) { s.Add(descriptor); } startup.ConfigureServices(s); }, out string message, additionalScopedTypes: controllerTypes), message); }
public void MissingOptional_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { s.AddSingleton <NeedsSimpleOptional>(); }, out string message); Assert.True(isCoherent, message); }
public void MissingSome_Fail() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { s.AddSingleton <NeedsSome>(); }, out string message); isCoherent.Should().BeFalse(message); message.Should().Contain(nameof(NeedsSome)); }
public void MissingSome_Fail() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { s.AddSingleton <NeedsSome>(); }, out string message); Assert.False(isCoherent); Assert.Contains(nameof(NeedsSome), message); }
public void AreDependenciesRegistered() { DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { Environment.SetEnvironmentVariable("ENVIRONMENT", "XUNIT"); ServiceHost.ConfigureDefaultServices(s); Program.Configure(s); }, out string message).Should().BeTrue(message); }
public void PresentOptional_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddSingleton <ISimple, Simple>(); s.AddSingleton <NeedsSimpleOptional>(); }, out string message); isCoherent.Should().BeTrue(message); }
public void SimpleScopedRequirementsMess_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddScoped <ISimple, Simple>(); s.AddScoped <NeedsSimple>(); }, out string message); isCoherent.Should().BeTrue(); }
public void SimpleRequirementsMess_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddSingleton <ISimple, Simple>(); s.AddSingleton <NeedsSimple>(); }, out string message); Assert.True(isCoherent, message); }
public void InstanceRequirementsMess_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddSingleton <IWithValue>(new WithValue("Test1")); s.AddSingleton <NeedsValue>(); }, out string message); Assert.True(isCoherent, message); }
public void ValueSome_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddSingleton <IWithValue>(new WithValue("Test1")); s.AddSingleton <NeedsSome>(); }, out string message); isCoherent.Should().BeTrue(); }
public void DelegateRequirementsMess_Pass() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddSingleton <ISimple, Simple>(); s.AddSingleton <IWithValue>(p => new WithValue(p.GetRequiredService <ISimple>().SimpleValue)); s.AddSingleton <NeedsValue>(); }, out string message); Assert.True(isCoherent, message); }
public void MismatchedScopes_Fail() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddScoped <ISimple, Simple>(); s.AddSingleton <NeedsSimple>(); }, out string message); isCoherent.Should().BeFalse(); message.Should().Contain(nameof(NeedsSimple)); }
public void AreDependenciesRegistered() { Assert.True(DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { Environment.SetEnvironmentVariable("ENVIRONMENT", "XUNIT"); ServiceHost.ConfigureDefaultServices(s); Program.Configure(s); s.AddScoped <FeedCleanerService>(); }, out string message), message); }
public void MismatchedScopes_Fail() { bool isCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddScoped <ISimple, Simple>(); s.AddSingleton <NeedsSimple>(); }, out string message); Assert.False(isCoherent); Assert.Contains(nameof(NeedsSimple), message); }
public void AreDependenciesRegistered() { DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { Environment.SetEnvironmentVariable("ENVIRONMENT", "XUNIT"); ServiceHost.ConfigureDefaultServices(s); Program.Configure(s); }, out string message, additionalScopedTypes: new[] { typeof(CoreHealthMonitorService) } ) .Should() .BeTrue(message); }
public void AreDependenciesRegistered() { DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { Environment.SetEnvironmentVariable("ENVIRONMENT", "XUNIT"); ServiceHost.ConfigureDefaultServices(s); Program.Configure(s); // The "IReliableStateManager" is provided by stateful services s.AddSingleton(Mock.Of <IReliableStateManager>()); s.AddScoped <DependencyUpdater>(); }, out string message).Should().BeTrue(message); }
public void AreDependenciesCoherent() { bool dependenciesCoherent = DependencyInjectionValidation.IsDependencyResolutionCoherent( collection => { var program = new Program(); program.ConfigureServiceCollection(collection); collection.AddSingleton <IConfiguration>(new ConfigurationBuilder().Build()); }, out string errorMessage, typeof(Program).Assembly.GetTypes().Where(t => t.GetCustomAttribute <CommandAttribute>() != null) ); dependenciesCoherent.Should().BeTrue(errorMessage); }
public void AreDependenciesRegistered() { DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { s.AddSingleton <IHostEnvironment>(new HostingEnvironment { EnvironmentName = Environments.Development }); s.AddBuildAssetRegistry(options => { options.UseInMemoryDatabase("BuildAssetRegistry"); options.EnableServiceProviderCaching(false); }); }, out string message).Should().BeTrue(message); }
public void AreDependenciesRegistered() { UpdatePublishedVersions task = new UpdatePublishedVersions(); var collection = new ServiceCollection(); task.ConfigureServices(collection); var provider = collection.BuildServiceProvider(); DependencyInjectionValidation.IsDependencyResolutionCoherent( s => { task.ConfigureServices(s); }, out string message, additionalSingletonTypes: task.GetExecuteParameterTypes() ) .Should() .BeTrue(message); }
public void Empty_Pass() { Assert.True(DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { }, out string message), message); }
public void Empty_Pass() { DependencyInjectionValidation.IsDependencyResolutionCoherent(s => { }, out string message).Should().BeTrue(); }