Exemplo n.º 1
0
        public async Task DeleteComment_ShouldReturnNull()
        {
            var service = new Mock <IStoryService>();

            service.Setup(s => s.DeleteCommentAsync("id"))
            .Throws(new Exception());

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

            var result = await controller.DeleteComment("id", "rId");

            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");
        }
Exemplo n.º 2
0
        public void CallDeleteCommentMethod_WhenParamsAreValid()
        {
            // Arrange
            var storyServiceMock   = new Mock <IStoryService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new StoriesController(storyServiceMock.Object, mappingServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var controllerContext = new Mock <ControllerContext>();
            var user = new Mock <IPrincipal>();

            user.Setup(p => p.IsInRole("admin")).Returns(true);
            user.SetupGet(x => x.Identity.Name).Returns("username");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(user.Object);
            controller.ControllerContext = controllerContext.Object;

            storyServiceMock.Setup(x => x.DeleteComment(It.IsAny <Guid>()));

            var story = new Story();

            storyServiceMock.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(story);

            var model = new StoryDetailsViewModel();

            mappingServiceMock.Setup(x => x.Map <StoryDetailsViewModel>(story)).Returns(model);

            var userModel = new User();

            userServiceMock.Setup(x => x.GetById(It.IsAny <string>())).Returns(userModel);

            // Act
            controller.DeleteComment(Guid.NewGuid(), Guid.NewGuid());

            // Assert
            storyServiceMock.Verify(x => x.DeleteComment(It.IsAny <Guid>()), Times.Once);
        }
Exemplo n.º 3
0
        public async Task DeleteComment_ShouldReturnView()
        {
            var service = new Mock <IStoryService>();

            service.Setup(s => s.DeleteCommentAsync("id"))
            .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.DeleteComment("id", "testId");

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

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