public async Task ShouldThrowValidatonExceptionOnRetrieveWhenContactIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomContactId = default;
            Guid randomStudentId = Guid.NewGuid();
            Guid inputContactId  = randomContactId;
            Guid inputStudentId  = randomStudentId;

            var invalidStudentContactException = new InvalidStudentContactException(
                parameterName: nameof(StudentContact.ContactId),
                parameterValue: inputContactId);

            var expectedStudentContactValidationException =
                new StudentContactValidationException(invalidStudentContactException);

            // when
            ValueTask <StudentContact> retrieveStudentContactTask =
                this.studentContactService.RetrieveStudentContactByIdAsync(inputStudentId, inputContactId);

            // then
            await Assert.ThrowsAsync <StudentContactValidationException>(() => retrieveStudentContactTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentContactByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
示例#2
0
        public async void ShouldThrowValidationExceptionOnAddWhenContactIdIsInvalidAndLogItAsync()
        {
            // given
            StudentContact randomStudentContact = CreateRandomStudentContact();
            StudentContact inputStudentContact  = randomStudentContact;

            inputStudentContact.ContactId = default;

            var invalidStudentContactException = new InvalidStudentContactException(
                parameterName: nameof(StudentContact.ContactId),
                parameterValue: inputStudentContact.ContactId);

            var expectedStudentContactValidationException =
                new StudentContactValidationException(invalidStudentContactException);

            // when
            ValueTask <StudentContact> addStudentContactTask =
                this.studentContactService.AddStudentContactAsync(inputStudentContact);

            // then
            await Assert.ThrowsAsync <StudentContactValidationException>(() =>
                                                                         addStudentContactTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertStudentContactAsync(It.IsAny <StudentContact>()),
                                          Times.Never);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }