Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODE RUB: Use SameValidationExceptionAs instead of SameExceptionAs #2654

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading