Add UseMvc unit tests (#8164)
This commit is contained in:
parent
fbae57cde1
commit
41de26a546
|
|
@ -2,7 +2,14 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Builder.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -49,5 +56,61 @@ namespace Microsoft.AspNetCore.Mvc.Core.Builder
|
|||
"in the application startup code.",
|
||||
exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseMvc_GlobalRoutingDisabled_NoEndpointInfos()
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore"));
|
||||
services.AddLogging();
|
||||
services.AddMvcCore(o => o.EnableGlobalRouting = false);
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var appBuilder = new ApplicationBuilder(serviceProvider);
|
||||
|
||||
// Act
|
||||
appBuilder.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
|
||||
var mvcEndpointDataSource = appBuilder.ApplicationServices
|
||||
.GetRequiredService<IEnumerable<EndpointDataSource>>()
|
||||
.OfType<MvcEndpointDataSource>()
|
||||
.First();
|
||||
|
||||
Assert.Empty(mvcEndpointDataSource.ConventionalEndpointInfos);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseMvc_GlobalRoutingEnabled_NoEndpointInfos()
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<DiagnosticSource>(new DiagnosticListener("Microsoft.AspNetCore"));
|
||||
services.AddLogging();
|
||||
services.AddMvcCore(o => o.EnableGlobalRouting = true);
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var appBuilder = new ApplicationBuilder(serviceProvider);
|
||||
|
||||
// Act
|
||||
appBuilder.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
|
||||
var mvcEndpointDataSource = appBuilder.ApplicationServices
|
||||
.GetRequiredService<IEnumerable<EndpointDataSource>>()
|
||||
.OfType<MvcEndpointDataSource>()
|
||||
.First();
|
||||
|
||||
var endpointInfo = Assert.Single(mvcEndpointDataSource.ConventionalEndpointInfos);
|
||||
Assert.Equal("default", endpointInfo.Name);
|
||||
Assert.Equal("{controller=Home}/{action=Index}/{id?}", endpointInfo.Template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue