public void Add_DLAddIsInvoked() { CandidateInformation candidateInfo = new CandidateInformation() { FirstName = "John", Surname = "Smith", Address = "Brighton", Email = "*****@*****.**", SkillSet = "C#", SavedOn = DateTime.Now }; var mockCandidateInfoRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<CandidateInformation>>(); ICandidateInformationBL candidateInfoBL = new BL.CandidateInformationBL(mockCandidateInfoRepo); candidateInfoBL.Add(candidateInfo); mockCandidateInfoRepo.AssertWasCalled(x => x.Add(candidateInfo)); }
public void FindAll_DLFindAllIsInvoked_ReturnsValues() { IQueryable<CandidateInformation> expectedValue = new List<CandidateInformation>().AsQueryable(); var mockCandidateInfoRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<CandidateInformation>>(); mockCandidateInfoRepo.Stub(x => x.FindAll()).Return(expectedValue); ICandidateInformationBL candidateInfoBL = new BL.CandidateInformationBL(mockCandidateInfoRepo); IQueryable<CandidateInformation> actualValue = candidateInfoBL.FindAll(); mockCandidateInfoRepo.AssertWasCalled(m => m.FindAll()); Assert.AreEqual(expectedValue, actualValue); }
public void FindById_DLFindByIdIsInvoked_ReturnsValue() { int id1 = 1; int id2 = 2; CandidateInformation candidateInfo1 = new CandidateInformation { Id = id1, FirstName = "John", Surname = "Smith", Address = "Brighton", Email = "*****@*****.**", SkillSet = "C#", SavedOn = DateTime.Now }; CandidateInformation candidateInfo2 = new CandidateInformation { Id = id2, FirstName = "John", Surname = "Smith", Address = "Brighton", Email = "*****@*****.**", SkillSet = "JavaScript", SavedOn = DateTime.Now }; CandidateInformation expectedValue = candidateInfo1; var mockCandidateInfoRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<CandidateInformation>>(); mockCandidateInfoRepo.Stub(x => x.FindById(id1)).Return(candidateInfo1); ICandidateInformationBL candidateInfoBL = new BL.CandidateInformationBL(mockCandidateInfoRepo); CandidateInformation actualValue = candidateInfoBL.FindById(id1); mockCandidateInfoRepo.AssertWasCalled(m => m.FindById(id1)); Assert.AreEqual(expectedValue, actualValue); }
public void Find_DLFindIsInvoked_ReturnsValue() { int id1 = 1; int id2 = 2; CandidateInformation candidateInfo1 = new CandidateInformation { Id = id1, FirstName = "John", Surname = "Smith", Address = "Brighton", Email = "*****@*****.**", SkillSet = "C#", SavedOn = DateTime.Now }; CandidateInformation candidateInfo2 = new CandidateInformation { Id = id2, FirstName = "John", Surname = "Smith", Address = "Brighton", Email = "*****@*****.**", SkillSet = "JavaScript", SavedOn = DateTime.Now }; IQueryable<CandidateInformation> candidateInfoes = new List<CandidateInformation>() { candidateInfo1, candidateInfo2 }.AsQueryable(); IQueryable<CandidateInformation> expectedValue = candidateInfoes.Where(x => x.SkillSet == "C#"); Expression<Func<CandidateInformation, bool>> queryExpression = (x => x.SkillSet == "C#"); var mockCandidateInfoRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<CandidateInformation>>(); mockCandidateInfoRepo.Stub(x => x.Find(queryExpression)).Return(candidateInfoes.Where(x => x.SkillSet == "C#")); ICandidateInformationBL candidateInfoBL = new BL.CandidateInformationBL(mockCandidateInfoRepo); IQueryable<CandidateInformation> actualValue = candidateInfoBL.Find(queryExpression); mockCandidateInfoRepo.AssertWasCalled(m => m.Find(queryExpression)); Assert.AreEqual(expectedValue.Count(), actualValue.Count()); }