public void CallAddNewImage_WhenParamsAreValid() { // Arrange var galleryServiceMock = new Mock <IGalleryImageService>(); var userServiceMock = new Mock <IUserService>(); var mappingServiceMock = new Mock <IMappingService>(); var utilsMock = new Mock <IUtilitiesService>(); var controller = new GalleryController(galleryServiceMock.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; var model = new CreateImageViewModel(); // Act controller.Create(model); // Assert galleryServiceMock.Verify(x => x.AddNewImage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void ReturnViewWhenInvalidModelState() { sut.ModelState.AddModelError("x", "Test Error"); var viewModel = new PhotoCreateViewModel { Title = "Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title Title " }; IActionResult result = sut.Create(viewModel); ViewResult viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <PhotoCreateViewModel>(viewResult.Model); Assert.Equal(viewModel.Title, model.Title); }