Skip to content

Commit

Permalink
Use SameValidationExceptionAs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kandarpgautam committed Feb 12, 2024
1 parent 2d9579c commit aaf3357
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ public async Task
Guid differentId = Guid.NewGuid();
Guid invalidCreatedBy = differentId;
Student randomStudent = CreateRandomStudent(dates: randomDate);
Student invalidStudent = randomStudent;
Student storageStudent = randomStudent.DeepClone();
invalidStudent.CreatedDate = storageStudent.CreatedDate.AddDays(randomNumber);
invalidStudent.UpdatedDate = storageStudent.UpdatedDate;
invalidStudent.CreatedBy = invalidCreatedBy;
Guid studentId = invalidStudent.Id;
Student modifiedStudent = storageStudent.DeepClone();
modifiedStudent.CreatedDate = storageStudent.CreatedDate.AddDays(randomNumber);
modifiedStudent.UpdatedDate = storageStudent.UpdatedDate;
modifiedStudent.CreatedBy = invalidCreatedBy;
Guid studentId = modifiedStudent.Id;

var invalidStudentException = new InvalidStudentException();

Expand All @@ -284,12 +284,12 @@ public async Task
values: $"Date is not the same as {nameof(Student.CreatedDate)}");
invalidStudentException.AddData(
key: nameof(Student.UpdatedDate),
values: $"Date is same as {nameof(Student.UpdatedDate)}");
values: $"Date is the same as {nameof(Student.UpdatedDate)}");
invalidStudentException.AddData(
key: nameof(Student.CreatedBy),
values: $"Id is not the same as {nameof(Student.CreatedBy)}");

var expectedStudentValidationException =
StudentValidationException expectedStudentValidationException =
new StudentValidationException(invalidStudentException);

this.storageBrokerMock.Setup(broker =>
Expand All @@ -302,7 +302,7 @@ public async Task

// when
ValueTask<Student> modifyStudentTask =
this.studentService.ModifyStudentAsync(invalidStudent);
this.studentService.ModifyStudentAsync(modifiedStudent);

// then
await Assert.ThrowsAsync<StudentValidationException>(() =>
Expand All @@ -313,13 +313,12 @@ await Assert.ThrowsAsync<StudentValidationException>(() =>
Times.Once);

this.storageBrokerMock.Verify(broker =>
broker.SelectStudentByIdAsync(invalidStudent.Id),
broker.SelectStudentByIdAsync(modifiedStudent.Id),
Times.Once);

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

this.loggingBrokerMock.VerifyNoOtherCalls();
this.storageBrokerMock.VerifyNoOtherCalls();
Expand Down

0 comments on commit aaf3357

Please sign in to comment.