public void TestDeleteOneApplicant() { // Arrange Mock <IApplicantRepository> mockApplicRepo = new Mock <IApplicantRepository>(MockBehavior.Loose); List <Applicant> applList = new List <Applicant>() { new Applicant() { ApplId = 1, ApplName = "Arkagij Petrov" }, new Applicant() { ApplId = 2, ApplName = "Anastasiya Konovalova" }, new Applicant() { ApplId = 3, ApplName = "Darina Kadurova" }, new Applicant() { ApplId = 4, ApplName = "Alina Komarova" }, new Applicant() { ApplId = 5, ApplName = "Vyacheslav Petrushin" }, }; List <Applicant> expected = new List <Applicant>() { new Applicant() { ApplId = 1, ApplName = "Arkagij Petrov" }, new Applicant() { ApplId = 3, ApplName = "Darina Kadurova" }, new Applicant() { ApplId = 4, ApplName = "Alina Komarova" }, new Applicant() { ApplId = 5, ApplName = "Vyacheslav Petrushin" }, }; mockApplicRepo.Setup(repo => repo.GetAll()).Returns(applList.AsQueryable); ApplicantLogic logic = new ApplicantLogic(mockApplicRepo.Object); mockApplicRepo.Setup(repo => repo.GetOne(2)).Returns(applList[2 - 1]); var del = logic.GetOneApplicant(2); mockApplicRepo.Setup(repo => repo.Remove(del)).Callback(() => applList.Remove(del)); mockApplicRepo.Verify(repo => repo.Remove(del), Times.AtMostOnce); }
public void TestGetOneApplicant() { // ARRANGE Mock <IApplicantRepository> mockApplRepo = new Mock <IApplicantRepository>(MockBehavior.Loose); List <Applicant> people = new List <Applicant>() { new Applicant() { ApplId = 1, ApplName = "Arkagij Petrov" }, new Applicant() { ApplId = 2, ApplName = "Anastasiya Konovalova" }, new Applicant() { ApplId = 3, ApplName = "Darina Kadurova" }, new Applicant() { ApplId = 4, ApplName = "Alina Komarova" }, new Applicant() { ApplId = 5, ApplName = "Vyacheslav Petrushin" }, }; Applicant expected = new Applicant() { ApplId = 2, ApplName = "Anastasiya Konovalova" }; mockApplRepo.Setup(repo => repo.GetOne(2)).Returns(expected as Applicant); ApplicantLogic applic_Logic = new ApplicantLogic(mockApplRepo.Object); // ACT Applicant result = applic_Logic.GetOneApplicant(2); mockApplRepo.Verify(repo => repo.GetOne(2), Times.Once); }