public async Task PreconditionIfRangeLastModifiedIgnoreTest()
        {
            // Arrange
            Client.DefaultRequestHeaders.Add("Range", "bytes=1-1");
            Client.DefaultRequestHeaders.Add("If-Range", HeaderUtilities.FormatDate(LastModified.AddSeconds(-1)));

            // Act
            HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true");

            response.EnsureSuccessStatusCode();

            string responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("0123456789abcdefghijklmnopgrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWXYZ", responseString);
            Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
            Assert.Equal(EntityTag, response.Headers.ETag);
            Assert.Null(response.Content.Headers.ContentRange);
        }
        public async Task PreconditionIfRangeLastModifiedLessTest()
        {
            // Arrange
            Client.DefaultRequestHeaders.Add("Range", "bytes=1-1");
            Client.DefaultRequestHeaders.Add("If-Range", HeaderUtilities.FormatDate(LastModified.AddSeconds(1)));

            // Act
            HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true");

            response.EnsureSuccessStatusCode();

            string responseString = await response.Content.ReadAsStringAsync();

            // Assert
            // Assert
            Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode);
            Assert.Equal("1", responseString);
            Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
            Assert.Equal(EntityTag, response.Headers.ETag);
            Assert.NotNull(response.Content.Headers.ContentRange);
            Assert.Equal("bytes 1-1/62", response.Content.Headers.ContentRange.ToString());
        }
示例#3
0
        public async Task PreconditionIfUnmodifiedSinceIfMatchFailTest()
        {
            // Arrange
            Client.DefaultRequestHeaders.Add("If-Match", EntityTag.ToString());
            Client.DefaultRequestHeaders.Add("If-Unmodified-Since", HeaderUtilities.FormatDate(LastModified.AddSeconds(-1)));

            // Act
            HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true");

            string responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
            Assert.Equal(string.Empty, responseString);
            Assert.NotEqual("bytes", response.Headers.AcceptRanges.ToString());
            Assert.Equal(EntityTag, response.Headers.ETag);
            Assert.Null(response.Content.Headers.ContentRange);
            Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
        }
示例#4
0
        public async Task PreconditionIfModifiedSinceSuccessPutTest()
        {
            // Arrange
            Client.DefaultRequestHeaders.Add("If-Modified-Since", HeaderUtilities.FormatDate(LastModified.AddSeconds(-1)));

            // Act
            HttpResponseMessage response = await Client.PutAsync("/file/file", new StringContent(string.Empty));

            response.EnsureSuccessStatusCode();

            string responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("0123456789abcdefghijklmnopgrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWXYZ", responseString);
            Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
            Assert.Equal(EntityTag, response.Headers.ETag);
            Assert.Null(response.Content.Headers.ContentRange);
            Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
        }
示例#5
0
        public async Task PreconditionIfModifiedSinceIfNoneMatchSuccessTest()
        {
            // Arrange
            var tmpNewEntityTag = new EntityTagHeaderValue("\"xyzzy\"", true);

            Client.DefaultRequestHeaders.Add("If-None-Match", tmpNewEntityTag.ToString());
            Client.DefaultRequestHeaders.Add("If-Modified-Since", HeaderUtilities.FormatDate(LastModified.AddSeconds(1)));

            // Act
            HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true");

            response.EnsureSuccessStatusCode();

            string responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("0123456789abcdefghijklmnopgrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWXYZ", responseString);
            Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
            Assert.Equal(EntityTag, response.Headers.ETag);
            Assert.Null(response.Content.Headers.ContentRange);
            Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
        }