Beispiel #1
0
        public void ShouldThrowServiceExceptionOnNavigateIfServiceErrorOccursAndLogIt()
        {
            // given
            string someRoute        = GetRandomRoute();
            var    serviceException = new Exception();

            var expectedStudentViewServiceException =
                new StudentViewServiceException(serviceException);

            this.navigationBrokerMock.Setup(broker =>
                                            broker.NavigateTo(It.IsAny <string>()))
            .Throws(serviceException);

            // when
            Action navigateToAction = () =>
                                      this.studentViewService.NavigateTo(someRoute);

            // then
            Assert.Throws <StudentViewServiceException>(navigateToAction);

            this.navigationBrokerMock.Verify(broker =>
                                             broker.NavigateTo(It.IsAny <string>()),
                                             Times.Once);

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

            this.navigationBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.userServiceMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.studentServiceMock.VerifyNoOtherCalls();
        }
        private StudentViewServiceException CreateAndLogServiceException(Exception exception)
        {
            var studentViewServiceException = new StudentViewServiceException(exception);

            this.loggingBroker.LogError(studentViewServiceException);

            return(studentViewServiceException);
        }
Beispiel #3
0
        public async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccuredAndLogItAsync()
        {
            // given
            StudentView someStudentView  = CreateRandomStudentView();
            var         serviceException = new Exception();

            var expectedStudentServiceException =
                new StudentViewServiceException(serviceException);

            this.userServiceMock.Setup(service =>
                                       service.GetCurrentlyLoggedInUser())
            .Throws(serviceException);

            // when
            ValueTask <StudentView> addStudentViewTask =
                this.studentViewService.AddStudentViewAsync(someStudentView);

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

            this.userServiceMock.Verify(service =>
                                        service.GetCurrentlyLoggedInUser(),
                                        Times.Once);

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

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Never);

            this.studentServiceMock.Verify(service =>
                                           service.RegisterStudentAsync(It.IsAny <Student>()),
                                           Times.Never);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.userServiceMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.studentServiceMock.VerifyNoOtherCalls();
            this.navigationBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #4
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();
        }