Exemple #1
0
        public void GetView_ReturnsNotFound_IfAllViewEnginesReturnNotFound(bool isMainPage)
        {
            // Arrange
            var viewName         = "foo.cshtml";
            var expectedViewName = "~/" + viewName;
            var engine1          = new Mock <IViewEngine>(MockBehavior.Strict);
            var engine2          = new Mock <IViewEngine>(MockBehavior.Strict);
            var engine3          = new Mock <IViewEngine>(MockBehavior.Strict);

            engine1
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "1", "2" }));
            engine2
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "3" }));
            engine3
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "4", "5" }));

            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations);
        }
        public void FindPartialView_ReturnsNotFound_IfAllViewEnginesReturnNotFound()
        {
            // Arrange
            var viewName = "foo";
            var engine1  = new Mock <IViewEngine>();
            var engine2  = new Mock <IViewEngine>();
            var engine3  = new Mock <IViewEngine>();

            engine1.Setup(e => e.FindPartialView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" }));
            engine2.Setup(e => e.FindPartialView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound(viewName, new[] { "3" }));
            engine3.Setup(e => e.FindPartialView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));

            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindPartialView(GetActionContext(), viewName);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations);
        }
        public void FindView_ReturnsViewFromFirstViewEngineWithFoundResult()
        {
            // Arrange
            var viewName = "foo";
            var engine1  = new Mock <IViewEngine>();
            var engine2  = new Mock <IViewEngine>();
            var engine3  = new Mock <IViewEngine>();
            var view2    = Mock.Of <IView>();
            var view3    = Mock.Of <IView>();

            engine1.Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty <string>()));
            engine2.Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.Found(viewName, view2));
            engine3.Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.Found(viewName, view3));

            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(GetActionContext(), viewName);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view2, result.View);
            Assert.Equal(viewName, result.ViewName);
        }
Exemple #4
0
        public void GetView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered(bool isMainPage)
        {
            // Arrange
            var viewName            = "test-view.cshtml";
            var optionsAccessor     = new TestOptionsManager <MvcViewOptions>();
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.False(result.Success);
            Assert.Empty(result.SearchedLocations);
        }
        public void FindPartialView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered()
        {
            // Arrange
            var viewName            = "my-partial-view";
            var optionsAccessor     = new TestOptionsManager <MvcViewOptions>();
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindPartialView(GetActionContext(), viewName);

            // Assert
            Assert.False(result.Success);
            Assert.Empty(result.SearchedLocations);
        }
        public void FindView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered()
        {
            // Arrange
            var viewName = "test-view";
            var actionContext = GetActionContext();
            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(actionContext, viewName);

            // Assert
            Assert.False(result.Success);
            Assert.Empty(result.SearchedLocations);
        }
Exemple #7
0
        public void FindView_IsMainPage_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered()
        {
            // Arrange
            var viewName            = "test-view";
            var actionContext       = GetActionContext();
            var optionsAccessor     = new TestOptionsManager <MvcViewOptions>();
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(actionContext, viewName, isMainPage: true);

            // Assert
            Assert.False(result.Success);
            Assert.Empty(result.SearchedLocations);
        }
        public void ViewEngines_UsesListOfViewEnginesFromOptions()
        {
            // Arrange
            var viewEngine1 = Mock.Of<IViewEngine>();
            var viewEngine2 = Mock.Of<IViewEngine>();
            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(viewEngine1);
            optionsAccessor.Value.ViewEngines.Add(viewEngine2);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.ViewEngines;

            // Assert
            Assert.Equal(new[] { viewEngine1, viewEngine2 }, result);
        }
        public void ViewEngines_UsesListOfViewEnginesFromOptions()
        {
            // Arrange
            var viewEngine1     = Mock.Of <IViewEngine>();
            var viewEngine2     = Mock.Of <IViewEngine>();
            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(viewEngine1);
            optionsAccessor.Value.ViewEngines.Add(viewEngine2);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.ViewEngines;

            // Assert
            Assert.Equal(new[] { viewEngine1, viewEngine2 }, result);
        }
        public void FindView_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult()
        {
            // Arrange
            var viewName = "test-view";
            var engine = new Mock<IViewEngine>();
            engine.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.NotFound(viewName, new[] { "controller/test-view" }));
            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(GetActionContext(), viewName);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(new[] { "controller/test-view" }, result.SearchedLocations);
        }
        public void FindView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult()
        {
            // Arrange
            var viewName = "test-view";
            var engine = new Mock<IViewEngine>();
            var view = Mock.Of<IView>();
            engine.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.Found(viewName, view));
            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(GetActionContext(), viewName);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view, result.View);
        }
Exemple #12
0
        public void FindView_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult()
        {
            // Arrange
            var viewName = "test-view";
            var engine   = new Mock <IViewEngine>();

            engine.Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.NotFound(viewName, new[] { "controller/test-view" }));
            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(GetActionContext(), viewName);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(new[] { "controller/test-view" }, result.SearchedLocations);
        }
Exemple #13
0
        public void FindView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult()
        {
            // Arrange
            var viewName = "test-view";
            var engine   = new Mock <IViewEngine>();
            var view     = Mock.Of <IView>();

            engine.Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>()))
            .Returns(ViewEngineResult.Found(viewName, view));
            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(GetActionContext(), viewName);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view, result.View);
        }
Exemple #14
0
        public void GetView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult(bool isMainPage)
        {
            // Arrange
            var viewName         = "test-view.cshtml";
            var expectedViewName = "~/" + viewName;
            var engine           = new Mock <IViewEngine>(MockBehavior.Strict);
            var view             = Mock.Of <IView>();

            engine
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.Found(expectedViewName, view));
            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view, result.View);
        }
Exemple #15
0
        public void GetView_ReturnsViewFromFirstViewEngineWithFoundResult(bool isMainPage)
        {
            // Arrange
            var viewName         = "foo.cshtml";
            var expectedViewName = "~/" + viewName;
            var engine1          = new Mock <IViewEngine>(MockBehavior.Strict);
            var engine2          = new Mock <IViewEngine>(MockBehavior.Strict);
            var engine3          = new Mock <IViewEngine>(MockBehavior.Strict);
            var view2            = Mock.Of <IView>();
            var view3            = Mock.Of <IView>();

            engine1
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.NotFound(expectedViewName, Enumerable.Empty <string>()));
            engine2
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.Found(expectedViewName, view2));
            engine3
            .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
            .Returns(ViewEngineResult.Found(expectedViewName, view3));

            var optionsAccessor = new TestOptionsManager <MvcViewOptions>();

            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view2, result.View);
            Assert.Equal(expectedViewName, result.ViewName);
        }
        public void FindPartialView_ReturnsNotFound_IfAllViewEnginesReturnNotFound()
        {
            // Arrange
            var viewName = "foo";
            var engine1 = new Mock<IViewEngine>();
            var engine2 = new Mock<IViewEngine>();
            var engine3 = new Mock<IViewEngine>();
            engine1.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" }));
            engine2.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.NotFound(viewName, new[] { "3" }));
            engine3.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));

            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindPartialView(GetActionContext(), viewName);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations);
        }
        public void GetView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult(bool isMainPage)
        {
            // Arrange
            var viewName = "test-view.cshtml";
            var expectedViewName = "~/" + viewName;
            var engine = new Mock<IViewEngine>(MockBehavior.Strict);
            var view = Mock.Of<IView>();
            engine
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.Found(expectedViewName, view));
            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view, result.View);
        }
        public void GetView_ReturnsViewFromFirstViewEngineWithFoundResult(bool isMainPage)
        {
            // Arrange
            var viewName = "foo.cshtml";
            var expectedViewName = "~/" + viewName;
            var engine1 = new Mock<IViewEngine>(MockBehavior.Strict);
            var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
            var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
            var view2 = Mock.Of<IView>();
            var view3 = Mock.Of<IView>();
            engine1
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.NotFound(expectedViewName, Enumerable.Empty<string>()));
            engine2
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.Found(expectedViewName, view2));
            engine3
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.Found(expectedViewName, view3));

            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view2, result.View);
            Assert.Equal(expectedViewName, result.ViewName);
        }
        public void FindView_ReturnsViewFromFirstViewEngineWithFoundResult()
        {
            // Arrange
            var viewName = "foo";
            var engine1 = new Mock<IViewEngine>();
            var engine2 = new Mock<IViewEngine>();
            var engine3 = new Mock<IViewEngine>();
            var view2 = Mock.Of<IView>();
            var view3 = Mock.Of<IView>();
            engine1.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty<string>()));
            engine2.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.Found(viewName, view2));
            engine3.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                   .Returns(ViewEngineResult.Found(viewName, view3));

            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.FindView(GetActionContext(), viewName);

            // Assert
            Assert.True(result.Success);
            Assert.Same(view2, result.View);
            Assert.Equal(viewName, result.ViewName);
        }
        public void GetView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered(bool isMainPage)
        {
            // Arrange
            var viewName = "test-view.cshtml";
            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.False(result.Success);
            Assert.Empty(result.SearchedLocations);
        }
        public void GetView_ReturnsNotFound_IfAllViewEnginesReturnNotFound(bool isMainPage)
        {
            // Arrange
            var viewName = "foo.cshtml";
            var expectedViewName = "~/" + viewName;
            var engine1 = new Mock<IViewEngine>(MockBehavior.Strict);
            var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
            var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
            engine1
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "1", "2" }));
            engine2
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "3" }));
            engine3
                .Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
                .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "4", "5" }));

            var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
            optionsAccessor.Value.ViewEngines.Add(engine1.Object);
            optionsAccessor.Value.ViewEngines.Add(engine2.Object);
            optionsAccessor.Value.ViewEngines.Add(engine3.Object);
            var compositeViewEngine = new CompositeViewEngine(optionsAccessor);

            // Act
            var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations);
        }