Exemplo n.º 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());
            }
        }
Exemplo n.º 2
0
        public void KeyCachingIsSharedByAllInstances()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                //single insert
                var insertedLink = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);

                //new repository created -> cache is initialized from memory context
                // -> cache already kontains the key
                linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);

                // same key again -> insert prevented
                var insertedLink2 = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);

                var list = linkRepo.Get();
                Assert.NotNull(list);
                Assert.Single(list);
            }
        }
Exemplo n.º 3
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);
            }
        }
        public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var hubRepo       = new HubRepository <H_TestHub_Stores>(context, HashFunctions.MD5, null);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_Stores>(context, HashFunctions.MD5);
                var linkRepo      = new LinkRepository <L_TestLink_Stores>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);

                var loadDate = DateTime.Now;

                // HUB - storing info
                hubRepo.Insert(TestHub1, loadDate, loadInformation: LoadInfo1);

                var hub = hubRepo.GetByKey(TestHub1.PrimaryKey);

                Assert.Equal(LoadInfo1.RecordSource, hub.RecordSource);
                Assert.Equal(LoadInfo1.LoadedBy, hub.LoadedBy);

                // SATELLITE - storing info
                Hub1Satellite1 = satelliteRepo.Insert(Hub1Satellite1, loadDate, loadInformation: LoadInfo1);

                var sat = satelliteRepo.GetCurrent(s => s.Reference == TestHub1.PrimaryKey).Single();

                Assert.Equal(LoadInfo1.RecordSource, sat.RecordSource);
                Assert.Equal(LoadInfo1.LoadedBy, sat.LoadedBy);

                // LINK - storing info
                Link1 = linkRepo.Insert(Link1, loadDate, loadInformation: LoadInfo1);

                var link = linkRepo.GetByKey(Link1.PrimaryKey);

                Assert.Equal(LoadInfo1.RecordSource, link.RecordSource);
                Assert.Equal(LoadInfo1.LoadedBy, link.LoadedBy);
            }
        }
        public void StoreLinkList()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var linkRepo = GetLinkRepo(context, keyCache);
                var loadDate = DateTime.Now;

                var list = new List <L_Link_Timeline>();
                for (int i = 0; i < insertCount; i++)
                {
                    var link = new L_Link_Timeline();
                    list.Add(link);
                }
                linkRepo.Insert(list, loadDate);

                var links = linkRepo.GetCurrent().ToList();
                Assert.Equal(insertCount, links.Count());
                Assert.Equal(list, links);

                linkRepo.Insert(list, loadDate);

                links = linkRepo.GetCurrent().ToList();
                Assert.Equal(insertCount, links.Count());
                Assert.Equal(list, links);

                var timelineRepo = GetTimelineRepo(context);
                var timeline     = timelineRepo.GetAll();
                Assert.Equal(insertCount, links.Count());
                foreach (var entry in timeline)
                {
                    Assert.Null(entry.EndDate);
                    Assert.Single(links.Where(x => x.PrimaryKey == entry.Reference));
                }
            }
        }
        public void StoreAndDeleteLink()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache     = new BasePrimaryKeyCache();
                var linkRepo     = GetLinkRepo(context, keyCache);
                var timelineRepo = GetTimelineRepo(context);

                var loadDate = DateTime.Now;

                var link1 = new L_Link_Timeline();
                for (int i = 1; i <= insertCount; i++)
                {
                    linkRepo.Insert(link1, loadDate.AddDays(i));
                    linkRepo.RemoveLink(link1, loadDate.AddDays(i).AddHours(12));

                    var timeline = timelineRepo.GetAll().ToList();
                }


                var storedTimeline = timelineRepo.GetAll();
                Assert.Equal(insertCount, storedTimeline.Count());

                var lastDate = loadDate;
                foreach (var entry in storedTimeline)
                {
                    Assert.Equal(OneDay, entry.LoadDate - lastDate);
                    Assert.Equal(TwelfeHours, entry.EndDate - entry.LoadDate);
                    lastDate = entry.LoadDate;
                }
            }
        }
Exemplo n.º 7
0
        public void EmptySetsYieldNoResults()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var testRepo = new SatelliteRepository <S_TestSatellite_Default>(context, HashFunctions.MD5);

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

                testList = testRepo.GetAll();
                Assert.Empty(testList);
            }
        }
        public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var referenceRepo = new CRUDRepository <LoadInformation, long>(context);

                var hubRepo       = new HubRepository <H_TestHub_References>(context, HashFunctions.MD5, null);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_References>(context, HashFunctions.MD5);
                var linkRepo      = new LinkRepository <L_TestLink_References>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);

                var loadDate = DateTime.Now;

                // REFERENCE ENTRY - inserting and data persistence tests
                var load1Key = referenceRepo.Insert(LoadInfo1);
                var load2Key = referenceRepo.Insert(LoadInfo2);

                var hubList = referenceRepo.Get();
                Assert.NotEmpty(hubList);
                Assert.Equal(2, hubList.Count());
                Assert.False(load1Key == default);
                Assert.False(load2Key == default);

                var loadInfo = referenceRepo.Get(x => x.PrimaryKey == load2Key).Single();

                Assert.Equal(LoadInfo2.RecordSource, loadInfo.RecordSource);
                Assert.Equal(LoadInfo2.LoadedBy, loadInfo.LoadedBy);

                // HUB - referencing
                TestHub1 = hubRepo.Insert(TestHub1, loadDate, loadReference: LoadInfo1);
                TestHub2 = hubRepo.Insert(TestHub2, loadDate, loadReference: LoadInfo2);
                Assert.Equal(load1Key, TestHub1.LoadReference);
                Assert.Equal(load2Key, TestHub2.LoadReference);

                // SATELLITE - referencing
                Hub1Satellite1 = satelliteRepo.Insert(Hub1Satellite1, loadDate, loadReference: LoadInfo1);
                Hub2Satellite1 = satelliteRepo.Insert(Hub2Satellite1, loadDate, loadReference: LoadInfo2);

                Assert.Equal(load1Key, Hub1Satellite1.LoadReference);
                Assert.Equal(load2Key, Hub2Satellite1.LoadReference);

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


                // LINK - referencing
                Link1 = linkRepo.Insert(Link1, loadDate, loadReference: LoadInfo1);

                Assert.Equal(load1Key, Link1.LoadReference);

                Link1 = linkRepo.Get().Single();
                Assert.Equal(load1Key, Link1.LoadReference);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public void KeyCalculation()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var testRepo = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);
                var loadDate = DateTime.Now;

                //single insert
                var test = testRepo.Insert(AdditionalTest, loadDate);
                Assert.Equal(HashFunctions.MD5(test.GetBusinessKeyString()), test.PrimaryKey);
                Assert.Equal(HashFunctions.MD5(test.GetBusinessKeyString()), testRepo.CalculateHashes(test).PrimaryKey);
            }
        }
Exemplo n.º 11
0
        public void DuplicatePrimaryKeyException()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_Default>(context, HashFunctions.MD5);

                var loadDate = DateTime.Now;

                //single insert
                satelliteRepo.Insert(Hub1Satellite1, loadDate);

                // same key (same loaddate) again
                Assert.Throws <InvalidOperationException>(() => satelliteRepo.Insert(Hub1Satellite2, loadDate));
            }
        }
Exemplo n.º 12
0
        public void CreateLink()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
                linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
            }
        }
Exemplo n.º 13
0
        public void KeyCalculation()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                L_TestLink_Default link = new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey);
                //single insert
                var insertedLink = linkRepo.Insert(link, loadDate);
                Assert.Equal(HashFunctions.MD5(link.GetBusinessKeyString()), insertedLink.PrimaryKey);
            }
        }
Exemplo n.º 14
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());
            }
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
0
        public void KeyCalculation()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var hubRepo       = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_Default>(context, HashFunctions.MD5);

                var loadDate = DateTime.Now;

                //single insert
                var testHub = hubRepo.Insert(TestHub1, loadDate);
                Assert.Equal(HashFunctions.MD5(testHub.GetBusinessKeyString()), testHub.PrimaryKey);
                Assert.Equal(HashFunctions.MD5(testHub.GetBusinessKeyString()), hubRepo.CalculateHashes(testHub).PrimaryKey);

                //single insert
                var testSatellite = satelliteRepo.Insert(Hub1Satellite1, loadDate);
                Assert.Equal(HashFunctions.MD5(testHub.GetBusinessKeyString()), testSatellite.Reference);
                Assert.Equal(HashFunctions.MD5(testHub.GetBusinessKeyString()), testSatellite.PrimaryKey.Reference);
            }
        }
Exemplo n.º 17
0
        public void LinkKeyCaching()
        {
            //Caching enabled -> same key is ignored
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                //single insert
                var insertedLink = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
                // same key again
                var insertedLink2 = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);

                Assert.Equal(insertedLink.PrimaryKey, insertedLink2.PrimaryKey);

                var queriedLinks = linkRepo.Get();

                Assert.NotNull(queriedLinks);
                Assert.Single(queriedLinks);
            }

            //caching disabled -> insert throws exception
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                //single insert
                var insertedLink = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
                // same key again
                Assert.Throws <InvalidOperationException>(() => linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate));
            }
        }
 private static LinkTimelineRepository <L_Link_Timeline, S_LinkTimelineEntry> GetLinkRepo(TestDwhDbContext context, IPrimaryKeyCache keyCache)
 {
     return(new LinkTimelineRepository <L_Link_Timeline, S_LinkTimelineEntry>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled));
 }
 private static SatelliteRepository <S_LinkTimelineEntry> GetTimelineRepo(TestDwhDbContext context)
 {
     return(new SatelliteRepository <S_LinkTimelineEntry>(context, HashFunctions.MD5));
 }