string DownloadJavaScript(WebHost host, string url) { using (var http = new HttpTestHarness(host)) { httpContext = http.Context.Object; http.Get(url); http.Response.VerifySet(r => r.ContentType = "text/javascript"); return http.ResponseOutputStream.ReadToEnd(); } }
public void WhenRequestFileWithDotExtension_ThenRequestIsResolvedSuccessfully() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "test.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c, bundles)); http.Server.Setup(s => s.MapPath("~/test.png")).Returns(filename); http.Get("~/test_hash.png"); http.Response.Verify(r => r.WriteFile(filename)); } }
public void WhenRequestFileWithDotExtension_ThenRequestIsResolvedSuccessfully() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "test.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c)); http.Server.Setup(s => s.MapPath("~/test.png")).Returns(filename); http.Get("~/test_hash.png"); http.Response.Verify(r => r.WriteFile(filename)); } }
public void WhenRequestFileThatIsNoReferencedByAsset_ThenDoNotReturnFile() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "protected.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c, bundles)); http.Server.Setup(s => s.MapPath("~/protected.png")).Returns(filename); http.Get("~/protected_hash.png"); http.Response.Verify(r => r.WriteFile(It.IsAny <string>()), Times.Never()); http.Response.VerifySet(r => r.StatusCode = 404); } }
public void WhenRequestFileThatIsNoReferencedByAsset_ThenDoNotReturnFile() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "protected.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c, bundles, null)); http.Server.Setup(s => s.MapPath("~/protected.png")).Returns(filename); http.Get("~/protected_hash.png"); http.Response.Verify(r => r.WriteFile(It.IsAny<string>()), Times.Never()); http.Response.VerifySet(r => r.StatusCode = 404); } }
public void WhenRequestFile_ThenResponseETagHeaderIsSHA1OfContents() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "test.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c)); http.Server.Setup(s => s.MapPath("~/test.png")).Returns(filename); http.Get("~/test_hash.png"); string expectedETag; using (var hasher = SHA1.Create()) { expectedETag = "\"" + Convert.ToBase64String(hasher.ComputeHash(content)) + "\""; } http.ResponseCache.Verify(c => c.SetETag(expectedETag)); } }
public void WhenRequestWithETagThatMatchesCurrent_ThenNotModifiedResponseReturned() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "test.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c, bundles)); http.Server.Setup(s => s.MapPath("~/test.png")).Returns(filename); string eTag; using (var hasher = SHA1.Create()) { eTag = "\"" + Convert.ToBase64String(hasher.ComputeHash(content)) + "\""; } http.RequestHeaders["If-None-Match"] = eTag; http.Get("~/test_hash.png"); http.Response.VerifySet(r => r.StatusCode = 304); } }
public void WhenRequestFile_ThenResponseETagHeaderIsSHA1OfContents() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "test.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c, bundles)); http.Server.Setup(s => s.MapPath("~/test.png")).Returns(filename); http.Get("~/test_hash.png"); string expectedETag; using (var hasher = SHA1.Create()) { expectedETag = "\"" + Convert.ToBase64String(hasher.ComputeHash(content)) + "\""; } http.ResponseCache.Verify(c => c.SetETag(expectedETag)); } }
public void WhenRequestWithETagThatMatchesCurrent_ThenNotModifiedResponseReturned() { using (var temp = new TempDirectory()) using (var http = new HttpTestHarness()) { var filename = Path.Combine(temp, "test.png"); var content = new byte[] { 1, 2, 3 }; File.WriteAllBytes(filename, content); http.MapRoute("{*path}", c => new RawFileRequestHandler(c)); http.Server.Setup(s => s.MapPath("~/test.png")).Returns(filename); string eTag; using (var hasher = SHA1.Create()) { eTag = "\"" + Convert.ToBase64String(hasher.ComputeHash(content)) + "\""; } http.RequestHeaders["If-None-Match"] = eTag; http.Get("~/test_hash.png"); http.Response.VerifySet(r => r.StatusCode = 304); } }
string Download(WebHost host, string url) { using (var http = new HttpTestHarness(host)) { httpContext = http.Context.Object; http.Get(url); return http.ResponseOutputStream.ReadToEnd(); } }