public async Task PostAsyncOkTest() { //Arrange var saveUserResource = UserGenerator.GetTestSaveUserResource(); var user = UserGenerator.GetTestUser(); user.Email = saveUserResource.Email; user.FirstName = saveUserResource.FirstName; user.LastName = saveUserResource.LastName; var userResponse = new UserResponse(user); var service = new Mock <IUserService>(); service.Setup(e => e.SaveAsync(It.IsAny <User>())).ReturnsAsync(userResponse); var controller = new UsersController(service.Object, _mapper); //Act var result = await controller.PostAsync(saveUserResource); //Assert var actionResult = Assert.IsType <OkObjectResult>(result); var userResource = Assert.IsAssignableFrom <UserResource>(actionResult.Value); UserAssertHelper.AssertEquals(saveUserResource, userResource); }
public async Task PostAsyncBadRequestTest() { // Arrange var controller = new UsersController(Mock.Of <IUserService>(), _mapper); controller.ModelState.AddModelError("error", "some error"); // Act var result = await controller.PostAsync(UserGenerator.GetTestSaveUserResource()); // Assert Assert.IsType <BadRequestObjectResult>(result); }