HttpRouteEntry IDirectRouteProvider.CreateRoute(DirectRouteProviderContext context) { Contract.Assert(context != null); DirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; HttpRouteValueDictionary builderConstraints = builder.Constraints; if (builderConstraints == null) { builder.Constraints = Constraints; } else { HttpRouteValueDictionary constraints = Constraints; if (constraints != null) { foreach (KeyValuePair <string, object> constraint in constraints) { builderConstraints.Add(constraint.Key, constraint.Value); } } } return(builder.Build()); }
public void CreateRoute_IfBuilderContraintsIsNotNullAndConstraintsPropertyIsNull_UsesBuilderConstraints() { // Arrange HttpRouteValueDictionary existingConstraints = new HttpRouteValueDictionary(); Mock <RouteProviderAttribute> productMock = CreateProductUnderTestMock(); productMock.SetupGet(p => p.Constraints).Returns((HttpRouteValueDictionary)null); IDirectRouteProvider product = productMock.Object; HttpRouteEntry expectedEntry = CreateEntry(); HttpRouteValueDictionary constraints = null; DirectRouteBuilder builder = null; builder = CreateBuilder(() => { constraints = builder.Constraints; return(null); }); builder.Constraints = existingConstraints; DirectRouteProviderContext context = CreateContext((i) => builder); // Act HttpRouteEntry ignore = product.CreateRoute(context); // Assert Assert.Same(existingConstraints, constraints); }
private static IHttpRoute BuildWithoutResolver(string template, IEnumerable <HttpActionDescriptor> actions) { DirectRouteProviderContext context = new DirectRouteProviderContext(null, actions, new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object); DirectRouteBuilder builder = context.CreateBuilder(template, constraintResolver: null); return(builder.Build().Route); }
public HttpRouteEntry CreateRoute(DirectRouteProviderContext context) { Contract.Assert(context != null); DirectRouteBuilder builder = context.CreateBuilder(_infoProvider.Template); Contract.Assert(builder != null); builder.Name = _infoProvider.Name; builder.Order = _infoProvider.Order; return(builder.Build()); }
private static IHttpRoute BuildWithResolver(string template, IInlineConstraintResolver constraintResolver) { HttpActionDescriptor[] actions = new HttpActionDescriptor[] { new ReflectedHttpActionDescriptor() }; DirectRouteProviderContext context = new DirectRouteProviderContext(null, actions, constraintResolver); // Act DirectRouteBuilder builder = context.CreateBuilder(template); IHttpRoute route = builder.Build().Route; // Assertions for default, unspecified behavior: Assert.NotNull(route); Assert.Equal(actions, route.DataTokens["actions"]); return(route); }
private static HttpRouteEntry CreateRouteEntry(string routePrefix, IDirectRouteProvider provider, IEnumerable <ReflectedHttpActionDescriptor> actions, IInlineConstraintResolver constraintResolver) { Contract.Assert(provider != null); DirectRouteProviderContext context = new DirectRouteProviderContext(routePrefix, actions, constraintResolver); HttpRouteEntry entry = provider.CreateRoute(context); if (entry == null) { throw Error.InvalidOperation(SRResources.TypeMethodMustNotReturnNull, typeof(IDirectRouteProvider).Name, "CreateRoute"); } return(entry); }
public void CreateRoute_IfBuilderContraintsIsNotNull_AddsConstraintsFromPropertyWhenBuilding() { // Arrange HttpRouteValueDictionary existingConstraints = new HttpRouteValueDictionary(); string existingConstraintKey = "ExistingContraintKey"; object existingConstraintValue = "ExistingContraint"; existingConstraints.Add(existingConstraintKey, existingConstraintValue); HttpRouteValueDictionary additionalConstraints = new HttpRouteValueDictionary(); string additionalConstraintKey = "NewConstraintKey"; string additionalConstraintValue = "NewConstraint"; additionalConstraints.Add(additionalConstraintKey, additionalConstraintValue); Mock <RouteProviderAttribute> productMock = CreateProductUnderTestMock(); productMock.SetupGet(p => p.Constraints).Returns(additionalConstraints); IDirectRouteProvider product = productMock.Object; HttpRouteEntry expectedEntry = CreateEntry(); HttpRouteValueDictionary constraints = null; DirectRouteBuilder builder = null; builder = CreateBuilder(() => { constraints = builder.Constraints; return(null); }); builder.Constraints = existingConstraints; DirectRouteProviderContext context = CreateContext((i) => builder); // Act HttpRouteEntry ignore = product.CreateRoute(context); // Assert Assert.Same(existingConstraints, constraints); Assert.Equal(2, constraints.Count); Assert.True(constraints.ContainsKey(existingConstraintKey)); Assert.Same(existingConstraintValue, constraints[existingConstraintKey]); Assert.True(constraints.ContainsKey(additionalConstraintKey)); Assert.Same(additionalConstraintValue, constraints[additionalConstraintKey]); }
public void CreateRoute_DelegatesToContextCreateBuilderBuild() { // Arrange string expectedTemplate = "RouteTemplate"; IDirectRouteProvider product = CreateProductUnderTest(expectedTemplate); HttpRouteEntry expectedEntry = CreateEntry(); DirectRouteBuilder builder = CreateBuilder(() => expectedEntry); DirectRouteProviderContext context = CreateContext((template) => template == expectedTemplate ? builder : new DirectRouteBuilder(new ReflectedHttpActionDescriptor[0])); // Act HttpRouteEntry entry = product.CreateRoute(context); // Assert Assert.Same(expectedEntry, entry); }
public void CreateRoute_UsesNamePropertyWhenBuilding() { // Arrange string expectedName = "RouteName"; RouteProviderAttribute product = CreateProductUnderTest(); product.Name = expectedName; string name = null; DirectRouteBuilder builder = null; builder = CreateBuilder(() => { name = builder.Name; return(null); }); DirectRouteProviderContext context = CreateContext((i) => builder); // Act HttpRouteEntry ignore = product.CreateRoute(context); // Assert Assert.Same(expectedName, name); }
public void CreateRoute_UsesOrderPropertyWhenBuilding() { // Arrange int expectedOrder = 123; RouteProviderAttribute product = CreateProductUnderTest(); product.Order = expectedOrder; int order = 0; DirectRouteBuilder builder = null; builder = CreateBuilder(() => { order = builder.Order; return(null); }); DirectRouteProviderContext context = CreateContext((i) => builder); // Act HttpRouteEntry ignore = product.CreateRoute(context); // Assert Assert.Equal(expectedOrder, order); }
internal HttpRouteEntry CreateRoute(DirectRouteProviderContext context) { return(((IDirectRouteProvider)this).CreateRoute(context)); }