Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Moar tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Aug 17, 2016
1 parent e81d8f4 commit 54ce5ee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Hosting.Tests.Internal
{
public class MyBadContainerFactory : IServiceProviderFactory<MyContainer>
{
public MyContainer CreateBuilder(IServiceCollection services)
{
var container = new MyContainer();
container.Populate(services);
return container;
}

public IServiceProvider CreateServiceProvider(MyContainer containerBuilder)
{
containerBuilder.Build();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public IServiceProvider CreateServiceProvider(MyContainer containerBuilder)
return containerBuilder;
}
}

}
16 changes: 16 additions & 0 deletions test/Microsoft.AspNetCore.Hosting.Tests/StartupManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ public void CustomServiceProviderFactoryFailsWithOverloadsInStartup()
Assert.Throws<InvalidOperationException>(() => StartupLoader.LoadMethods(services, typeof(MyContainerStartupWithOverloads), "Development"));
}

[Fact]
public void BadServiceProviderFactoryFailsThatReturnsNullServiceProviderOverriddenByDefault()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<MyContainer>, MyBadContainerFactory>();
var services = serviceCollection.BuildServiceProvider();

var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), "Development");

var app = new ApplicationBuilder(services);
app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);

Assert.NotNull(app.ApplicationServices);
Assert.IsNotType(typeof(MyContainer), app.ApplicationServices);
}

public class MyContainerStartupWithOverloads
{
public void ConfigureServices(IServiceCollection services)
Expand Down

0 comments on commit 54ce5ee

Please sign in to comment.