예제 #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));
        }
예제 #2
0
        public void ReadByContactId_AddressRecorsdByContactId_ExpectedEmptyRecordProvidedContactId()
        {
            mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object);

            var addressRepository = new DataRepository.AddressRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object);

            mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object);
            mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object);

            Assert.IsEmpty(addressRepository.ReadByContactId(11));
            Assert.IsEmpty(addressRepository.ReadByContactId(12));
        }
예제 #3
0
        public void ReadAll_AddressRecord_ExpectedAllAddressRecords()
        {
            mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object);

            var addressRepository = new DataRepository.AddressRepository(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.True(addressRepository.ReadAll().FirstOrDefault().Id == 1);
        }
예제 #4
0
        public void Read_AddressRecordById_ExpectedNullForProvidedId()
        {
            mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object);

            var addressRepository = new DataRepository.AddressRepository(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(addressRepository.Read(11));
        }
예제 #5
0
        public void ReadByContactId_AddressRecordsByContactId_ExpectedAddressRecordForContactId()
        {
            mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object);

            var addressRepository = new DataRepository.AddressRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object);

            mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object);
            mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressDBSet.Object);

            Assert.IsTrue(addressRepository.ReadByContactId(1).FirstOrDefault().Id == 1);
            Assert.IsTrue(addressRepository.ReadByContactId(1).LastOrDefault().Id == 2);
            Assert.IsTrue(addressRepository.ReadByContactId(2).FirstOrDefault().Id == 3);
            Assert.IsTrue(addressRepository.ReadByContactId(2).LastOrDefault().Id == 4);
        }
예제 #6
0
        public void ReadAll_AddressRecord_ExpectedEmptyResult()
        {
            mockDataContext.Setup((item) => item.Context).Returns(mockAddressBook.Object);

            var addressRepository = new DataRepository.AddressRepository(mockLogger.Object, mockDatabaseSettings.Object, mockDataContext.Object);

            var mockedAddressNoResultDBSet = GetQueryableMockDbSet <DataModel.Address>((new DataModel.Address[] { }).ToList());

            mockAddressBook.Setup((item) => item.SaveChanges()).Returns(1);
            mockAddressBook.Setup((item) => item.Contacts).Returns(mockedContactDBSet.Object);
            mockAddressBook.Setup((item) => item.AddressList).Returns(mockedAddressNoResultDBSet.Object);

            Assert.IsEmpty(addressRepository.ReadAll());
        }
예제 #7
0
        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));
        }
예제 #8
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);
        }
예제 #9
0
        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);
        }