public void Index_ContextItemIsNull_EmptyResultReturned() { // Given var expectedViewModel = new HelloWorld(); testHarness = new HelloWorldControllerTestHarness(); testHarness.RequestContext.GetContextItem <IHelloWorld>().Returns(expectedViewModel); // When var result = testHarness.HelloWorldController.Index(); // Then Assert.IsNotNull(result); Assert.IsTrue(result is EmptyResult, "result is not EmptyResult"); }
public void Index_ContextItemIsNotNull_ModelTopHeaderContentEqualsCurrentPage() { // Given var currentPageItemId = Guid.NewGuid(); var expectedViewModel = Substitute.For <IHelloWorld>(); var currentPageModel = Substitute.For <IBasePage>(); expectedViewModel.Id.Returns(currentPageItemId); expectedViewModel.CurrentPage.Returns(currentPageModel); testHarness = new HelloWorldControllerTestHarness(); testHarness.RequestContext.GetContextItem <IHelloWorld>().Returns(expectedViewModel); // When var result = testHarness.HelloWorldController.Index(); // Then Assert.IsNotNull(result); Assert.IsTrue(result is ViewResult, "result is not ViewResult"); var viewResult = result as ViewResult; var model = viewResult.Model as IHelloWorld; Assert.IsNotNull(model, "model in ViewResult is null"); Assert.IsNotNull(model.CurrentPage, "model.CurrentPage in ViewResult is null"); }