public async Task ShouldPutStudentGuardianAsync() { // given Student inputStudent = await PostStudentAsync(); Guardian inputGuardian = await PostGuardianAsync(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(inputStudent.Id, inputGuardian.Id); StudentGuardian inputStudentGuardian = randomStudentGuardian; await this.otripleSApiBroker.PostStudentGuardianAsync(inputStudentGuardian); StudentGuardian modifiedStudentGuardian = randomStudentGuardian.DeepClone(); modifiedStudentGuardian.UpdatedDate = DateTimeOffset.UtcNow; // when await this.otripleSApiBroker.PutStudentGuardianAsync(modifiedStudentGuardian); StudentGuardian actualStudentGuardian = await this.otripleSApiBroker.GetStudentGuardianAsync( randomStudentGuardian.StudentId, randomStudentGuardian.GuardianId); // then actualStudentGuardian.Should().BeEquivalentTo(modifiedStudentGuardian); await this.otripleSApiBroker.DeleteStudentGuardianAsync(actualStudentGuardian.StudentId, actualStudentGuardian.GuardianId); await this.otripleSApiBroker.DeleteGuardianByIdAsync(actualStudentGuardian.GuardianId); await this.otripleSApiBroker.DeleteStudentByIdAsync(actualStudentGuardian.StudentId); }
public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotSameAsCreateDateAndLogItAsync() { // given int randomNumber = GetRandomNumber(); int randomMinutes = randomNumber; DateTimeOffset randomDate = GetRandomDateTime(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(randomDate); StudentGuardian invalidStudentGuardian = randomStudentGuardian; invalidStudentGuardian.UpdatedDate = randomDate; StudentGuardian storageStudentGuardian = randomStudentGuardian.DeepClone(); Guid studentId = invalidStudentGuardian.StudentId; Guid semesterCourseId = invalidStudentGuardian.GuardianId; invalidStudentGuardian.CreatedDate = storageStudentGuardian.CreatedDate.AddMinutes(randomNumber); var invalidStudentGuardianInputException = new InvalidStudentGuardiantException( parameterName: nameof(StudentGuardian.CreatedDate), parameterValue: invalidStudentGuardian.CreatedDate); var expectedStudentGuardianValidationException = new StudentGuardianValidationException(invalidStudentGuardianInputException); this.storageBrokerMock.Setup(broker => broker.SelectStudentGuardianByIdAsync(studentId, semesterCourseId)) .ReturnsAsync(storageStudentGuardian); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(randomDate); // when ValueTask <StudentGuardian> modifyStudentGuardianTask = this.studentGuardianService.ModifyStudentGuardianAsync(invalidStudentGuardian); // then await Assert.ThrowsAsync <StudentGuardianValidationException>(() => modifyStudentGuardianTask.AsTask()); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentGuardianByIdAsync( invalidStudentGuardian.StudentId, invalidStudentGuardian.GuardianId), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentGuardianValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldModifyStudentGuardianAsync() { // given int randomNumber = GetRandomNumber(); int randomDays = randomNumber; DateTimeOffset randomDate = GetRandomDateTime(); DateTimeOffset randomInputDate = GetRandomDateTime(); StudentGuardian randomStudentGuardian = CreateRandomStudentGuardian(randomInputDate); StudentGuardian inputStudentGuardian = randomStudentGuardian; StudentGuardian afterUpdateStorageStudentGuardian = inputStudentGuardian; StudentGuardian expectedStudentGuardian = afterUpdateStorageStudentGuardian; StudentGuardian beforeUpdateStorageStudentGuardian = randomStudentGuardian.DeepClone(); inputStudentGuardian.UpdatedDate = randomDate; Guid studentId = inputStudentGuardian.StudentId; Guid guardianId = inputStudentGuardian.GuardianId; this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(randomDate); this.storageBrokerMock.Setup(broker => broker.SelectStudentGuardianByIdAsync(studentId, guardianId)) .ReturnsAsync(beforeUpdateStorageStudentGuardian); this.storageBrokerMock.Setup(broker => broker.UpdateStudentGuardianAsync(inputStudentGuardian)) .ReturnsAsync(afterUpdateStorageStudentGuardian); // when StudentGuardian actualStudentGuardian = await this.studentGuardianService.ModifyStudentGuardianAsync(inputStudentGuardian); // then actualStudentGuardian.Should().BeEquivalentTo(expectedStudentGuardian); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentGuardianByIdAsync(studentId, guardianId), Times.Once); this.storageBrokerMock.Verify(broker => broker.UpdateStudentGuardianAsync(inputStudentGuardian), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }