public void OnResourceExecuting_ForAContentTypeMatch_IsNoOp(string contentType)
        {
            // Arrange
            var httpContext = new DefaultHttpContext();

            httpContext.Request.ContentType = contentType;
            var consumesFilter       = new ConsumesAttribute("application/json", "application/xml");
            var actionWithConstraint = new ActionDescriptor()
            {
                ActionConstraints = new List <IActionConstraintMetadata>()
                {
                    consumesFilter
                },
                FilterDescriptors =
                    new List <FilterDescriptor>()
                {
                    new FilterDescriptor(consumesFilter, FilterScope.Action)
                }
            };
            var actionContext            = new ActionContext(httpContext, new RouteData(), actionWithConstraint);
            var resourceExecutingContext = new ResourceExecutingContext(
                actionContext,
                new[] { consumesFilter },
                new List <IValueProviderFactory>());

            // Act
            consumesFilter.OnResourceExecuting(resourceExecutingContext);

            // Assert
            Assert.Null(resourceExecutingContext.Result);
        }
        public void OnResourceExecuting_NullOrEmptyRequestContentType_SetsUnsupportedMediaTypeResult(string contentType)
        {
            // Arrange
            var httpContext = new DefaultHttpContext();

            httpContext.Request.ContentType = contentType;
            var consumesFilter       = new ConsumesAttribute("application/json");
            var actionWithConstraint = new ActionDescriptor()
            {
                ActionConstraints = new List <IActionConstraintMetadata>()
                {
                    consumesFilter
                },
                FilterDescriptors =
                    new List <FilterDescriptor>()
                {
                    new FilterDescriptor(consumesFilter, FilterScope.Action)
                }
            };
            var actionContext = new ActionContext(httpContext, new RouteData(), actionWithConstraint);

            var resourceExecutingContext = new ResourceExecutingContext(
                actionContext,
                new[] { consumesFilter },
                new List <IValueProviderFactory>());

            // Act
            consumesFilter.OnResourceExecuting(resourceExecutingContext);

            // Assert
            Assert.NotNull(resourceExecutingContext.Result);
            Assert.IsType <UnsupportedMediaTypeResult>(resourceExecutingContext.Result);
        }
        public void OnResourceExecuting_ForAContentTypeMatch_IsNoOp(string contentType)
        {
            // Arrange
            var httpContext = new DefaultHttpContext();
            httpContext.Request.ContentType = contentType;
            var consumesFilter = new ConsumesAttribute("application/json", "application/xml");
            var actionWithConstraint = new ActionDescriptor()
            {
                ActionConstraints = new List<IActionConstraintMetadata>() { consumesFilter },
                FilterDescriptors =
                    new List<FilterDescriptor>() { new FilterDescriptor(consumesFilter, FilterScope.Action) }
            };
            var actionContext = new ActionContext(httpContext, new RouteData(), actionWithConstraint);
            var resourceExecutingContext = new ResourceExecutingContext(actionContext, new[] { consumesFilter });

            // Act
            consumesFilter.OnResourceExecuting(resourceExecutingContext);

            // Assert
            Assert.Null(resourceExecutingContext.Result);
        }
        public void OnResourceExecuting_ForNoContentTypeMatch_SetsUnsupportedMediaTypeResult(string contentType)
        {
            // Arrange
            var httpContext = new DefaultHttpContext();
            httpContext.Request.ContentType = contentType;
            var consumesFilter = new ConsumesAttribute("application/json");
            var actionWithConstraint = new ActionDescriptor()
            {
                ActionConstraints = new List<IActionConstraintMetadata>() { consumesFilter },
                FilterDescriptors =
                    new List<FilterDescriptor>() { new FilterDescriptor(consumesFilter, FilterScope.Action) }
            };
            var actionContext = new ActionContext(httpContext, new RouteData(), actionWithConstraint);

            var resourceExecutingContext = new ResourceExecutingContext(
                actionContext,
                new[] { consumesFilter },
                new List<IValueProviderFactory>());

            // Act
            consumesFilter.OnResourceExecuting(resourceExecutingContext);

            // Assert
            Assert.NotNull(resourceExecutingContext.Result);
            Assert.IsType<UnsupportedMediaTypeResult>(resourceExecutingContext.Result);
        }