public void ErrorControllerHelper_HandleUnknownAction_WithNoViews_SearchesForViewTwiceThenDisplaysError()
        {
            var viewEngineMock = new Mock<IViewEngine>();
            viewEngineMock
                .Setup(m => m.FindView(It.IsAny<ControllerContext>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                .Returns(new ViewEngineResult(Enumerable.Empty<string>()));
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(viewEngineMock.Object);

            using (var httpOut = new FakeHttpOutput())
            {
                var httpContext = new FakeHttpContext(new FakeHttpRequest(), new FakeHttpResponse(httpOut));
                var controllerContext = CreateControllerContext(httpContext);

                ErrorControllerHelper.HandleUnknownAction(controllerContext, "action");

                viewEngineMock
                    .Verify(m => m.FindView(It.IsAny<ControllerContext>(), It.IsAny<string>(), It.IsAny<string>(), true), Times.Exactly(2));
                viewEngineMock
                    .Verify(m => m.FindView(It.IsAny<ControllerContext>(), It.IsAny<string>(), It.IsAny<string>(), false), Times.Exactly(2));

                Assert.That(httpContext.Response.ContentType, Is.EqualTo("text/html"));
                Assert.That(httpOut.GetContentString(), Does.StartWith("<!DOCTYPE html>"));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FakeHttpResponse"/> class.
        /// </summary>
        /// <param name="httpOutput">The HTTP output object.</param>
        public FakeHttpResponse(FakeHttpOutput httpOutput = null)
        {
            this.cacheDependencies = new List<CacheDependency>();
            this.cacheItemDependencies = new List<string>();
            this.cookies = new HttpCookieCollection();
            this.fileDependencies = new List<string>();
            this.headers = new NameValueCollection();
            this.log = new StringBuilder();

            this.appPathModifier = p => p;
            this.cache = new FakeHttpCachePolicy();
            this.isClientConnected = true;

            this.StatusCode = 200;

            if (httpOutput != null)
            {
                this.httpOutput = httpOutput;
                this.Output = httpOutput.OutputWriter;
            }
            else
            {
                this.Output = TextWriter.Null;
            }
        }