public async Task DeleteAsync_DeleteInvalidUser_ObjectNotFoundException() { // Arrange var getableUser = new Mock <IGetableUser>(); var userRepository = new Mock <IRepositoryAsync <UserEntity> >(); var editUser = new EditUser( getableUser.Object, userRepository.Object); getableUser.Setup(gu => gu.GetById(_user.Id)) .Throws(new ObjectNotFoundException($"User by Id:{_user.Id} not found.")); // Act Func <Task> act = async() => await editUser.DeleteAsync(_user.Id); // Assert await Assert.ThrowsAsync <ObjectNotFoundException>(act); }
public async Task DeleteAsync_DeleteUser_User() { // Arrange var getableUser = new Mock <IGetableUser>(); var userRepository = new Mock <IRepositoryAsync <UserEntity> >(); var userService = new EditUser( getableUser.Object, userRepository.Object); getableUser.Setup(gu => gu.GetById(_user.Id)) .Returns(_user); // Act var result = await userService.DeleteAsync(_user.Id); // Assert Assert.NotNull(result); Assert.Equal(_user, result); Assert.Equal(_user.Id, result.Id); }