public void Create_AddressRecord_ExpectedFailedCreationFlag() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var addressRepository = new DataRepository.AddressRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); DataModel.Address newAddressModel = new DataModel.Address() { Id = 10, Street = "Street", City = "City", State = "State", Contact = contactModelList.First() }; mockAddressBook.Setup((item) => item.Add(addressModel)).Throws(new Exception("Unexpected")); mockAddressBook.Setup((item) => item.SaveChanges()).Returns(0); mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object); mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object); Assert.IsFalse(addressRepository.Create(addressModel)); Assert.IsNull(mockAddressBook.Object.AddressList.SingleOrDefault((item) => item.Id == newAddressModel.Id)); }
public void Create_AddressRecord_ExpectedSuccessfulCreationFlag() { mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object); var addressRepository = new DataRepository.AddressRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object); List <DataModel.Address> addressList = addressModelList.ToList(); DataModel.Address newAddressModel = new DataModel.Address() { Id = 10, Street = "Street", City = "City", State = "State", Contact = contactModelList.First() }; addressList.Add(newAddressModel); mockedAddressDBSet = GetQueryableMockDbSet <DataModel.Address>(addressList.ToList()); 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(addressRepository.Create(newAddressModel)); Assert.IsTrue(mockAddressBook.Object.AddressList.SingleOrDefault((item) => item.Id == newAddressModel.Id).Id == newAddressModel.Id); }