public void Should_Forward_FindView_To_Current_ModuleApplication_ViewEngineCollection() { // Arrange var mockEngines = new Mock <ViewEngineCollection>(); var result = new ViewEngineResult(new[] { "foo", "bar", "baz" }); var controller = new Mock <DnnController>(); controller.SetupAllProperties(); var context = MockHelper.CreateMockControllerContext(controller.Object); // ReSharper disable ConvertToConstant.Local var viewName = "Foo"; var masterName = "Bar"; // ReSharper restore ConvertToConstant.Local mockEngines.Setup(e => e.FindView(context, viewName, masterName)) .Returns(result); SetupMockModuleApplication(context, mockEngines.Object); var viewEngine = new ModuleDelegatingViewEngine(); // Act var engineResult = viewEngine.FindView(context, viewName, masterName, true); // Assert mockEngines.Verify(e => e.FindView(context, viewName, masterName)); Assert.AreEqual("foo", engineResult.SearchedLocations.ElementAt(0)); Assert.AreEqual("bar", engineResult.SearchedLocations.ElementAt(1)); Assert.AreEqual("baz", engineResult.SearchedLocations.ElementAt(2)); }
public void Should_Track_ViewEngine_View_Pairs_On_FindView_And_Releases_View_Appropriately() { // Arrange var mockEngines = new Mock <ViewEngineCollection>(); var mockEngine = new Mock <IViewEngine>(); var mockView = new Mock <IView>(); var result = new ViewEngineResult(mockView.Object, mockEngine.Object); var controller = new Mock <DnnController>(); controller.SetupAllProperties(); var context = MockHelper.CreateMockControllerContext(controller.Object); // ReSharper disable ConvertToConstant.Local string viewName = "Foo"; string masterName = "Bar"; // ReSharper restore ConvertToConstant.Local mockEngines.Setup(e => e.FindView(context, viewName, masterName)) .Returns(result); SetupMockModuleApplication(context, mockEngines.Object); var viewEngine = new ModuleDelegatingViewEngine(); // Act ViewEngineResult engineResult = viewEngine.FindView(context, viewName, masterName, true); viewEngine.ReleaseView(context, engineResult.View); // Assert mockEngine.Verify(e => e.ReleaseView(context, mockView.Object)); }
public void Should_Return_Failed_ViewEngineResult_For_FindView_If_No_Current_Module_Application() { // Arrange var mockEngines = new Mock <ViewEngineCollection>(); var viewEngine = new ModuleDelegatingViewEngine(); var controller = new Mock <DnnController>(); controller.SetupAllProperties(); var context = MockHelper.CreateMockControllerContext(controller.Object); // Act var engineResult = viewEngine.FindView(context, "Foo", "Bar", true); // Assert Assert.IsNotNull(engineResult); Assert.IsNull(engineResult.View); Assert.AreEqual(0, engineResult.SearchedLocations.Count()); }