Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }