From a634f6b116ceeef5c36d928ec4e15ac5d01cd75b Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Sat, 25 Aug 2018 21:43:06 -0700 Subject: [PATCH] add another test --- .../Internal/MvcEndpointDataSourceTests.cs | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/MvcEndpointDataSourceTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/MvcEndpointDataSourceTests.cs index e4230b1d56..416e359291 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/MvcEndpointDataSourceTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/MvcEndpointDataSourceTests.cs @@ -656,7 +656,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal new { controller = "Foo", action = "Bar", subarea = "test" }); var expectedDefaults = new RouteValueDictionary( new { controller = "Foo", action = "Bar", subarea = "test", subscription = "general" }); - var actionDescriptorCollection = GetActionDescriptorCollection(requiredValues: requiredValues); + var actionDescriptorCollection = GetActionDescriptorCollection(requiredValues); var dataSource = CreateMvcEndpointDataSource(actionDescriptorCollection); dataSource.ConventionalEndpointInfos.Add( CreateEndpointInfo( @@ -674,6 +674,60 @@ namespace Microsoft.AspNetCore.Mvc.Internal AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); } + [Fact] + public void RequiredValues_DoesNotMatchParameterDefaults_Included() + { + // Arrange + var action = new RouteValueDictionary( + new { controller = "Foo", action = "Baz", }); // Doesn't match default + var expectedDefaults = new RouteValueDictionary( + new { controller = "Foo", action = "Baz", }); + var actionDescriptorCollection = GetActionDescriptorCollection(action); + var dataSource = CreateMvcEndpointDataSource(actionDescriptorCollection); + dataSource.ConventionalEndpointInfos.Add( + CreateEndpointInfo( + string.Empty, + "{controller}/{action}/{id?}", + defaults: new RouteValueDictionary(new { controller = "Foo", action = "Bar" }))); + + // Act + var endpoints = dataSource.Endpoints; + + // Assert + var endpoint = Assert.Single(endpoints); + var matcherEndpoint = Assert.IsType(endpoint); + Assert.Equal("Foo/Baz/{id?}", matcherEndpoint.RoutePattern.RawText); + AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); + } + + [Fact] + public void RequiredValues_DoesNotMatchNonParameterDefaults_FilteredOut() + { + // Arrange + var action1 = new RouteValueDictionary( + new { controller = "Foo", action = "Bar", }); + var action2 = new RouteValueDictionary( + new { controller = "Foo", action = "Baz", }); // Doesn't match default + var expectedDefaults = new RouteValueDictionary( + new { controller = "Foo", action = "Bar", }); + var actionDescriptorCollection = GetActionDescriptorCollection(action1, action2); + var dataSource = CreateMvcEndpointDataSource(actionDescriptorCollection); + dataSource.ConventionalEndpointInfos.Add( + CreateEndpointInfo( + string.Empty, + "Blog/{*slug}", + defaults: new RouteValueDictionary(new { controller = "Foo", action = "Bar" }))); + + // Act + var endpoints = dataSource.Endpoints; + + // Assert + var endpoint = Assert.Single(endpoints); + var matcherEndpoint = Assert.IsType(endpoint); + Assert.Equal("Blog/{*slug}", matcherEndpoint.RoutePattern.RawText); + AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); + } + [Fact] public void RequiredValues_HavingNull_AndNotPresentInDefaultValues_IsAddedToDefaultValues() {