public void SortMediaTypeHeaderValuesByQFactor_SortsCorrectly(IEnumerable <string> unsorted, IEnumerable <string> expectedSorted)
        {
            var unsortedValues       = MediaTypeHeaderValue.ParseList(unsorted.ToList());
            var expectedSortedValues = MediaTypeHeaderValue.ParseList(expectedSorted.ToList());

            var actualSorted = unsortedValues.OrderByDescending(m => m, MediaTypeHeaderValueComparer.QualityComparer).ToList();

            Assert.Equal(expectedSortedValues, actualSorted);
        }
        public void ParseList_WithSomeInvlaidValues_Throws()
        {
            var inputs = new[]
            {
                "text/html,application/xhtml+xml, ignore-this, ignore/this",
                "application/xml;q=0.9,image/webp,*/*;q=0.8"
            };

            Assert.Throws <FormatException>(() => MediaTypeHeaderValue.ParseList(inputs));
        }
        public void ParseList_NullOrEmptyArray_ReturnsEmptyList()
        {
            var results = MediaTypeHeaderValue.ParseList(null);

            Assert.NotNull(results);
            Assert.Equal(0, results.Count);

            results = MediaTypeHeaderValue.ParseList(new string[0]);
            Assert.NotNull(results);
            Assert.Equal(0, results.Count);

            results = MediaTypeHeaderValue.ParseList(new string[] { "" });
            Assert.NotNull(results);
            Assert.Equal(0, results.Count);
        }
        public void ParseList_SetOfValidValueStrings_ReturnsValues()
        {
            var inputs  = new[] { "text/html,application/xhtml+xml,", "application/xml;q=0.9,image/webp,*/*;q=0.8" };
            var results = MediaTypeHeaderValue.ParseList(inputs);

            var expectedResults = new[]
            {
                new MediaTypeHeaderValue("text/html"),
                new MediaTypeHeaderValue("application/xhtml+xml"),
                new MediaTypeHeaderValue("application/xml", 0.9),
                new MediaTypeHeaderValue("image/webp"),
                new MediaTypeHeaderValue("*/*", 0.8),
            }.ToList();

            Assert.Equal(expectedResults, results);
        }
        public void ParseList_WithSomeInvlaidValues_IgnoresInvalidValues()
        {
            var inputs = new[]
            {
                "text/html,application/xhtml+xml, ignore-this, ignore/this",
                "application/xml;q=0.9,image/webp,*/*;q=0.8"
            };
            var results = MediaTypeHeaderValue.ParseList(inputs);

            var expectedResults = new[]
            {
                new MediaTypeHeaderValue("text/html"),
                new MediaTypeHeaderValue("application/xhtml+xml"),
                new MediaTypeHeaderValue("ignore/this"),
                new MediaTypeHeaderValue("application/xml", 0.9),
                new MediaTypeHeaderValue("image/webp"),
                new MediaTypeHeaderValue("*/*", 0.8),
            }.ToList();

            Assert.Equal(expectedResults, results);
        }