Skip to content

Commit

Permalink
#24: GetApplicantById unit test when id is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
choutianxius committed Sep 10, 2024
1 parent 9b0f7a7 commit da56b59
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion AggieRent.Tests/Services/ApplicantServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void GetApplicantById_ValidId_ThenReturnRelatedUser()
},
];
mockApplicantRepository
.Setup(x => x.Get(It.IsAny<string>()))
.Setup(x => x.GetVerbose(It.IsAny<string>()))
.Returns((string id) => applicants.FirstOrDefault(a => a.Id == id));
var applicantService = new ApplicantService(mockApplicantRepository.Object);

Expand All @@ -42,6 +42,24 @@ public void GetApplicantById_ValidId_ThenReturnRelatedUser()
OccupiedApartmentId = applicants[0].OccupiedApartmentId,
};
Assert.Equivalent(expectedApplicant, returnedApplicant);
mockApplicantRepository.Verify(x => x.GetVerbose(applicants[0].Id), Times.Once());
}

[Fact]
public void GetApplicantById_UnknownId_ThenReturnNull()
{
var mockApplicantRepository = new Mock<IApplicantRepository>();
List<Applicant> applicants = [];
mockApplicantRepository
.Setup(x => x.GetVerbose(It.IsAny<string>()))
.Returns((string id) => applicants.FirstOrDefault(a => a.Id == id));
var applicantService = new ApplicantService(mockApplicantRepository.Object);

var idToFind = Guid.NewGuid().ToString();
var returnedApplicant = applicantService.GetApplicantById(idToFind);

Assert.Null(returnedApplicant);
mockApplicantRepository.Verify(x => x.GetVerbose(idToFind), Times.Once());
}
}
}

0 comments on commit da56b59

Please sign in to comment.