public void RefreshStats_ShouldReturnView() { var service = new Mock <IStoryService>(); service.Setup(s => s.GetStoryByIdAsViewModel("id")) .Returns(() => new StoryViewModel()); StoriesController controller = new StoriesController( service.Object, userManager.Object, logger) { TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object) }; var result = controller.RefreshStats("id"); result.ShouldNotBeNull(); var viewResult = Assert.IsAssignableFrom <ViewComponentResult>(result); viewResult.ViewComponentName.ShouldBe("StoryOptions"); }
public void RefreshStats_ShouldReturnNull() { var service = new Mock <IStoryService>(); service.Setup(s => s.GetStoryByIdAsViewModel("id")) .Throws(new Exception()); StoriesController controller = new StoriesController(service.Object, userManager.Object, logger) { TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object) }; var result = controller.RefreshStats("id"); result.ShouldBeNull(); controller.TempData.ContainsKey("notification").ShouldBeTrue(); controller.TempData["notification"].ShouldNotBeNull(); controller.TempData["notification"].ShouldBeOfType <string[]>(); string[] arr = controller.TempData["notification"] as string[]; arr[0].ShouldBe("danger"); }