Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.

Commit 482987b

Browse files
committed
Add tests for If-Unmodified-Since header
1 parent 8487bf0 commit 482987b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/Microsoft.AspNetCore.StaticFiles.Tests/CacheHeaderTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,53 @@ public async Task IfModifiedSinceDateLessThanLastModifiedShouldReturn200(HttpMet
365365
Assert.Equal(HttpStatusCode.OK, res2.StatusCode);
366366
}
367367

368+
[Theory]
369+
[MemberData(nameof(SupportedMethods))]
370+
public async Task InvalidIfUnmodifiedSinceDateFormatGivesNormalGet(HttpMethod method)
371+
{
372+
TestServer server = StaticFilesTestServer.Create(app => app.UseFileServer());
373+
374+
HttpResponseMessage res = await server
375+
.CreateRequest("/SubFolder/extra.xml")
376+
.AddHeader("If-Unmodified-Since", "bad-date")
377+
.SendAsync(method.Method);
378+
379+
Assert.Equal(HttpStatusCode.OK, res.StatusCode);
380+
}
381+
382+
[Theory]
383+
[MemberData(nameof(SupportedMethods))]
384+
public async Task FutureIfUnmodifiedSinceDateFormatGivesNormalGet(HttpMethod method)
385+
{
386+
TestServer server = StaticFilesTestServer.Create(app => app.UseFileServer());
387+
388+
HttpResponseMessage res = await server
389+
.CreateRequest("/SubFolder/extra.xml")
390+
.And(req => req.Headers.IfUnmodifiedSince = DateTimeOffset.Now.AddYears(1))
391+
.SendAsync(method.Method);
392+
393+
Assert.Equal(HttpStatusCode.OK, res.StatusCode);
394+
}
395+
396+
[Theory]
397+
[MemberData(nameof(SupportedMethods))]
398+
public async Task IfUnmodifiedSinceDateLessThanLastModifiedShouldReturn412(HttpMethod method)
399+
{
400+
TestServer server = StaticFilesTestServer.Create(app => app.UseFileServer());
401+
402+
HttpResponseMessage res1 = await server
403+
.CreateRequest("/SubFolder/extra.xml")
404+
.SendAsync(method.Method);
405+
406+
HttpResponseMessage res2 = await server
407+
.CreateRequest("/SubFolder/extra.xml")
408+
.And(req => req.Headers.IfUnmodifiedSince = DateTimeOffset.MinValue)
409+
.SendAsync(method.Method);
410+
411+
Assert.Equal(HttpStatusCode.PreconditionFailed, res2.StatusCode);
412+
}
413+
414+
368415
public static IEnumerable<object> SupportedMethods => new[]
369416
{
370417
new [] { HttpMethod.Get },

0 commit comments

Comments
 (0)