Adding more specific error for private configure

This commit is contained in:
John Luo 2015-10-20 10:43:43 -07:00
parent 77f29142aa
commit 0394987271
3 changed files with 43 additions and 2 deletions

View File

@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Hosting.Startup
{
if (required)
{
throw new InvalidOperationException(string.Format("A method named '{0}' or '{1}' in the type '{2}' could not be found.",
throw new InvalidOperationException(string.Format("A public method named '{0}' or '{1}' could not be found in the '{2}' type.",
methodNameWithEnv,
methodNameWithNoEnv,
startupType.FullName));

View File

@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNet.Hosting.Fakes
{
public class StartupPrivateConfigure
{
public StartupPrivateConfigure()
{
}
public void ConfigureServices(IServiceCollection services)
{
}
private void Configure(IApplicationBuilder builder)
{
}
}
}

View File

@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Hosting.Tests
var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);
var ex = Assert.Throws<InvalidOperationException>(() => loader.LoadMethods(type, diagnosticMessages));
Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message);
Assert.Equal("A public method named 'ConfigureBoom' or 'Configure' could not be found in the 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' type.", ex.Message);
}
[Fact]
@ -98,6 +98,22 @@ namespace Microsoft.AspNet.Hosting.Tests
var ex = Assert.Throws<InvalidOperationException>(() => loader.LoadMethods(type, diagnosticMessages));
Assert.Equal("Having multiple overloads of method 'Configure' is not supported.", ex.Message);
}
[Fact]
public void StartupWithPrivateConfiguresThrows()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<IFakeStartupCallback>(this);
var services = serviceCollection.BuildServiceProvider();
var diagnosticMessages = new List<string>();
var hostingEnv = new HostingEnvironment { EnvironmentName = "PrivateConfigure" };
var loader = new StartupLoader(services, hostingEnv);
var type = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);
var ex = Assert.Throws<InvalidOperationException>(() => loader.LoadMethods(type, diagnosticMessages));
Assert.Equal("A public method named 'ConfigurePrivateConfigure' or 'Configure' could not be found in the 'Microsoft.AspNet.Hosting.Fakes.StartupPrivateConfigure' type.", ex.Message);
}
[Fact]
public void StartupWithTwoConfigureServicesThrows()