public void GetBestCandidateForJobWithXYearsExperience_WithMultipleCandidatesMatchingCriteria_ReturnsCandidateWithMostExperience() { // Arrange var candidate = new Candidate { Name = "Nick", WorkHistory = new List <CandidateJob> { new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddYears(1).AddDays(1) } } }; var candidate2 = new Candidate { Name = "Nick 2", WorkHistory = new List <CandidateJob> { new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddYears(1).AddDays(2) } } }; var candidateRepo = new CandidateRepository(new List <Candidate> { candidate, candidate2 }); // Act var result = candidateRepo.GetBestCandidateForJobWithXYearsExperience("Software Developer", 1); // Assert Assert.AreEqual(candidate2.Name, result.Name); }
static void Main(string[] args) { // Load candidates into memory, I wouldn't couple this to repo class if expanded and instead keep it as a separate responsiblity. // If we had logic unrelated to repo we could also wrap this in a service layer to e.g. trigger emails as part of the same call, then a controller layer to handle routing if we're // going full onion architecture. var candidates = JsonConvert.DeserializeObject<IList<Candidate>>(File.ReadAllText($@"..\..\..\candidates.json")); var repo = new CandidateRepository(candidates); Console.WriteLine("Welcome to the CharityJob super awesome candidate matcher."); while (true) { Console.WriteLine("What job would you like to search for?"); Console.Write("Answer: "); var result = repo.GetBestCandidateForJobWithXYearsExperience(Console.ReadLine(), 5); var response = result == null ? "Sorry no result this time." : $"Congrats we found a match! Name: {result.Name}, Email: {result.Email}, Phone: {result.Phone}"; Console.WriteLine(response); } }
public void GetBestCandidateForJobWithXYearsExperience_WithCandidatesNotMatchingJobDescription_AreNotReturnedInResponse() { // Arrange var candidate = new Candidate { Name = "Nick", WorkHistory = new List <CandidateJob> { new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddYears(1).AddDays(1) } } }; var candidateRepo = new CandidateRepository(new List <Candidate> { candidate }); // Act var result = candidateRepo.GetBestCandidateForJobWithXYearsExperience("Software Developer 123", 1); // Assert Assert.AreEqual(null, result); }
public void GetBestCandidateForJobWithXYearsExperience_WithCandidateWithoutEndDate_CalculatesEndDateAsStartDate() { // Arrange var candidate = new Candidate { Name = "Nick", WorkHistory = new List <CandidateJob> { new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow.AddYears(-1).AddDays(-1) } } }; var candidateRepo = new CandidateRepository(new List <Candidate> { candidate }); // Act var result = candidateRepo.GetBestCandidateForJobWithXYearsExperience("Software Developer", 1); // Assert Assert.AreEqual(candidate.Name, result.Name); }
public void GetBestCandidateForJobWithXYearsExperience_WithEmptyJobTitle_ReturnsNull() { // Arrange var candidate = new Candidate { Name = "Nick", WorkHistory = new List <CandidateJob> { new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddYears(1).AddDays(1) } } }; var candidateRepo = new CandidateRepository(new List <Candidate> { candidate }); // Act var result = candidateRepo.GetBestCandidateForJobWithXYearsExperience("", 1); // Assert Assert.AreEqual(null, result); }
public void GetBestCandidateForJobWithXYearsExperience_WithCandidateWithMultipleJobRolesMatching_SumsUpAllResults() { // Arrange var candidate = new Candidate { Name = "Nick", WorkHistory = new List <CandidateJob> { new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(6) }, new CandidateJob { JobTitle = "Software Developer", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(6).AddDays(1) } } }; var candidateRepo = new CandidateRepository(new List <Candidate> { candidate }); // Act var result = candidateRepo.GetBestCandidateForJobWithXYearsExperience("Software Developer", 1); // Assert Assert.AreEqual(candidate.Name, result.Name); }