public void ReadById_AddressRecord_ExpectedAddressRecordForProvidedAddressId() { int addressId = 1; DataModel.Address address; DataModel.Contact contact = new DataModel.Contact() { Id = 1, FirstName = "FirstName", LastName = "LastName", Type = new DataModel.ContactType() { Id = 1, Type = "PERSON" } }; mockAddressRepository.Setup((item) => item.Read(addressId)).Returns( address = new DataModel.Address() { Id = 1, Street = "Street", Contact = contact } ); var addressRepository = new BusinessRepository.AddressRepository(mockLogger.Object, mockAddressRepository.Object ); var result = addressRepository.Read(addressId); Assert.IsNotNull(result); Assert.IsTrue(result.FullAddress == GetFullAddress(address)); Assert.IsTrue(result.ContactId == contact.Id); }
public void Update_AddressRecord_ExpectedFailedUpdateFlag() { 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 updateAddressModel = new DataModel.Address() { Id = 10, Street = "Street", City = "City", State = "State", Contact = contactModelList.First() }; DateTime oldUpdatedTime = updateAddressModel.Updated; mockedAddressDBSet = GetQueryableMockDbSet <DataModel.Address>(addressList.ToList()); 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.Update(updateAddressModel)); Assert.AreEqual(updateAddressModel.Updated, oldUpdatedTime); Assert.IsNull(mockAddressBook.Object.AddressList.SingleOrDefault((item) => item.Id == updateAddressModel.Id)); }
public void Setup() { mockAddressRepository = new Mock <DataInterface.IAddressRepository>(); mockDatabaseSettings = new Mock <DataInterface.IDatabaseSetting>(); mockLogger = new Mock <ILogger <BusinessRepository.AddressRepository> >(); mockDataContext = new Mock <DataInterface.IDBContext <DataContext.AddressBook> >(); addressModel = new DataModel.Address(); }
public void Setup() { mockDatabaseSettings = new Mock <DataInterface.IDatabaseSetting>(); mockLogger = new Mock <ILogger <DataRepository.AddressRepository> >(); mockDataContext = new Mock <DataInterface.IDBContext <DataContext.AddressBook> >(); mockAddressBook = new Mock <DataContext.AddressBook>(); contactModelList = new DataModel.Contact[] { new DataModel.Contact() { Id = 1, FirstName = "FirstName", LastName = "LastName" }, new DataModel.Contact() { Id = 2, FirstName = "FirstName1", LastName = "LastName1" } }; addressModelList = new DataModel.Address[] { new DataModel.Address() { Id = 1, Street = "Street", City = "City", State = "State", Contact = contactModelList.First() }, new DataModel.Address() { Id = 2, Street = "Street1", City = "City1", State = "State1", Contact = contactModelList.First() }, new DataModel.Address() { Id = 3, Street = "Street", City = "City", State = "State", Contact = contactModelList.Last() }, new DataModel.Address() { Id = 4, Street = "Street1", City = "City1", State = "State1", Contact = contactModelList.Last() } }; mockedContactDBSet = GetQueryableMockDbSet <DataModel.Contact>(contactModelList.ToList()); mockedAddressDBSet = GetQueryableMockDbSet <DataModel.Address>(addressModelList.ToList()); addressModel = addressModelList.First(); }
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 Update_AddressRecord_ExpectedSuccessfulUpdateFlag() { 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 updateAddressModel = addressModelList.First(); DateTime oldUpdatedTime = updateAddressModel.Updated; 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.Update(updateAddressModel)); Assert.AreNotEqual(updateAddressModel.Updated, oldUpdatedTime); Assert.IsTrue(mockAddressBook.Object.AddressList.SingleOrDefault((item) => item.Id == updateAddressModel.Id).Id == updateAddressModel.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); }
public void Setup() { mockDatabaseSettings = new Mock <DataInterface.IDatabaseSetting>(); mockLogger = new Mock <ILogger <DataRepository.AddressRepository> >(); mockDataContext = new Mock <DataInterface.IDBContext <DataContext.AddressBook> >(); mockAddressBook = new Mock <DataContext.AddressBook>(); contactTypeModelList = new DataModel.ContactType[] { new DataModel.ContactType() { Id = 1, Type = "PERSON" }, new DataModel.ContactType() { Id = 2, Type = "BUSINESS" }, new DataModel.ContactType() { Id = 3, Type = "OTHER" }, }; contactModelList = new DataModel.Contact[] { new DataModel.Contact() { Id = 1, FirstName = "FirstName", LastName = "LastName", Type = contactTypeModelList.Single((item) => item.Id == 1) }, new DataModel.Contact() { Id = 2, FirstName = "FirstName1", LastName = "LastName1", Type = contactTypeModelList.Single((item) => item.Id == 2) }, new DataModel.Contact() { Id = 3, FirstName = "FirstName1", LastName = "LastName1", Type = contactTypeModelList.Single((item) => item.Id == 3) } }; addressModelList = new DataModel.Address[] { new DataModel.Address() { Id = 1, Street = "Street", City = "City", State = "State", Contact = contactModelList.First() }, new DataModel.Address() { Id = 2, Street = "Street1", City = "City1", State = "State1", Contact = contactModelList.First() }, new DataModel.Address() { Id = 3, Street = "Street", City = "City", State = "State", Contact = contactModelList.Last() }, new DataModel.Address() { Id = 4, Street = "Street1", City = "City1", State = "State1", Contact = contactModelList.Last() } }; mockedContactDBSet = GetQueryableMockDbSet <DataModel.Contact>(contactModelList.ToList()); mockedAddressDBSet = GetQueryableMockDbSet <DataModel.Address>(addressModelList.ToList()); mockedContactTypeDBSet = GetQueryableMockDbSet <DataModel.ContactType>(contactTypeModelList.ToList()); contactModel = contactModelList.First(); addressModel = addressModelList.First(); }
private string GetFullAddress(DataModel.Address address) { return(address.Street + "," + address.City + "," + address.State); }