public void CallCreateStoryMethod_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.CreateStory(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); var model = new CreateEditStoryViewModel(); // Act controller.CreateStory(model); // Assert storyServiceMock.Verify(x => x.CreateStory(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public async Task TestCreateStory_BadRequest(RequestStoryDTO requestStoryDTO) { // Arrange DBStatus dbStatus = DBStatus.Failed; storiesService.Setup(x => x.CreateStoryAsync(requestStoryDTO, "akash")).ReturnsAsync(dbStatus); storiesController.ControllerContext = httpContext; //Act var actionResult = await storiesController.CreateStory(requestStoryDTO) as BadRequestObjectResult; //Assert Assert.NotNull(actionResult); Assert.Equal(400, actionResult.StatusCode); BadResponseDTO badResponseDTO = actionResult.Value as BadResponseDTO; Assert.Equal(1, badResponseDTO.Status); }
public void CreateStory_Should_Return_InvalidModel_For_Wrong_File_Type() { var fileMock = new Mock <IFormFile>(); fileMock.Setup(x => x.ContentType).Returns("image/sss"); var story = new Mock <StoryInputModel>(); story.Object.StoryImage = fileMock.Object; story.SetupAllProperties(); var controller = new StoriesController(storyService.Object); var result = controller.CreateStory(story.Object).GetAwaiter().GetResult(); result.Should().BeOfType <ViewResult>().Which.ViewData.Values.Should().Contain(GlobalConstants.WrongFileType); }
public void CreateStory_Should_Return_InvalidModel() { var story = new StoryInputModel { Author = "some", CreatedOn = DateTime.Now, Genre = "someGenre", StoryImage = null, Summary = null, Title = null }; var controller = new StoriesController(storyService.Object); controller.ModelState.AddModelError("Title", "StringLength"); var result = controller.CreateStory(story).GetAwaiter().GetResult(); result.Should().BeOfType <ViewResult>().Which.Model.Should().BeOfType <StoryInputModel>(); }