public void ActionConstraint_Accept_MatchesForMachingRequestContentType(string contentType) { // Arrange var constraint = new ConsumesAttribute("application/json", "text/xml"); var action = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint, FilterScope.Action) } }; var context = new ActionConstraintContext(); context.Candidates = new List <ActionSelectorCandidate>() { new ActionSelectorCandidate(action, new [] { constraint }), }; context.CurrentCandidate = context.Candidates[0]; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert Assert.True(constraint.Accept(context)); }
public void EndpointConstraint_Accept_ForNoRequestType_ReturnsTrueForAllConstraints(string contentType) { // Arrange var constraint1 = new ConsumesAttribute("application/json"); var endpointWithConstraint = CreateEndpoint(constraint1); var constraint2 = new ConsumesAttribute("text/xml"); var endpointWithConstraint2 = CreateEndpoint(constraint2); var endpointWithoutConstraint = CreateEndpoint(); var context = new EndpointConstraintContext(); context.Candidates = new List <EndpointSelectorCandidate>() { new EndpointSelectorCandidate(endpointWithConstraint, new [] { constraint1 }), new EndpointSelectorCandidate(endpointWithConstraint2, new [] { constraint2 }), }; context.HttpContext = CreateHttpContext(contentType: contentType); // Act & Assert context.CurrentCandidate = context.Candidates[0]; Assert.True(constraint1.Accept(context)); context.CurrentCandidate = context.Candidates[1]; Assert.True(constraint2.Accept(context)); }
public void EndpointConstraint_Accept_ForNoMatchingCandidates_SelectsTheFirstCandidate(string contentType) { // Arrange var constraint1 = new ConsumesAttribute("application/json", "text/xml"); var endpoint1 = CreateEndpoint(constraint1); var constraint2 = new Mock <ITestEndpointConsumeConstraint>(); var endpoint2 = CreateEndpoint(constraint2.Object); constraint2.Setup(o => o.Accept(It.IsAny <EndpointConstraintContext>())) .Returns(false); var context = new EndpointConstraintContext(); context.Candidates = new List <EndpointSelectorCandidate>() { new EndpointSelectorCandidate(endpoint1, new [] { constraint1 }), new EndpointSelectorCandidate(endpoint2, new [] { constraint2.Object }), }; context.CurrentCandidate = context.Candidates[0]; context.HttpContext = CreateHttpContext(contentType: contentType); // Act & Assert Assert.True(constraint1.Accept(context)); }
public void EndpointConstraint_Accept_UnrecognizedMediaType_SelectsTheCandidateWithoutConstraintIfPresent(string contentType) { // Arrange var endpointWithoutConstraint = CreateEndpoint(); var constraint1 = new ConsumesAttribute("application/json"); var endpointWithConstraint = CreateEndpoint(constraint1); var constraint2 = new ConsumesAttribute("text/xml"); var endpointWithConstraint2 = CreateEndpoint(constraint2); var context = new EndpointConstraintContext(); context.Candidates = new List <EndpointSelectorCandidate>() { new EndpointSelectorCandidate(endpointWithConstraint, new [] { constraint1 }), new EndpointSelectorCandidate(endpointWithConstraint2, new [] { constraint2 }), new EndpointSelectorCandidate(endpointWithoutConstraint, new List <IEndpointConstraint>()), }; context.HttpContext = CreateHttpContext(contentType: contentType); // Act & Assert context.CurrentCandidate = context.Candidates[0]; Assert.False(constraint1.Accept(context)); context.CurrentCandidate = context.Candidates[1]; Assert.False(constraint2.Accept(context)); }
public void Accept_ForNoMatchingCandidates_SelectsTheFirstCandidate(string contentType) { // Arrange var constraint1 = new ConsumesAttribute("application/json", "text/xml"); var action1 = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint1, FilterScope.Action) } }; var constraint2 = new Mock<ITestConsumeConstraint>(); var action2 = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint2.Object, FilterScope.Action) } }; constraint2.Setup(o => o.Accept(It.IsAny<ActionConstraintContext>())) .Returns(false); var context = new ActionConstraintContext(); context.Candidates = new List<ActionSelectorCandidate>() { new ActionSelectorCandidate(action1, new [] { constraint1 }), new ActionSelectorCandidate(action2, new [] { constraint2.Object }), }; context.CurrentCandidate = context.Candidates[0]; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert Assert.True(constraint1.Accept(context)); }
public void EndpointConstraint_Accept_MatchesForMachingRequestContentType(string contentType) { // Arrange var constraint = new ConsumesAttribute("application/json", "text/xml"); var endpoint = CreateEndpoint(constraint); var context = new EndpointConstraintContext(); context.Candidates = new List <EndpointSelectorCandidate>() { new EndpointSelectorCandidate(endpoint, new [] { constraint }), }; context.CurrentCandidate = context.Candidates[0]; context.HttpContext = CreateHttpContext(contentType: contentType); // Act & Assert Assert.True(constraint.Accept(context)); }
public void ActionConstraint_Accept_UnrecognizedMediaType_SelectsTheCandidateWithoutConstraintIfPresent(string contentType) { // Arrange var actionWithoutConstraint = new ActionDescriptor(); var constraint1 = new ConsumesAttribute("application/json"); var actionWithConstraint = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint1, FilterScope.Action) } }; var constraint2 = new ConsumesAttribute("text/xml"); var actionWithConstraint2 = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint2, FilterScope.Action) } }; var context = new ActionConstraintContext(); context.Candidates = new List <ActionSelectorCandidate>() { new ActionSelectorCandidate(actionWithConstraint, new [] { constraint1 }), new ActionSelectorCandidate(actionWithConstraint2, new [] { constraint2 }), new ActionSelectorCandidate(actionWithoutConstraint, new List <IActionConstraint>()), }; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert context.CurrentCandidate = context.Candidates[0]; Assert.False(constraint1.Accept(context)); context.CurrentCandidate = context.Candidates[1]; Assert.False(constraint2.Accept(context)); }
public void ActionConstraint_Accept_ForNoRequestType_ReturnsTrueForAllConstraints(string contentType) { // Arrange var constraint1 = new ConsumesAttribute("application/json"); var actionWithConstraint = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint1, FilterScope.Action) } }; var constraint2 = new ConsumesAttribute("text/xml"); var actionWithConstraint2 = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint2, FilterScope.Action) } }; var actionWithoutConstraint = new ActionDescriptor(); var context = new ActionConstraintContext(); context.Candidates = new List <ActionSelectorCandidate>() { new ActionSelectorCandidate(actionWithConstraint, new [] { constraint1 }), new ActionSelectorCandidate(actionWithConstraint2, new [] { constraint2 }), }; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert context.CurrentCandidate = context.Candidates[0]; Assert.True(constraint1.Accept(context)); context.CurrentCandidate = context.Candidates[1]; Assert.True(constraint2.Accept(context)); }
public void ActionConstraint_Accept_ForNoMatchingCandidates_SelectsTheFirstCandidate(string contentType) { // Arrange var constraint1 = new ConsumesAttribute("application/json", "text/xml"); var action1 = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint1, FilterScope.Action) } }; var constraint2 = new Mock <ITestActionConsumeConstraint>(); var action2 = new ActionDescriptor() { FilterDescriptors = new List <FilterDescriptor>() { new FilterDescriptor(constraint2.Object, FilterScope.Action) } }; constraint2.Setup(o => o.Accept(It.IsAny <ActionConstraintContext>())) .Returns(false); var context = new ActionConstraintContext(); context.Candidates = new List <ActionSelectorCandidate>() { new ActionSelectorCandidate(action1, new [] { constraint1 }), new ActionSelectorCandidate(action2, new [] { constraint2.Object }), }; context.CurrentCandidate = context.Candidates[0]; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert Assert.True(constraint1.Accept(context)); }
public void Accept_MatchesForMachingRequestContentType(string contentType) { // Arrange var constraint = new ConsumesAttribute("application/json", "text/xml"); var action = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint, FilterScope.Action) } }; var context = new ActionConstraintContext(); context.Candidates = new List<ActionSelectorCandidate>() { new ActionSelectorCandidate(action, new [] { constraint }), }; context.CurrentCandidate = context.Candidates[0]; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert Assert.True(constraint.Accept(context)); }
public void Accept_ForNoRequestType_ReturnsTrueForAllConstraints(string contentType) { // Arrange var constraint1 = new ConsumesAttribute("application/json"); var actionWithConstraint = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint1, FilterScope.Action) } }; var constraint2 = new ConsumesAttribute("text/xml"); var actionWithConstraint2 = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint2, FilterScope.Action) } }; var actionWithoutConstraint = new ActionDescriptor(); var context = new ActionConstraintContext(); context.Candidates = new List<ActionSelectorCandidate>() { new ActionSelectorCandidate(actionWithConstraint, new [] { constraint1 }), new ActionSelectorCandidate(actionWithConstraint2, new [] { constraint2 }), }; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert context.CurrentCandidate = context.Candidates[0]; Assert.True(constraint1.Accept(context)); context.CurrentCandidate = context.Candidates[1]; Assert.True(constraint2.Accept(context)); }
public void Accept_UnrecognizedMediaType_SelectsTheCandidateWithoutConstraintIfPresent(string contentType) { // Arrange var actionWithoutConstraint = new ActionDescriptor(); var constraint1 = new ConsumesAttribute("application/json"); var actionWithConstraint = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint1, FilterScope.Action) } }; var constraint2 = new ConsumesAttribute("text/xml"); var actionWithConstraint2 = new ActionDescriptor() { FilterDescriptors = new List<FilterDescriptor>() { new FilterDescriptor(constraint2, FilterScope.Action) } }; var context = new ActionConstraintContext(); context.Candidates = new List<ActionSelectorCandidate>() { new ActionSelectorCandidate(actionWithConstraint, new [] { constraint1 }), new ActionSelectorCandidate(actionWithConstraint2, new [] { constraint2 }), new ActionSelectorCandidate(actionWithoutConstraint, new List<IActionConstraint>()), }; context.RouteContext = CreateRouteContext(contentType: contentType); // Act & Assert context.CurrentCandidate = context.Candidates[0]; Assert.False(constraint1.Accept(context)); context.CurrentCandidate = context.Candidates[1]; Assert.False(constraint2.Accept(context)); }