コード例 #1
0
        public void ExecuteResult_WithNullEtag_DoesNotAddEtagToHeader()
        {
            // arrange
            var result = new IdenticonResult(123, 40, "");
            var context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.Response.AppendHeader("ETag", It.IsAny<string>())).Throws(new InvalidOperationException());
            context.Setup(c => c.HttpContext.Response.OutputStream).Returns(new MemoryStream());

            // act, assert
            result.ExecuteResult(context.Object);
        }
コード例 #2
0
        public void ExecuteResult_SetsProperContentType()
        {
            // arrange
            var result = new IdenticonResult(123, 40, "");
            var context = new Mock<ControllerContext>();
            context.SetupSet(c => c.HttpContext.Response.ContentType, "image/png");
            context.Setup(c => c.HttpContext.Response.OutputStream).Returns(new MemoryStream());

            // act
            result.ExecuteResult(context.Object);

            // assert
            context.VerifySet(c => c.HttpContext.Response.ContentType, "image/png");
        }
コード例 #3
0
        public void ExecuteResult_WithEtag_AddsEtagToHeader()
        {
            // arrange
            var result = new IdenticonResult(123, 40, "some-etag-value");
            var context = new Mock<ControllerContext>();
            string etag = null;
            context.Setup(c => c.HttpContext.Response.AppendHeader("ETag", It.IsAny<string>())).Callback<string, string>((key, value) => etag = value);
            context.Setup(c => c.HttpContext.Response.OutputStream).Returns(new MemoryStream());

            // act
            result.ExecuteResult(context.Object);

            // assert
            Assert.AreEqual("some-etag-value", etag);
        }
コード例 #4
0
        public void ExecuteResult_ClearsResponse()
        {
            // arrange
            var result = new IdenticonResult(123, 40, null);
            var context = new Mock<ControllerContext>();
            bool responseCleared = false;
            context.Setup(c => c.HttpContext.Response.Clear()).Callback(() => responseCleared = true);
            context.Setup(c => c.HttpContext.Response.OutputStream).Returns(new MemoryStream());

            // act
            result.ExecuteResult(context.Object);

            // assert
            Assert.IsTrue(responseCleared);
        }