Example #1
0
        public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var testRepo = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var loadDate = DateTime.Now;

                //Bulk insert
                testRepo.Insert(testInstances, loadDate);

                var testList = testRepo.Get();
                Assert.NotEmpty(testList);
                Assert.Equal(testInstances.Count, testList.Count());
                Assert.Equal(testInstances.Count, testRepo.Count());

                var test = testRepo.GetByKey(AdditionalTest.PrimaryKey);
                Assert.Null(test);

                //additional insert
                testRepo.Insert(AdditionalTest, loadDate);

                testList = testRepo.Get();
                Assert.NotEmpty(testList);
                Assert.Equal(testInstances.Count + 1, testList.Count());
            }
        }
Example #2
0
        public void KeyCachingCanBeSharedByAllInstances()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var cache    = new BasePrimaryKeyCache();
                var testRepo = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, cache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                //single insert
                testRepo.Insert(AdditionalTest, loadDate);

                // same key again
                testRepo.Insert(AdditionalTest, loadDate);

                var list = testRepo.Get(x => x.TestNr == AdditionalTest.TestNr);
                Assert.NotNull(list);
                Assert.Single(list);

                //new repository created -> cache is initialized from memory context
                // -> cache already kontains the key
                testRepo = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, cache, DVKeyCaching.Enabled);

                // same key again  -> insert is prevented
                testRepo.Insert(AdditionalTest, loadDate);

                list = testRepo.Get(x => x.TestNr == AdditionalTest.TestNr);
                Assert.NotNull(list);
                Assert.Single(list);
            }
        }
Example #3
0
        public void EmptySetsYieldNoResults()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var testRepo = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);

                var testList = testRepo.Get();
                Assert.Empty(testList);

                var test = testRepo.GetByKey("UnknownId");
                Assert.Null(test);
            }
        }
Example #4
0
        public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var hubRepo       = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_Default>(context, HashFunctions.MD5);

                var loadDate = DateTime.Now;

                hubRepo.Insert(TestHub1, loadDate);
                hubRepo.Insert(TestHub2, loadDate);

                var hubList = hubRepo.Get();
                Assert.NotEmpty(hubList);
                Assert.Equal(2, hubList.Count());


                satelliteRepo.Insert(Hub1Satellite1, loadDate);
                satelliteRepo.Insert(Hub2Satellite1, loadDate);

                var satelliteList = satelliteRepo.GetCurrent();
                Assert.NotEmpty(satelliteList);
                Assert.Equal(2, satelliteList.Count());

                //increment load date to simulate later insert of new data slice
                loadDate = loadDate.AddDays(1);

                satelliteRepo.Insert(Hub1Satellite2, loadDate);
                satelliteRepo.Insert(Hub2Satellite2, loadDate);

                satelliteList = satelliteRepo.GetCurrent();
                Assert.NotEmpty(satelliteList);
                Assert.Equal(2, satelliteList.Count());

                var satHub1 = satelliteList.Where(sat => sat.TestNr == TestHubBusinessKey1).Single();
                var satHub2 = satelliteList.Where(sat => sat.TestNr == TestHubBusinessKey2).Single();

                Assert.Equal(Hub1Satellite2, satHub1);
                Assert.Equal(Hub2Satellite2, satHub2);


                // a total of 4 should now be stored in the db
                satelliteList = satelliteRepo.GetAll();
                Assert.NotEmpty(satelliteList);
                Assert.Equal(4, satelliteList.Count());
            }
        }
Example #5
0
        public void HubKeyCachingPreventsInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var cache    = new BasePrimaryKeyCache();
                var testRepo = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, cache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                //single insert
                testRepo.Insert(AdditionalTest, loadDate);

                // same key again
                testRepo.Insert(AdditionalTest, loadDate);

                var list = testRepo.Get(x => x.TestNr == AdditionalTest.TestNr);
                Assert.NotNull(list);
                Assert.Single(list);
            }
        }