public void AttributeRoute_GenerateLink_OutOfArea_IgnoresAmbientValue() { // Arrange var entry1 = CreateGenerationEntry("Help/Store", new { area = "Help", action = "Edit", controller = "Store" }); entry1.Precedence = 1; var entry2 = CreateGenerationEntry("Store", new { area = (string)null, action = "Edit", controller = "Store" }); entry2.Precedence = 2; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry1, entry2); var context = CreateVirtualPathContext( values: new { action = "Edit", controller = "Store" }, ambientValues: new { area = "Blog" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal("Store", path); }
public void AttributeRoute_GenerateLink_RejectedByHandler() { // Arrange var entry1 = CreateGenerationEntry("api/Store", new { action = "Edit", controller = "Store" }); var entry2 = CreateGenerationEntry("api2/{controller}", new { action = "Edit", controller = "Store" }); var next = new StubRouter(); var callCount = 0; next.GenerationDelegate = (VirtualPathContext c) => { // Reject entry 1. callCount++; return(!c.ProvidedValues.Contains(new KeyValuePair <string, object>( AttributeRouting.RouteGroupKey, entry1.RouteGroup))); }; var route = CreateAttributeRoute(next, entry1, entry2); var context = CreateVirtualPathContext(new { action = "Edit", controller = "Store" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal("api2/Store", path); Assert.Equal(2, callCount); }
public void AttributeRoute_GenerateLink_Match_WithMoreParameters() { // Arrange var entry = CreateGenerationEntry( "api/{area}/dosomething/{controller}/{action}", new { action = "Index", controller = "Store", area = "AwesomeCo" }); var expectedValues = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "area", "AwesomeCo" }, { "controller", "Store" }, { "action", "Index" }, { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext( new { action = "Index", controller = "Store" }, new { area = "AwesomeCo" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal("api/AwesomeCo/dosomething/Store/Index", path); Assert.Equal(expectedValues, next.GenerationContext.ProvidedValues); }
public void SetUp() { _model = new TestModel(); _router = new StubRouter<TestModel>(_model); _stringSubject = new StubSubject<string>(); _intSubject = new StubSubject<int>(); _decimalSubject = new StubSubject<decimal>(); }
public void AttributeRoute_GenerateLink_NoMatch_WithConstraint() { // Arrange var entry = CreateGenerationEntry("api/Store/{action}/{id:int}", new { action = "Index", controller = "Store" }); var route = CreateAttributeRoute(entry); var expectedValues = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "id", "5" }, { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store", id = "heyyyy" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Null(path); }
public void AttributeRoute_GenerateLink_ForwardsRouteGroup() { // Arrange var entry = CreateGenerationEntry("api/Store", new { action = "Index", controller = "Store" }); var expectedValues = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal(expectedValues, next.GenerationContext.ProvidedValues); }
public void AttributeRoute_GenerateLink_ForwardsRouteGroup() { // Arrange var entry = CreateGenerationEntry("api/Store", new { action = "Index", controller = "Store" }); var expectedValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal(expectedValues, next.GenerationContext.ProvidedValues); }
public void AttributeRoute_GenerateLink_NoMatch_WithConstraint() { // Arrange var entry = CreateGenerationEntry("api/Store/{action}/{id:int}", new { action = "Index", controller = "Store" }); var route = CreateAttributeRoute(entry); var expectedValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "id", "5" }, { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store", id = "heyyyy" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Null(path); }
public void AttributeRoute_GenerateLink_Match_WithConstraint() { // Arrange var entry = CreateGenerationEntry("api/Store/{action}/{id:int}", new { action = "Index", controller = "Store" }); var expectedValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "action", "Index" }, { "id", 5 }, { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store", id = 5 }); // Act var pathData = route.GetVirtualPath(context); // Assert Assert.NotNull(pathData); Assert.Equal(new PathString("/api/Store/Index/5"), pathData.VirtualPath); Assert.Same(route, pathData.Router); Assert.Empty(pathData.DataTokens); Assert.Equal(expectedValues, next.GenerationContext.ProvidedValues); }
public void TreeRouter_GenerateLink_ToArea_PredecedenceReversed() { // Arrange var entry1 = CreateGenerationEntry("Help/Store", new { area = "Help", action = "Edit", controller = "Store" }); entry1.GenerationPrecedence = 1; var entry2 = CreateGenerationEntry("Store", new { area = (string)null, action = "Edit", controller = "Store" }); entry2.GenerationPrecedence = 2; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry1, entry2); var context = CreateVirtualPathContext(new { area = "Help", action = "Edit", controller = "Store" }); // Act var pathData = route.GetVirtualPath(context); // Assert Assert.NotNull(pathData); Assert.Equal("/Help/Store", pathData.VirtualPath); Assert.Same(route, pathData.Router); Assert.Empty(pathData.DataTokens); }
public void TreeRouter_GenerateLink_NoMatch_WithConstraint() { // Arrange var entry = CreateGenerationEntry("api/Store/{action}/{id:int}", new { action = "Index", controller = "Store" }); var route = CreateAttributeRoute(entry); var next = new StubRouter(); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store", id = "heyyyy" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Null(path); }
public void TreeRouter_GenerateLink_Match_WithMoreParameters() { // Arrange var entry = CreateGenerationEntry( "api/{area}/dosomething/{controller}/{action}", new { action = "Index", controller = "Store", area = "AwesomeCo" }); var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext( new { action = "Index", controller = "Store" }, new { area = "AwesomeCo" }); // Act var pathData = route.GetVirtualPath(context); // Assert Assert.NotNull(pathData); Assert.Equal("/api/AwesomeCo/dosomething/Store/Index", pathData.VirtualPath); Assert.Same(route, pathData.Router); Assert.Empty(pathData.DataTokens); }
public void AttributeRoute_GenerateLink_ToArea_WithAmbientValues() { // Arrange var entry1 = CreateGenerationEntry("Help/Store", new { area = "Help", action = "Edit", controller = "Store" }); entry1.Precedence = 1; var entry2 = CreateGenerationEntry("Store", new { area = (string)null, action = "Edit", controller = "Store" }); entry2.Precedence = 2; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry1, entry2); var context = CreateVirtualPathContext( values: new { action = "Edit", controller = "Store" }, ambientValues: new { area = "Help" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal("Help/Store", path); }
public void AttributeRoute_GenerateLink_Match_WithMoreParameters() { // Arrange var entry = CreateGenerationEntry( "api/{area}/dosomething/{controller}/{action}", new { action = "Index", controller = "Store", area = "AwesomeCo" }); var expectedValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "area", "AwesomeCo" }, { "controller", "Store" }, { "action", "Index" }, { AttributeRouting.RouteGroupKey, entry.RouteGroup }, }; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext( new { action = "Index", controller = "Store" }, new { area = "AwesomeCo" }); // Act var path = route.GetVirtualPath(context); // Assert Assert.Equal("api/AwesomeCo/dosomething/Store/Index", path); Assert.Equal(expectedValues, next.GenerationContext.ProvidedValues); }
public void AttributeRoute_GenerateLink_RejectedByHandler() { // Arrange var entry1 = CreateGenerationEntry("api/Store", new { action = "Edit", controller = "Store" }); var entry2 = CreateGenerationEntry("api2/{controller}", new { action = "Edit", controller = "Store" }); var next = new StubRouter(); var callCount = 0; next.GenerationDelegate = (VirtualPathContext c) => { // Reject entry 1. callCount++; return !c.ProvidedValues.Contains(new KeyValuePair<string, object>( AttributeRouting.RouteGroupKey, entry1.RouteGroup)); }; var route = CreateAttributeRoute(next, entry1, entry2); var context = CreateVirtualPathContext(new { action = "Edit", controller = "Store" }); // Act var pathData = route.GetVirtualPath(context); // Assert Assert.NotNull(pathData); Assert.Equal(new PathString("/api2/Store"), pathData.VirtualPath); Assert.Same(route, pathData.Router); Assert.Empty(pathData.DataTokens); Assert.Equal(2, callCount); }
public void AttributeRoute_GenerateLink_OutOfArea_IgnoresAmbientValue() { // Arrange var entry1 = CreateGenerationEntry("Help/Store", new { area = "Help", action = "Edit", controller = "Store" }); entry1.Precedence = 1; var entry2 = CreateGenerationEntry("Store", new { area = (string)null, action = "Edit", controller = "Store" }); entry2.Precedence = 2; var next = new StubRouter(); var route = CreateAttributeRoute(next, entry1, entry2); var context = CreateVirtualPathContext( values: new { action = "Edit", controller = "Store" }, ambientValues: new { area = "Blog" }); // Act var pathData = route.GetVirtualPath(context); // Assert Assert.NotNull(pathData); Assert.Equal(new PathString("/Store"), pathData.VirtualPath); Assert.Same(route, pathData.Router); Assert.Empty(pathData.DataTokens); }
public void TreeRouter_GenerateLink_Match_WithConstraint() { // Arrange var entry = CreateGenerationEntry("api/Store/{action}/{id:int}", new { action = "Index", controller = "Store" }); var next = new StubRouter(); var route = CreateAttributeRoute(next, entry); var context = CreateVirtualPathContext(new { action = "Index", controller = "Store", id = 5 }); // Act var pathData = route.GetVirtualPath(context); // Assert Assert.NotNull(pathData); Assert.Equal("/api/Store/Index/5", pathData.VirtualPath); Assert.Same(route, pathData.Router); Assert.Empty(pathData.DataTokens); }