Ejemplo n.º 1
0
        public async Task ApplyAsync_PrefersEndpointsWithODataRoutingMetadata()
        {
            // Arrange
            IEdmModel             model           = EdmCoreModel.Instance;
            IODataRoutingMetadata routingMetadata = new ODataRoutingMetadata("odata", model, new ODataPathTemplate());

            Endpoint[] endpoints = new[]
            {
                CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "get" })),
                CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "post" })),
                CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "delete" }))
            };

            CandidateSet candidateSet = CreateCandidateSet(endpoints);

            HttpContext httpContext = CreateHttpContext("POST");

            HttpMethodMatcherPolicy httpMethodPolicy = new HttpMethodMatcherPolicy();

            ODataRoutingMatcherPolicy policy = CreatePolicy();

            // Act
            await httpMethodPolicy.ApplyAsync(httpContext, candidateSet);

            await policy.ApplyAsync(httpContext, candidateSet);

            // Assert
            Assert.False(candidateSet.IsValidCandidate(0));
            Assert.True(candidateSet.IsValidCandidate(1));
            Assert.False(candidateSet.IsValidCandidate(2));
        }
Ejemplo n.º 2
0
        public void AppliesToEndpoints_EndpointWithoutODataRoutingMetadata_ReturnsFalse()
        {
            // Arrange
            Endpoint[] endpoints = new[] { CreateEndpoint("/", null), };

            ODataRoutingMatcherPolicy policy = CreatePolicy();

            // Act
            bool result = policy.AppliesToEndpoints(endpoints);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 3
0
        public void AppliesToEndpoints_EndpointHasODataRoutingMetadata_ReturnsTrue()
        {
            // Arrange
            IODataRoutingMetadata routingMetadata = new ODataRoutingMetadata();

            Endpoint[] endpoints = new[]
            {
                CreateEndpoint("/", routingMetadata),
                CreateEndpoint("/", null),
            };

            ODataRoutingMatcherPolicy policy = CreatePolicy();

            // Act
            bool result = policy.AppliesToEndpoints(endpoints);

            // Assert
            Assert.True(result);
        }