示例#1
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);
            }
        }
        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;
                }
            }
        }
示例#4
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);
            }
        }
示例#5
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);
            }
        }
示例#6
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);
            }
        }
示例#7
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);
            }
        }
示例#8
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));
            }
        }