public async Task ShouldThrowServiceExceptionOnDeleteWhenExceptionOccursAndLogItAsync() { // given Guid randomExamFeeId = Guid.NewGuid(); Guid inputExamFeeId = randomExamFeeId; var exception = new Exception(); var expectedExamFeeServiceException = new ExamFeeServiceException(exception); this.storageBrokerMock.Setup(broker => broker.SelectExamFeeByIdAsync(inputExamFeeId)) .ThrowsAsync(exception); // when ValueTask <ExamFee> deleteExamFeeTask = this.examFeeService.RemoveExamFeeByIdAsync(inputExamFeeId); // then await Assert.ThrowsAsync <ExamFeeServiceException>(() => deleteExamFeeTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedExamFeeServiceException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectExamFeeByIdAsync(inputExamFeeId), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public void ShouldThrowServiceExceptionOnRetrieveAllExamFeesWhenExceptionOccursAndLogIt() { // given var exception = new Exception(); var expectedExamFeeServiceException = new ExamFeeServiceException(exception); this.storageBrokerMock.Setup(broker => broker.SelectAllExamFees()) .Throws(exception); // when . then Assert.Throws <ExamFeeServiceException>(() => this.examFeeService.RetrieveAllExamFees()); this.storageBrokerMock.Verify(broker => broker.SelectAllExamFees(), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedExamFeeServiceException))), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
private ExamFeeServiceException CreateAndLogServiceException(Exception exception) { var examFeeServiceException = new ExamFeeServiceException(exception); this.loggingBroker.LogError(examFeeServiceException); return(examFeeServiceException); }
public async Task ShouldThrowServiceExceptionOnModifyIfServiceExceptionOccursAndLogItAsync() { // given int randomNegativeNumber = GetNegativeRandomNumber(); DateTimeOffset randomDateTime = GetRandomDateTime(); ExamFee someExamFee = CreateRandomExamFee(randomDateTime); someExamFee.CreatedDate = randomDateTime.AddMinutes(randomNegativeNumber); var serviceException = new Exception(); var failedExamFeeServiceException = new FailedExamFeeServiceException(serviceException); var expectedExamFeeServiceException = new ExamFeeServiceException(failedExamFeeServiceException); this.storageBrokerMock.Setup(broker => broker.SelectExamFeeByIdAsync(someExamFee.Id)) .ThrowsAsync(serviceException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(randomDateTime); // when ValueTask <ExamFee> modifyExamFeeTask = this.examFeeService.ModifyExamFeeAsync(someExamFee); // then await Assert.ThrowsAsync <ExamFeeServiceException>(() => modifyExamFeeTask.AsTask()); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectExamFeeByIdAsync(someExamFee.Id), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedExamFeeServiceException))), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowServiceExceptionOnCreateWhenExceptionOccursAndLogItAsync() { // given DateTimeOffset dateTime = GetRandomDateTime(); ExamFee someExamFee = CreateRandomExamFee(dateTime); someExamFee.UpdatedBy = someExamFee.CreatedBy; someExamFee.UpdatedDate = someExamFee.CreatedDate; var serviceException = new Exception(); var failedExamFeeServiceException = new FailedExamFeeServiceException(serviceException); var expectedExamFeeServiceException = new ExamFeeServiceException(failedExamFeeServiceException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(dateTime); this.storageBrokerMock.Setup(broker => broker.InsertExamFeeAsync(It.IsAny <ExamFee>())) .ThrowsAsync(serviceException); // when ValueTask <ExamFee> createExamFeeTask = this.examFeeService.AddExamFeeAsync(someExamFee); // then await Assert.ThrowsAsync <ExamFeeServiceException>(() => createExamFeeTask.AsTask()); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertExamFeeAsync(It.IsAny <ExamFee>()), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedExamFeeServiceException))), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowServiceExceptionOnRetrieveWhenExceptionOccursAndLogItAsync() { // given Guid someExamFeeId = Guid.NewGuid(); var serviceException = new Exception(); var failedExamFeeServiceException = new FailedExamFeeServiceException(serviceException); var expectedExamFeeServiceException = new ExamFeeServiceException(failedExamFeeServiceException); this.storageBrokerMock.Setup(broker => broker.SelectExamFeeByIdAsync(someExamFeeId)) .ThrowsAsync(serviceException); // when ValueTask <ExamFee> retrieveExamFeeByIdTask = this.examFeeService.RetrieveExamFeeByIdAsync(someExamFeeId); // then await Assert.ThrowsAsync <ExamFeeServiceException>(() => retrieveExamFeeByIdTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedExamFeeServiceException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectExamFeeByIdAsync(someExamFeeId), Times.Once); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }