public void FileDoesNotExist() { fileSystem.Stub(x => x.DoesFileExist(FileName)).Return(false); ICachingPolicy cachingPolicy = new NoCachingPolicy(); FileResult result = new FileResult(FileName, cachingPolicy); result.Apply(context); Assert.AreEqual((int)HttpStatusCode.NotFound, context.StatusCode); }
public void ContentTypeCouldNotBeDetermined() { fileSystem.Stub(x => x.DoesFileExist(FileNameStrangeExtension)).Return(true); byte[] fileBytes = new byte[100]; fileSystem.Stub(x => x.ReadFileAsBytes(FileNameStrangeExtension)).Return(fileBytes); ICachingPolicy cachingPolicy = new NoCachingPolicy(); FileResult result = new FileResult(FileNameStrangeExtension, cachingPolicy); result.Apply(context); Assert.AreEqual((int)HttpStatusCode.OK, context.StatusCode); Assert.IsNull(context.ResponseContentType); }
public void WithCachingPolicyAndCacheVersionIsValid() { const string ETag = "\"1\""; FileResult result = new FileResult( FileNameStrangeExtension, new CachingByETagPolicy(TimeSpan.FromDays(1), () => new Tuple <string, DateTime?>(ETag, timeService.CurrentTime))); result.StatusCode = (int)HttpStatusCode.Accepted; context.RequestHeaders[HttpConsts.HeaderIfNoneMatch] = ETag; result.Apply(context); Assert.AreEqual((int)HttpStatusCode.NotModified, context.StatusCode); }
public void FileResultShouldSetContentLength() { const int DataLength = 100; byte[] data = new byte[DataLength]; fileSystem.Stub(x => x.DoesFileExist(FileName)).Return(true); fileSystem.Stub(x => x.ReadFileAsBytes(FileName)).Return(data); FileResult result = new FileResult(FileName, new NoCachingPolicy()); result.Apply(context); Assert.AreEqual(DataLength, context.ResponseContentLength); }
public void ReturnFile() { fileSystem.Stub(x => x.DoesFileExist(FileName)).Return(true); byte[] fileBytes = new byte[100]; fileSystem.Stub(x => x.ReadFileAsBytes(FileName)).Return(fileBytes); ICachingPolicy cachingPolicy = new NoCachingPolicy(); FileResult result = new FileResult(FileName, cachingPolicy); result.Apply(context); Assert.AreEqual((int)HttpStatusCode.OK, context.StatusCode); Assert.AreEqual(HttpConsts.ContentTypeImagePng, context.ResponseContentType); Assert.AreEqual(null, context.ResponseHeaders[HttpConsts.HeaderTransferEncoding]); }
public void FileShouldBeCompressedIfRequested(string acceptEncodingValue) { context.RequestHeaders.Add(HttpConsts.HeaderAcceptEncoding, acceptEncodingValue); fileSystem.Stub(x => x.DoesFileExist(FileName)).Return(true); byte[] fileBytes = new byte[100]; fileSystem.Stub(x => x.ReadFileAsBytes(FileName)).Return(fileBytes); ICachingPolicy cachingPolicy = new NoCachingPolicy(); FileResult result = new FileResult(FileName, cachingPolicy); result.AllowGzipCompression = true; result.Apply(context); Assert.AreEqual((int)HttpStatusCode.OK, context.StatusCode); Assert.AreEqual("gzip", context.ResponseHeaders[HttpConsts.HeaderContentEncoding]); Assert.AreEqual(HttpConsts.ContentTypeImagePng, context.ResponseContentType); }