private void CheckValidTryParse(string input, ContentRangeHeaderValue expectedResult)
        {
            ContentRangeHeaderValue result = null;

            Assert.True(ContentRangeHeaderValue.TryParse(input, out result));
            Assert.Equal(expectedResult, result);
        }
Example #2
0
        public void TryParse_SetOfValidValueStrings_ParsedCorrectly()
        {
            CheckValidTryParse(" bytes 1-2/3 ", new ContentRangeHeaderValue(1, 2, 3));
            CheckValidTryParse("bytes  *  /  3", new ContentRangeHeaderValue(3));

            CheckValidTryParse(" custom 1234567890123456789-1234567890123456799/*",
                               new ContentRangeHeaderValue(1234567890123456789, 1234567890123456799)
            {
                Unit = "custom"
            });

            CheckValidTryParse(" custom * / 123 ",
                               new ContentRangeHeaderValue(123)
            {
                Unit = "custom"
            });

            // Note that we don't have a public constructor for value 'bytes */*' since the RFC doesn't mention a
            // scenario for it. However, if a server returns this value, we're flexible and accept it.
            Assert.True(ContentRangeHeaderValue.TryParse("bytes */*", out var result));
            Assert.Equal("bytes", result.Unit);
            Assert.Null(result.From);
            Assert.Null(result.To);
            Assert.Null(result.Length);
            Assert.False(result.HasRange, "HasRange");
            Assert.False(result.HasLength, "HasLength");
        }
        public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input)
        {
            ContentRangeHeaderValue result = null;

            Assert.False(ContentRangeHeaderValue.TryParse(input, out result));
            Assert.Null(result);
        }