Beispiel #1
0
        public void ShouldThrowValidationExceptionOnNavigateIfRouteIsInvalidAndLogItAsync(
            string invalidRoute)
        {
            // given
            var invalidStudentViewException =
                new InvalidStudentViewException(
                    parameterName: "Route",
                    parameterValue: invalidRoute);

            var expectedStudentViewValidationException =
                new StudentViewValidationException(invalidStudentViewException);

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

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

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

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

            this.navigationBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.userServiceMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.studentServiceMock.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public async Task ShouldThrowValidationExceptionOnAddIfStudentIdentityIsInvalidAndLogItAsync(
            string invalidIdentityNumber)
        {
            // given
            StudentView randomStudentView  = CreateRandomStudentView();
            StudentView invalidStudentView = randomStudentView;

            invalidStudentView.IdentityNumber = invalidIdentityNumber;

            var invalidStudentViewException = new InvalidStudentViewException(
                parameterName: nameof(StudentView.IdentityNumber),
                parameterValue: invalidStudentView.IdentityNumber);

            var expectedStudentViewValidationException =
                new StudentViewValidationException(invalidStudentViewException);

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

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

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

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

            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();
        }