public PhoneBookTest() { pbMgr = new PhoneBookMgr(); factoryMock = new Mock <IUnitOfWorkFactory>(); uowMock = new Mock <IUnitOfWork>(); repoMock = new Mock <IPhoneBookRepository>(); factoryMock.Setup(f => f.GetUnitOfWork()).Returns(uowMock.Object); uowMock.Setup(f => f.PhoneBookRepo).Returns(repoMock.Object); }
public void FindPersonInDB() { string name = "John Smith"; repoMock.Setup(x => x.GetAll(It.IsAny <Expression <Func <PHONEBOOK, bool> > >())).Returns(new List <PHONEBOOK> { new PHONEBOOK { NAME = "John Smith" } }); PhoneBookMgr phbk = new PhoneBookMgr(factoryMock.Object); List <IPerson> lstPerson = phbk.GetAllPeopleFromDB(name); Assert.IsNotNull(lstPerson); // Test if null Assert.AreEqual(1, lstPerson.Count); // Verify the correct Number }
public void AddPersonToDB() { bool savewascalled = false; repoMock.Setup(x => x.Add(It.Is <PHONEBOOK>(c => c.NAME == "John Smith"))).Returns(true); uowMock.Setup(f => f.SaveChanges()).Callback(() => savewascalled = true); PhoneBookMgr phbk = new PhoneBookMgr(factoryMock.Object); Person per = new Person(); per.SetAddress(""); per.SetName("John Smith"); per.SetPhoneNum(""); bool retval = phbk.AddPersonToDB(per); Assert.AreEqual(true, retval, "Add is successful"); Assert.IsTrue(savewascalled, "Save was called"); }