コード例 #1
0
ファイル: ContentCommandTests.cs プロジェクト: breki/syborg
        public void SettingCachingRuleShouldWork()
        {
            TimeSpan maxAge = TimeSpan.FromDays(7);

            cmd.CacheByMaxAge(@"somedir\*", maxAge);

            routeMatch.AddParameter("path", @"somedir\somepath.png");
            const string ExpectedFileName = @"d:\somedir\contents\somedir\somepath.png";

            fileSystem.Stub(x => x.DoesFileExist(ExpectedFileName)).Return(true);

            IFileInformation fileInfo = MockRepository.GenerateStub <IFileInformation>();

            fileInfo.LastWriteTime = now.AddDays(-3);
            fileSystem.Stub(x => x.GetFileInformation(ExpectedFileName)).Return(fileInfo);

            fileSystem.Stub(x => x.ReadFileAsBytes(ExpectedFileName)).Return(new byte[100]);

            IWebCommandResult     result       = cmd.Execute(context, routeMatch);
            FileResult            fileResult   = (FileResult)result;
            CachingByMaxAgePolicy maxAgePolicy = (CachingByMaxAgePolicy)fileResult.CachingPolicy;

            Assert.AreEqual(maxAge, maxAgePolicy.MaxAge);

            context.RequestHeaders.Add(HttpConsts.HeaderIfModifiedSince, fileInfo.LastWriteTime.ToRfc2822DateTime());
            result.Apply(context);

            Assert.AreEqual((int)HttpStatusCode.NotModified, context.StatusCode);
        }
コード例 #2
0
ファイル: ContentCommandTests.cs プロジェクト: breki/syborg
        public void TestCachingByETag()
        {
            log.Debug("TestCachingByETag");

            TimeSpan maxAge = TimeSpan.FromDays(30);

            cmd.CacheByETag(
                @"somedir\*",
                maxAge,
                () => new Tuple <string, DateTime?>("xyz", new DateTime(2016, 01, 19, 10, 22, 0)));

            routeMatch.AddParameter("path", @"somedir\somepath.png");
            const string ExpectedFileName = @"d:\somedir\contents\somedir\somepath.png";

            fileSystem.Stub(x => x.DoesFileExist(ExpectedFileName)).Return(true);

            IWebCommandResult   result        = cmd.Execute(context, routeMatch);
            FileResult          fileResult    = (FileResult)result;
            CachingByETagPolicy cachingPolicy = (CachingByETagPolicy)fileResult.CachingPolicy;

            Assert.AreEqual(maxAge, cachingPolicy.MaxAge);

            context.RequestHeaders.Add(HttpConsts.HeaderIfNoneMatch, "xyz");
            result.Apply(context);

            Assert.AreEqual((int)HttpStatusCode.NotModified, context.StatusCode);
        }