public void CanUpdateCache() { var expiration = new ExpirationStrategyMock(); var planId = new Guid(1, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0); int calledTimes = 0; var plan = LoadPlan(planId); var referenceRoute = LoadPlan(planId); Func <Guid, PlanNodeDO> cacheMiss = x => { calledTimes++; Assert.AreEqual(planId, x); return(plan); }; var cache = new PlanCache(expiration); var plan1 = cache.Get(planId, cacheMiss); var updated = LoadPlan(planId, "updated"); var o = new PlanSnapshot(plan1, false); var c = new PlanSnapshot(updated, false); cache.Update(updated.Id, c.Compare(o)); var plan2 = cache.Get(planId, cacheMiss); Assert.AreEqual(1, calledTimes); Assert.IsTrue(AreEquals(plan1, referenceRoute)); Assert.IsTrue(AreEquals(plan2, updated)); }
public void CanLoadFromCacheUsingChildActivitiesId() { var expiration = new ExpirationStrategyMock(); var planId = new Guid(1, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0); int calledTimes = 0; var plan = LoadPlan(planId); Func <Guid, PlanNodeDO> cacheMiss = x => { calledTimes++; return(plan); }; var cache = new PlanCache(expiration); var plan1 = cache.Get(new Guid(2, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0), cacheMiss); Assert.IsTrue(AreEquals(plan1, plan)); foreach (var id in PlanTreeHelper.Linearize(plan).Select(x => x.Id)) { Assert.IsTrue(AreEquals(plan, cache.Get(id, cacheMiss))); } Assert.AreEqual(1, calledTimes); }
public void CanPersistPropertyChanges() { var provider = new PlanStorageProviderMonitor(GenerateRefTree()); var cache = new PlanCache(new ExpirationStrategyMock()); var repository = new PlanRepository(new PlanStorage(cache, provider)); repository.GetById <ActivityDO>(NewGuid(2)).Label = "newName"; repository.GetById <ActivityDO>(NewGuid(3)).Label = "newName3"; repository.SaveChanges(); repository = new PlanRepository(new PlanStorage(cache, provider)); Assert.AreEqual("newName", repository.GetById <ActivityDO>(NewGuid(2)).Label, "Labels are different"); Assert.AreEqual("newName3", repository.GetById <ActivityDO>(NewGuid(3)).Label, "Labels are different"); }
public void CanAddPlan() { var provider = new PersistentPlanStorage(null); var cache = new PlanCache(new ExpirationStrategyMock()); var repository = new PlanRepository(new PlanStorage(cache, provider)); var plan = GenerateTestPlan(); repository.Add(plan); repository.SaveChanges(); var loadedPlan = provider.LoadPlan(Guid.Empty); AssertEquals(plan, loadedPlan); AssertEquals(plan, repository.GetById <PlanDO>(NewGuid(13))); }
public void CanAddPlanWithEmptyDefaultIds() { var provider = new PersistentPlanStorage(null); var cache = new PlanCache(new ExpirationStrategyMock()); var repository = new PlanRepository(new PlanStorage(cache, provider)); var refPlan = GenerateTestPlan(); PlanTreeHelper.Visit(refPlan, x => x.Id = Guid.Empty); repository.Add(refPlan); repository.SaveChanges(); PlanTreeHelper.Visit(refPlan, x => Assert.IsTrue(x.Id != Guid.Empty)); var loadedPlan = provider.LoadPlan(Guid.Empty); AssertEquals(refPlan, loadedPlan); }
public void CanLoadOnCacheMiss() { var expiration = new ExpirationStrategyMock(); var planId = new Guid(1, (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0); int calledTimes = 0; Func <Guid, PlanNodeDO> cacheMiss = x => { calledTimes++; Assert.AreEqual(planId, x); return(LoadPlan(x)); }; var cache = new PlanCache(expiration); cache.Get(planId, cacheMiss); Assert.AreEqual(1, calledTimes); }