public void Create_ContactRecord_ExpectedSuccessfulCreationFlag() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); List <DataModel.Contact> contactList = contactModelList.ToList(); DataModel.Contact newContactModel = new DataModel.Contact() { Id = 10, FirstName = "FirstName", LastName = "LastName", Type = contactTypeModelList.First() }; contactList.Add(newContactModel); mockedContactDBSet = GetQueryableMockDbSet <DataModel.Contact>(contactList.ToList()); mockAddressBook.Setup((item) => item.SaveChanges()).Returns(1); mockAddressBook.Setup((item) => item.ContactTypes).Returns(mockedContactTypeDBSet.Object); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsTrue(contactRepository.Create(newContactModel)); Assert.IsTrue(mockAddressBook.Object.Contacts.SingleOrDefault((item) => item.Id == newContactModel.Id).Id == newContactModel.Id); }
public void ReadAll_ContactRecord_ExpectedAllContactRecords() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); mockAddressBook.Setup((item) => item.SaveChanges()).Returns(1); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsTrue(contactRepository.ReadAll().First().Id == 1); Assert.IsTrue(contactRepository.ReadAll().Last().Id == 3); }
public void ReadAll_ContactRecord_ExpectedEmptyResult() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); var mockedContactNoResultDBSet = GetQueryableMockDbSet <DataModel.Contact>((new DataModel.Contact[] { }).ToList()); mockAddressBook.Setup((item) => item.SaveChanges()).Returns(1); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactNoResultDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsEmpty(contactRepository.ReadAll()); }
public void Read_ContactRecordById_ExpectedNullForProvidedId() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); mockAddressBook.Setup((item) => item.SaveChanges()).Returns(1); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsNull(contactRepository.Read(11)); Assert.IsNull(contactRepository.Read(12)); Assert.IsNull(contactRepository.Read(13)); }
public void Update_ContactRecord_ExpectedSuccessfulUpdateFlag() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); List <DataModel.Contact> contactList = contactModelList.ToList(); DataModel.Contact updateContactModel = contactModelList.First(); DateTime oldUpdatedTime = updateContactModel.Updated; mockAddressBook.Setup((item) => item.SaveChanges()).Returns(1); mockAddressBook.Setup((item) => item.ContactTypes).Returns(mockedContactTypeDBSet.Object); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsTrue(contactRepository.Update(updateContactModel)); Assert.AreNotEqual(updateContactModel.Updated, oldUpdatedTime); Assert.IsTrue(mockAddressBook.Object.Contacts.SingleOrDefault((item) => item.Id == updateContactModel.Id).Id == updateContactModel.Id); }
public void Update_Contact_ExpectedFailedUpdateFlag() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); List <DataModel.Contact> contactList = contactModelList.ToList(); DataModel.Contact updateContactModel = new DataModel.Contact() { Id = 10, FirstName = "Street", LastName = "City", Type = contactTypeModelList.First() }; DateTime oldUpdatedTime = updateContactModel.Updated; mockAddressBook.Setup((item) => item.SaveChanges()).Returns(0); mockAddressBook.Setup((item) => item.ContactTypes).Returns(mockedContactTypeDBSet.Object); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsFalse(contactRepository.Update(updateContactModel)); Assert.AreEqual(updateContactModel.Updated, oldUpdatedTime); Assert.IsNull(mockAddressBook.Object.Contacts.SingleOrDefault((item) => item.Id == updateContactModel.Id)); }
public void Create_ContactRecord_ExpectedFailedCreationFlag() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var contactRepository = new DataRepository.ContactRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); List <DataModel.Contact> contactList = contactModelList.ToList(); DataModel.Contact newContactModel = new DataModel.Contact() { Id = 10, FirstName = "FirstName", LastName = "LastName", Type = contactTypeModelList.First() }; contactList.Add(newContactModel); mockAddressBook.Setup((item) => item.Add(newContactModel)).Throws(new Exception("Unexpected")); mockAddressBook.Setup((item) => item.SaveChanges()).Returns(0); mockAddressBook.Setup((item) => item.ContactTypes).Returns(mockedContactTypeDBSet.Object); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsFalse(contactRepository.Create(newContactModel)); Assert.IsNull(mockAddressBook.Object.Contacts.SingleOrDefault((item) => item.Id == newContactModel.Id)); }