Ejemplo n.º 1
0
        public async Task ShouldThrowStudentViewDependencyExceptionIfDependencyErrorOccursAndLogItAsync(
            Exception dependencyException)
        {
            // given
            var expectedStudentViewDependencyException =
                new StudentViewDependencyException(dependencyException);

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

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

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

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

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

            this.studentServiceMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.navigationBrokerMock.VerifyNoOtherCalls();
            this.userServiceMock.VerifyNoOtherCalls();
        }
        private StudentViewDependencyException CreateAndLogDependencyException(Exception exception)
        {
            var studentViewDependencyException = new StudentViewDependencyException(exception);

            this.loggingBroker.LogError(studentViewDependencyException);

            return(studentViewDependencyException);
        }
Ejemplo n.º 3
0
        public async Task ShouldThrowDependencyExceptionOnAddIfStudentDependencyErrorOccuredAndLogItAsync(
            Exception studentServiceDependencyException)
        {
            // given
            StudentView someStudentView = CreateRandomStudentView();

            var expectedStudentDependencyException =
                new StudentViewDependencyException(studentServiceDependencyException);

            this.studentServiceMock.Setup(service =>
                                          service.RegisterStudentAsync(It.IsAny <Student>()))
            .ThrowsAsync(studentServiceDependencyException);

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

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

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

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

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

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

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