Пример #1
0
        public void FormatFilter_IsActive(
            string format,
            FormatSource place,
            bool expected)
        {
            // Arrange
            var mockObjects            = new MockObjects(format, place);
            var resultExecutingContext = mockObjects.CreateResultExecutingContext();
            var filterAttribute        = new FormatFilterAttribute();
            var filter = new FormatFilter(mockObjects.IOptions, mockObjects.ScopedInstance);

            // Act and Assert
            Assert.Equal(expected, filter.IsActive);
        }
Пример #2
0
        // Set up application services
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                var formatFilter = new FormatFilterAttribute();
                options.Filters.Add(formatFilter);

                var customFormatter = new CustomFormatter("application/custom");
                options.OutputFormatters.Add(customFormatter);

                options.FormatterMappings.SetMediaTypeMappingForFormat(
                    "custom",
                    MediaTypeHeaderValue.Parse("application/custom"));
            });
        }
Пример #3
0
        // Set up application services
        public void ConfigureServices(IServiceCollection services)
        {
            var mvcBuilder = services.AddMvc(options =>
            {
                var formatFilter = new FormatFilterAttribute();
                options.Filters.Add(formatFilter);

                var customFormatter = new CustomFormatter("application/custom");
                options.OutputFormatters.Add(customFormatter);
                options.OutputFormatters.RemoveType<StringOutputFormatter>();

                options.FormatterMappings.SetMediaTypeMappingForFormat(
                    "custom",
                    MediaTypeHeaderValue.Parse("application/custom"));
            });

            mvcBuilder.AddXmlDataContractSerializerFormatters();
        }
Пример #4
0
        public void FormatFilter_IsActive(
            string format,
            FormatSource place,
            bool expected)
        {
            // Arrange
            var mockObjects = new MockObjects(format, place);
            var resultExecutingContext = mockObjects.CreateResultExecutingContext();
            var filterAttribute = new FormatFilterAttribute();
            var filter = new FormatFilter(mockObjects.IOptions, mockObjects.ScopedInstance);

            // Act and Assert
            Assert.Equal(expected, filter.IsActive);
        }