예제 #1
0
        public void OnResultExecuting_ItemsFlagSet_ReplacesOutputWriter()
        {
            // Arrange
            TextWriter originalWriter = TextWriter.Null;
            TextWriter newWriter      = null;

            Mock <ResultExecutingContext> mockFilterContext = new Mock <ResultExecutingContext>();

            mockFilterContext.Expect(o => o.HttpContext.Items[It.IsAny <object>()]).Returns("theCacheKey");
            mockFilterContext.Expect(o => o.HttpContext.Response.Output).Returns(originalWriter);
            mockFilterContext
            .ExpectSet(o => o.HttpContext.Response.Output)
            .Callback(w => { newWriter = w; });

            // Act
            ChildActionCacheAttribute attr = new ChildActionCacheAttribute()
            {
                Duration = 10
            };

            // Act
            attr.OnResultExecuting(mockFilterContext.Object);

            // Assert
            ChildActionCacheAttribute.WrappedStringWriter stringWriter = newWriter as ChildActionCacheAttribute.WrappedStringWriter;
            Assert.IsNotNull(stringWriter);
            Assert.AreEqual(originalWriter, stringWriter.OriginalWriter);
        }
예제 #2
0
        public void OnResultExecuting_ItemsFlagNotSet_DoesNothing()
        {
            // Arrange
            Mock <ResultExecutingContext> mockFilterContext = new Mock <ResultExecutingContext>();

            mockFilterContext.Expect(o => o.HttpContext.Items).Returns(new Hashtable()).Verifiable(); // empty hashtable has no keys set
            mockFilterContext.Expect(o => o.HttpContext.Response.Output).Never();

            // Act
            ChildActionCacheAttribute attr = new ChildActionCacheAttribute()
            {
                Duration = 10
            };

            // Act
            attr.OnResultExecuting(mockFilterContext.Object);

            // Assert
            mockFilterContext.Verify();
        }
        public void OnResultExecuting_ItemsFlagSet_ReplacesOutputWriter() {
            // Arrange
            TextWriter originalWriter = TextWriter.Null;
            TextWriter newWriter = null;

            Mock<ResultExecutingContext> mockFilterContext = new Mock<ResultExecutingContext>();
            mockFilterContext.Expect(o => o.HttpContext.Items[It.IsAny<object>()]).Returns("theCacheKey");
            mockFilterContext.Expect(o => o.HttpContext.Response.Output).Returns(originalWriter);
            mockFilterContext
                .ExpectSet(o => o.HttpContext.Response.Output)
                .Callback(w => { newWriter = w; });

            // Act
            ChildActionCacheAttribute attr = new ChildActionCacheAttribute() {
                Duration = 10
            };

            // Act
            attr.OnResultExecuting(mockFilterContext.Object);

            // Assert
            ChildActionCacheAttribute.WrappedStringWriter stringWriter = newWriter as ChildActionCacheAttribute.WrappedStringWriter;
            Assert.IsNotNull(stringWriter);
            Assert.AreEqual(originalWriter, stringWriter.OriginalWriter);
        }
        public void OnResultExecuting_ItemsFlagNotSet_DoesNothing() {
            // Arrange
            Mock<ResultExecutingContext> mockFilterContext = new Mock<ResultExecutingContext>();
            mockFilterContext.Expect(o => o.HttpContext.Items).Returns(new Hashtable()).Verifiable(); // empty hashtable has no keys set
            mockFilterContext.Expect(o => o.HttpContext.Response.Output).Never();

            // Act
            ChildActionCacheAttribute attr = new ChildActionCacheAttribute() {
                Duration = 10
            };

            // Act
            attr.OnResultExecuting(mockFilterContext.Object);

            // Assert
            mockFilterContext.Verify();
        }