123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using Xunit;
- namespace Masuit.Tools.Core.Test.AspNetCore
- {
- public class FileContentsTests : TestBase
- {
- [Fact]
- public async Task FullFileContentsAttachmentEtagTest()
- {
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/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(62, response.Content.Headers.ContentLength);
- Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task FullFileContentsAttachmentNoEtagTest()
- {
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/true/false");
- 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.Null(response.Headers.ETag);
- Assert.Null(response.Content.Headers.ContentRange);
- Assert.Equal(62, response.Content.Headers.ContentLength);
- Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task FullFileContentsInlineEtagTest()
- {
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/false/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(62, response.Content.Headers.ContentLength);
- Assert.Equal("inline", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task FullFileContentsInlineNoEtagTest()
- {
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/false/false");
- 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.Null(response.Headers.ETag);
- Assert.Null(response.Content.Headers.ContentRange);
- Assert.Equal(62, response.Content.Headers.ContentLength);
- Assert.Equal("inline", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task FullFileContentsInlineFileNameTest()
- {
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/false");
- 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.Null(response.Headers.ETag);
- Assert.Null(response.Content.Headers.ContentRange);
- Assert.Equal(62, response.Content.Headers.ContentLength);
- Assert.Equal("inline", response.Content.Headers.ContentDisposition.DispositionType);
- Assert.Equal("TestFile.txt", response.Content.Headers.ContentDisposition.FileName);
- }
- [Fact]
- public async Task Partial1FileContentsAttachmentEtagTest()
- {
- // Arrange
- Client.DefaultRequestHeaders.Add("Range", "bytes=0-0");
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/true/true");
- response.EnsureSuccessStatusCode();
- string responseString = await response.Content.ReadAsStringAsync();
- // Assert
- Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode);
- Assert.Equal("0", responseString);
- Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
- Assert.Equal(EntityTag, response.Headers.ETag);
- Assert.NotNull(response.Content.Headers.ContentRange);
- Assert.Equal("bytes 0-0/62", response.Content.Headers.ContentRange.ToString());
- Assert.Equal(1, response.Content.Headers.ContentLength);
- Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task Partial1FileContentsAttachmentNoEtagTest()
- {
- // Arrange
- Client.DefaultRequestHeaders.Add("Range", "bytes=0-0");
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/true/false");
- response.EnsureSuccessStatusCode();
- string responseString = await response.Content.ReadAsStringAsync();
- // Assert
- Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode);
- Assert.Equal("0", responseString);
- Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
- Assert.Null(response.Headers.ETag);
- Assert.NotNull(response.Content.Headers.ContentRange);
- Assert.Equal("bytes 0-0/62", response.Content.Headers.ContentRange.ToString());
- Assert.Equal(1, response.Content.Headers.ContentLength);
- Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task Partial2FileContentsAttachmentEtagTest()
- {
- // Arrange
- Client.DefaultRequestHeaders.Add("Range", "bytes=1-1");
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/true/true");
- response.EnsureSuccessStatusCode();
- string responseString = await response.Content.ReadAsStringAsync();
- // 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());
- Assert.Equal(1, response.Content.Headers.ContentLength);
- Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task Partial2FileContentsAttachmentNoEtagTest()
- {
- // Arrange
- Client.DefaultRequestHeaders.Add("Range", "bytes=1-1");
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/true/false");
- response.EnsureSuccessStatusCode();
- string responseString = await response.Content.ReadAsStringAsync();
- // Assert
- Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode);
- Assert.Equal("1", responseString);
- Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
- Assert.Null(response.Headers.ETag);
- Assert.NotNull(response.Content.Headers.ContentRange);
- Assert.Equal("bytes 1-1/62", response.Content.Headers.ContentRange.ToString());
- Assert.Equal(1, response.Content.Headers.ContentLength);
- Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task Partial2FileContentsInlineEtagTest()
- {
- // Arrange
- Client.DefaultRequestHeaders.Add("Range", "bytes=1-1");
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/false/true");
- response.EnsureSuccessStatusCode();
- string responseString = await response.Content.ReadAsStringAsync();
- // 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());
- Assert.Equal(1, response.Content.Headers.ContentLength);
- Assert.Equal("inline", response.Content.Headers.ContentDisposition.DispositionType);
- }
- [Fact]
- public async Task Partial2FileContentsInlineNoEtagTest()
- {
- // Arrange
- Client.DefaultRequestHeaders.Add("Range", "bytes=1-1");
- // Act
- HttpResponseMessage response = await Client.GetAsync("/file/content/false/false");
- response.EnsureSuccessStatusCode();
- string responseString = await response.Content.ReadAsStringAsync();
- // Assert
- Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode);
- Assert.Equal("1", responseString);
- Assert.Equal("bytes", response.Headers.AcceptRanges.ToString());
- Assert.Null(response.Headers.ETag);
- Assert.NotNull(response.Content.Headers.ContentRange);
- Assert.Equal("bytes 1-1/62", response.Content.Headers.ContentRange.ToString());
- Assert.Equal(1, response.Content.Headers.ContentLength);
- Assert.Equal("inline", response.Content.Headers.ContentDisposition.DispositionType);
- }
- }
- }
|