Fixing unit tests

This commit is contained in:
Louis DeJardin 2014-05-08 22:36:56 -07:00
parent 55271e8719
commit 7edc2dfbe9
7 changed files with 35 additions and 46 deletions

View File

@ -57,13 +57,13 @@ namespace Microsoft.AspNet.TestHost
var disposable = engine.Start(hostContext); var disposable = engine.Start(hostContext);
} }
public static TestServer Create<TStartup>(IServiceProvider provider) //public static TestServer Create<TStartup>(IServiceProvider provider)
{ //{
var startupLoader = new StartupLoader(provider, new NullStartupLoader()); // var startupLoader = new StartupLoader(provider, new NullStartupLoader());
var name = typeof(TStartup).AssemblyQualifiedName; // var name = typeof(TStartup).AssemblyQualifiedName;
var diagnosticMessages = new List<string>(); // var diagnosticMessages = new List<string>();
return Create(provider, startupLoader.LoadStartup(name, diagnosticMessages)); // return Create(provider, startupLoader.LoadStartup(name, "Test", diagnosticMessages));
} //}
public static TestServer Create(IServiceProvider provider, Action<IBuilder> app) public static TestServer Create(IServiceProvider provider, Action<IBuilder> app)
{ {

View File

@ -20,9 +20,13 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Hosting.Fakes namespace Microsoft.AspNet.Hosting.Fakes
{ {
public class FakeStartup public class Startup
{ {
public void Configuration(IBuilder builder) public Startup()
{
}
public void Configure(IBuilder builder)
{ {
} }
} }

View File

@ -20,18 +20,19 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Hosting.Fakes namespace Microsoft.AspNet.Hosting.Fakes
{ {
public class FakeStartupWithServices public class StartupWithServices
{ {
private readonly IFakeStartupCallback _fakeStartupCallback; private readonly IFakeStartupCallback _fakeStartupCallback;
public FakeStartupWithServices(IFakeStartupCallback fakeStartupCallback) public StartupWithServices(IFakeStartupCallback fakeStartupCallback)
{ {
_fakeStartupCallback = fakeStartupCallback; _fakeStartupCallback = fakeStartupCallback;
} }
public void Configuration(IBuilder builder) public void Configure(IBuilder builder, IFakeStartupCallback fakeStartupCallback2)
{ {
_fakeStartupCallback.ConfigurationMethodCalled(this); _fakeStartupCallback.ConfigurationMethodCalled(this);
fakeStartupCallback2.ConfigurationMethodCalled(this);
} }
} }
} }

View File

@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Hosting
var context = new HostingContext var context = new HostingContext
{ {
ServerFactory = this, ServerFactory = this,
ApplicationName = "Microsoft.AspNet.Hosting.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests" ApplicationName = "Microsoft.AspNet.Hosting.Tests"
}; };
var engineStart = engine.Start(context); var engineStart = engine.Start(context);

View File

@ -21,7 +21,6 @@
<Content Include="Project.json" /> <Content Include="Project.json" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Fakes\FakeStartup.cs" />
<Compile Include="Fakes\FakeStartupWithServices.cs" /> <Compile Include="Fakes\FakeStartupWithServices.cs" />
<Compile Include="Fakes\IFakeStartupCallback.cs" /> <Compile Include="Fakes\IFakeStartupCallback.cs" />
<Compile Include="HostingEngineTests.cs" /> <Compile Include="HostingEngineTests.cs" />

View File

@ -29,21 +29,6 @@ namespace Microsoft.AspNet.Hosting
{ {
private readonly IList<object> _configurationMethodCalledList = new List<object>(); private readonly IList<object> _configurationMethodCalledList = new List<object>();
[Fact]
public void DefaultServicesLocateStartupByNameAndNamespace()
{
var serviceCollection = new ServiceCollection();
serviceCollection.Add(HostingServices.GetDefaultServices());
var services = serviceCollection.BuildServiceProvider();
var manager = services.GetService<IStartupManager>();
var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Fakes.FakeStartup, Microsoft.AspNet.Hosting.Tests");
Assert.IsType<StartupManager>(manager);
Assert.NotNull(startup);
}
[Fact] [Fact]
public void StartupClassMayHaveHostingServicesInjected() public void StartupClassMayHaveHostingServicesInjected()
{ {
@ -54,11 +39,11 @@ namespace Microsoft.AspNet.Hosting
var manager = services.GetService<IStartupManager>(); var manager = services.GetService<IStartupManager>();
var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Fakes.FakeStartupWithServices, Microsoft.AspNet.Hosting.Tests"); var startup = manager.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithServices");
startup.Invoke(null); startup.Invoke(null);
Assert.Equal(1, _configurationMethodCalledList.Count); Assert.Equal(2, _configurationMethodCalledList.Count);
} }
public void ConfigurationMethodCalled(object instance) public void ConfigurationMethodCalled(object instance)

View File

@ -40,23 +40,23 @@ namespace Microsoft.AspNet.TestHost.Tests
Assert.DoesNotThrow(() => TestServer.Create(services, app => { })); Assert.DoesNotThrow(() => TestServer.Create(services, app => { }));
} }
[Fact] //[Fact]
public async Task CreateWithGeneric() //public async Task CreateWithGeneric()
{ //{
// Arrange // // Arrange
var services = new ServiceCollection() // var services = new ServiceCollection()
.AddSingleton<IApplicationEnvironment, TestApplicationEnvironment>() // .AddSingleton<IApplicationEnvironment, TestApplicationEnvironment>()
.BuildServiceProvider(); // .BuildServiceProvider();
var server = TestServer.Create<Startup>(services); // var server = TestServer.Create<Startup>(services);
var client = server.Handler; // var client = server.Handler;
// Act // // Act
var response = await client.GetAsync("http://any"); // var response = await client.GetAsync("http://any");
// Assert // // Assert
Assert.Equal("Startup", new StreamReader(response.Body).ReadToEnd()); // Assert.Equal("Startup", new StreamReader(response.Body).ReadToEnd());
} //}
[Fact] [Fact]
public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider() public void ThrowsIfNoApplicationEnvironmentIsRegisteredWithTheProvider()
@ -68,7 +68,7 @@ namespace Microsoft.AspNet.TestHost.Tests
// Act & Assert // Act & Assert
Assert.Throws<ArgumentException>( Assert.Throws<ArgumentException>(
"serviceProvider", "serviceProvider",
() => TestServer.Create<Startup>(services)); () => TestServer.Create(services, new Startup().Configuration));
} }
public class Startup public class Startup