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()); } }
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 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 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 DatabaseInjectionSteps(ScenarioContext context, ContactService contactService, HubRepository hubRepository) { this.context = context; this.contactService = contactService; this.hubRepository = hubRepository; }
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); } }
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); } }
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); } }
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); } }
public IHubRepository <TEntity> GetHubRepository <TEntity>() where TEntity : IDvHubEntity, new() { if (_repositories == null) { _repositories = new Dictionary <Type, object>(); } var type = typeof(TEntity); if (!_repositories.ContainsKey(type)) { _repositories[type] = new HubRepository <TEntity>(DataVaultContext); } return((IHubRepository <TEntity>)_repositories[type]); }
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); } }
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()); } }
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); } }
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); } }
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)); } }