public async Task ShouldThrowDependencyExceptionOnDeleteWhenDbUpdateConcurrencyExceptionOccursAndLogItAsync() { // given Guid randomExamFeeId = Guid.NewGuid(); Guid inputExamFeeId = randomExamFeeId; var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedExamFeeException = new LockedExamFeeException(databaseUpdateConcurrencyException); var expectedExamFeeException = new ExamFeeDependencyException(lockedExamFeeException); this.storageBrokerMock.Setup(broker => broker.SelectExamFeeByIdAsync(inputExamFeeId)) .ThrowsAsync(databaseUpdateConcurrencyException); // when ValueTask <ExamFee> deleteExamFeeTask = this.examFeeService.RemoveExamFeeByIdAsync(inputExamFeeId); // then await Assert.ThrowsAsync <ExamFeeDependencyException>(() => deleteExamFeeTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedExamFeeException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectExamFeeByIdAsync(inputExamFeeId), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public void ShouldThrowDependencyExceptionOnRetrieveAllExamFeesWhenSqlExceptionOccursAndLogIt() { // given var sqlException = GetSqlException(); var expectedExamFeeDependencyException = new ExamFeeDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectAllExamFees()) .Throws(sqlException); // when Action retrieveAllExamFeesAction = () => this.examFeeService.RetrieveAllExamFees(); // then Assert.Throws <ExamFeeDependencyException>( retrieveAllExamFeesAction); this.storageBrokerMock.Verify(broker => broker.SelectAllExamFees(), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( expectedExamFeeDependencyException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
private ExamFeeDependencyException CreateAndLogDependencyException(Exception exception) { var examFeeDependencyException = new ExamFeeDependencyException(exception); this.loggingBroker.LogError(examFeeDependencyException); return(examFeeDependencyException); }
public async Task ShouldThrowDependencyExceptionOnModifyIfDbUpdateConcurrencyExceptionOccursAndLogItAsync() { // given int randomNegativeNumber = GetNegativeRandomNumber(); DateTimeOffset randomDateTime = GetRandomDateTime(); ExamFee someExamFee = CreateRandomExamFee(randomDateTime); someExamFee.CreatedDate = randomDateTime.AddMinutes(randomNegativeNumber); var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedExamFeeException = new LockedExamFeeException(databaseUpdateConcurrencyException); var expectedExamFeeDependencyException = new ExamFeeDependencyException(lockedExamFeeException); this.storageBrokerMock.Setup(broker => broker.SelectExamFeeByIdAsync(someExamFee.Id)) .ThrowsAsync(databaseUpdateConcurrencyException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(randomDateTime); // when ValueTask <ExamFee> modifyExamFeeTask = this.examFeeService.ModifyExamFeeAsync(someExamFee); // then await Assert.ThrowsAsync <ExamFeeDependencyException>(() => 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( expectedExamFeeDependencyException))), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnCreateWhenDbExceptionOccursAndLogItAsync() { // given DateTimeOffset dateTime = GetRandomDateTime(); ExamFee someExamFee = CreateRandomExamFee(dateTime); someExamFee.UpdatedBy = someExamFee.CreatedBy; someExamFee.UpdatedDate = someExamFee.CreatedDate; var databaseUpdateException = new DbUpdateException(); var expectedExamFeeDependencyException = new ExamFeeDependencyException(databaseUpdateException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(dateTime); this.storageBrokerMock.Setup(broker => broker.InsertExamFeeAsync(It.IsAny <ExamFee>())) .ThrowsAsync(databaseUpdateException); // when ValueTask <ExamFee> createExamFeeTask = this.examFeeService.AddExamFeeAsync(someExamFee); // then await Assert.ThrowsAsync <ExamFeeDependencyException>(() => 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( expectedExamFeeDependencyException))), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnRetrieveWhenDbExceptionOccursAndLogItAsync() { // given Guid someExamFeeId = Guid.NewGuid(); var databaseUpdateException = new DbUpdateException(); var expectedExamFeeDependencyException = new ExamFeeDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.SelectExamFeeByIdAsync(someExamFeeId)) .ThrowsAsync(databaseUpdateException); // when ValueTask <ExamFee> retrieveExamFeeByIdTask = this.examFeeService.RetrieveExamFeeByIdAsync(someExamFeeId); // then await Assert.ThrowsAsync <ExamFeeDependencyException>(() => retrieveExamFeeByIdTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedExamFeeDependencyException))), 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(); }