Beispiel #1
0
        public async Task PutAsyncOkTest()
        {
            //Arrange
            var updateUserResource = UserGenerator.GetTestUpdateUserResource();

            var user = UserGenerator.GetTestUser();

            user.Email     = updateUserResource.Email;
            user.FirstName = updateUserResource.FirstName;
            user.LastName  = updateUserResource.LastName;

            var userResponse = new UserResponse(user);

            var service = new Mock <IUserService>();

            service.Setup(e => e.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(userResponse);
            service.Setup(e => e.UpdateAsync(It.IsAny <int>(), It.IsAny <User>())).ReturnsAsync(userResponse);

            var controller = new UsersController(service.Object, _mapper);

            //Act
            var result = await controller.PutAsync(1, updateUserResource);

            //Assert
            var actionResult = Assert.IsType <OkObjectResult>(result);
            var userResource = Assert.IsAssignableFrom <UserResource>(actionResult.Value);

            UserAssertHelper.AssertEquals(updateUserResource, userResource);
        }
Beispiel #2
0
        public async Task PutAsyncBadRequestTest()
        {
            // Arrange
            var controller = new UsersController(Mock.Of <IUserService>(), _mapper);

            controller.ModelState.AddModelError("error", "some error");

            // Act
            var result = await controller.PutAsync(1, UserGenerator.GetTestUpdateUserResource());

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }