Ejemplo n.º 1
0
        public void FormatterMappings_GetMediaTypeMappingForFormat_ThrowsForInvalidFormats(string format)
        {
            // Arrange
            var options = new FormatterMappings();

            // Act & Assert
            Assert.Throws <ArgumentException>("format", () => options.GetMediaTypeMappingForFormat(format));
        }
Ejemplo n.º 2
0
        public void FormatterMappings_SetFormatMapping_DiffSetGetFormat(string setFormat, string contentType, string getFormat)
        {
            // Arrange
            var options = new FormatterMappings();

            options.SetMediaTypeMappingForFormat(setFormat, MediaTypeHeaderValue.Parse(contentType));

            // Act
            var returnMediaType = options.GetMediaTypeMappingForFormat(getFormat);

            // Assert
            MediaTypeAssert.Equal(contentType, returnMediaType);
        }
Ejemplo n.º 3
0
        public void FormatterMappings_ClearFormatMapping(string format, bool expected)
        {
            // Arrange
            var options   = new FormatterMappings();
            var mediaType = MediaTypeHeaderValue.Parse("application/xml");

            options.SetMediaTypeMappingForFormat("xml", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/json");
            options.SetMediaTypeMappingForFormat("json", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/foo");
            options.SetMediaTypeMappingForFormat("foo", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/bar");
            options.SetMediaTypeMappingForFormat("bar", mediaType);

            // Act
            var cleared = options.ClearMediaTypeMappingForFormat(format);

            // Assert
            Assert.Equal(expected, cleared);
            Assert.Null(options.GetMediaTypeMappingForFormat(format));
        }