示例#1
0
        private async ValueTask <List <StudentView> > TryCatch(ReturningStudentViewsFunction returningStudentViewsFunction)
        {
            try
            {
                return(await returningStudentViewsFunction());
            }
            catch (StudentDependencyException studentDependencyException)
            {
                throw CreateAndLogDependencyException(studentDependencyException);
            }
            catch (StudentServiceException studentServiceException)
            {
                throw CreateAndLogDependencyException(studentServiceException);
            }
            catch (Exception serviceException)
            {
                var failedStudentViewServiceException = new FailedStudentViewServiceException(serviceException);

                throw CreateAndLogServiceException(failedStudentViewServiceException);
            }
        }
示例#2
0
        public async Task ShouldThrowStudentViewServiceExceptionIfServiceErrorOccursAndLogItAsync()
        {
            // given
            var serviceException = new Exception();

            var failedStudentViewServiceException =
                new FailedStudentViewServiceException(serviceException);

            var expectedStudentViewServiceException =
                new StudentViewServiceException(failedStudentViewServiceException);

            this.studentServiceMock.Setup(service =>
                                          service.RetrieveAllStudentsAsync())
            .ThrowsAsync(serviceException);

            // when
            ValueTask <List <StudentView> > retrieveAllStudentViewsTask =
                this.studentViewService.RetrieveAllStudentViewsAsync();

            // then
            await Assert.ThrowsAsync <StudentViewServiceException>(() =>
                                                                   retrieveAllStudentViewsTask.AsTask());

            this.studentServiceMock.Verify(service =>
                                           service.RetrieveAllStudentsAsync(),
                                           Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedStudentViewServiceException))),
                                          Times.Once);

            this.studentServiceMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.navigationBrokerMock.VerifyNoOtherCalls();
            this.userServiceMock.VerifyNoOtherCalls();
        }