Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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]);
        }
Esempio n. 6
0
        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);
        }