Beispiel #1
0
        public void ExecuteResult_Should_Write_Rss()
        {
            var controllerContext = new ControllerContext(_httpContext.Object, new RouteData(), new Mock <ControllerBase>().Object);

            _httpContext.HttpResponse.ExpectSet(r => r.ContentType).Verifiable();
            _httpContext.HttpResponse.Expect(r => r.Write(It.IsAny <string>())).Verifiable();

            FeedResult result = new FeedResult(feedViewData, "rss");

            result.ExecuteResult(controllerContext);

            _httpContext.Verify();
        }
Beispiel #2
0
        public void ProcessRequest_Should_Write_Xml()
        {
            string xml;

            cache.Expect(c => c.TryGet(It.IsAny <string>(), out xml)).Returns(false);

            var handler = new OpenSearchHandler
            {
                Settings            = settings.Object,
                CacheDurationInDays = 365,
                Compress            = true,
                GenerateETag        = true
            };

            _httpContext.HttpResponse.Expect(r => r.Write(It.IsAny <string>())).Verifiable();

            handler.ProcessRequest(_httpContext.Object);

            _httpContext.Verify();
        }
Beispiel #3
0
        public void OnResultExecuted_Should_Not_Compress_Response_When_Exception_Occurred_And_Exception_Is_Not_Handled()
        {
            HttpContextMock       httpContext       = MvcTestHelper.GetHttpContext();
            ControllerContext     controllerContext = new ControllerContext(httpContext.Object, new RouteData(), new Mock <ControllerBase>().Object);
            ResultExecutedContext executedContext   = new ResultExecutedContext(controllerContext, new EmptyResult(), false, new Exception());

            //httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny<string>(), It.IsAny<string>())).Never();
            httpContext.HttpResponse.Verify(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>()), Times.Never());//.Never();
            _attribute.OnResultExecuted(executedContext);

            httpContext.Verify();
        }
Beispiel #4
0
        public void OnResultExecuted_Should_Compress_Response_When_Exception_Occurred_But_Exception_Is_Handled()
        {
            HttpContextMock       httpContext       = MvcTestHelper.GetHttpContext();
            ControllerContext     controllerContext = new ControllerContext(httpContext.Object, new RouteData(), new Mock <ControllerBase>().Object);
            ResultExecutedContext executedContext   = new ResultExecutedContext(controllerContext, new EmptyResult(), false, new Exception())
            {
                ExceptionHandled = true
            };

            httpContext.HttpRequest.Object.Headers.Add("Accept-Encoding", "gzip");
            httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            httpContext.HttpResponse.SetupGet(r => r.Filter).Returns(new MemoryStream());
            httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            httpContext.HttpResponse.SetupSet(r => r.Filter = It.IsAny <Stream>());

            _attribute.OnResultExecuted(executedContext);

            httpContext.Verify();
        }
Beispiel #5
0
        public void OnResultExecuted_Should_Compress_Response(string encoding)
        {
            HttpContextMock       httpContext       = MvcTestHelper.GetHttpContext();
            ControllerContext     controllerContext = new ControllerContext(httpContext.Object, new RouteData(), new Mock <ControllerBase>().Object);
            ResultExecutedContext executedContext   = new ResultExecutedContext(controllerContext, new EmptyResult(), false, null);

            httpContext.HttpRequest.Object.Headers.Add("Accept-Encoding", encoding);

            if (!string.IsNullOrEmpty(encoding))
            {
                httpContext.HttpResponse.SetupGet(r => r.Filter).Returns(new MemoryStream());
                httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
                httpContext.HttpResponse.SetupSet(r => r.Filter = It.IsAny <Stream>());
            }

            _attribute.OnResultExecuted(executedContext);

            if (!string.IsNullOrEmpty(encoding))
            {
                httpContext.Verify();
            }
        }
Beispiel #6
0
 public override void Dispose()
 {
     _httpContext.Verify();
 }