public async void ShouldThrowValidationExceptionOnModifyWhenUserIsNullAndLogItAsync() { // given User randomUser = null; User nullUser = randomUser; var nullUserException = new NullUserException(); var expectedUserValidationException = new UserValidationException(nullUserException); // when ValueTask <User> modifyUserTask = this.userService.ModifyUserAsync(nullUser); // then await Assert.ThrowsAsync <UserValidationException>(() => modifyUserTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedUserValidationException))), Times.Once); this.userManagementBrokerMock.Verify(broker => broker.SelectUserByIdAsync(It.IsAny <Guid>()), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.userManagementBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnCreateWhenUserIsNullAndLogItAsync() { // given User invalidUser = null; var nullUserException = new NullUserException(); string password = GetRandomPassword(); var expectedUserValidationException = new UserValidationException(nullUserException); // when ValueTask <User> createUserTask = this.userService.RegisterUserAsync(invalidUser, password); // then await Assert.ThrowsAsync <UserValidationException>(() => createUserTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedUserValidationException))), Times.Once); this.userManagementBrokerMock.Verify(broker => broker.SelectUserByIdAsync(It.IsAny <Guid>()), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.userManagementBrokerMock.VerifyNoOtherCalls(); }