コード例 #1
0
        public async Task CreateComment_ShouldReturnNull()
        {
            var service = new Mock <IStoryService>();

            service.Setup(s => s.CreateCommentAsync("id", "text", user))
            .Throws(new Exception());

            StoriesController controller = new StoriesController(
                service.Object, userManager.Object, logger)
            {
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };

            var result = await controller.CreateComment("id", "text");

            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");
        }
コード例 #2
0
        public async Task CreateComment_ShouldReturnView()
        {
            var service = new Mock <IStoryService>();

            service.Setup(s => s.CreateCommentAsync("testId", "text", user))
            .ReturnsAsync(() => true);

            service.Setup(s => s.GetStoryByIdAsViewModel("testId"))
            .Returns(() => new StoryViewModel());

            StoriesController controller = new StoriesController(
                service.Object, userManager.Object, logger)
            {
                TempData = new TempDataDictionary(httpContext.Object, tempDataProvider.Object)
            };

            var result = await controller.CreateComment("testId", "text");

            result.ShouldNotBeNull();
            var viewResult = Assert.IsAssignableFrom <PartialViewResult>(result);

            viewResult.ViewName.ShouldBe("_StoryComments");
        }