private static void AssertEquals(PlanNodeDO expected, PlanNodeDO actual) { var snapShotA = new PlanSnapshot(expected, false); var snapShotB = new PlanSnapshot(actual, false); var changes = snapShotB.Compare(snapShotA); if (changes.HasChanges) { foreach (var changedObject in changes.Update) { foreach (var prop in changedObject.ChangedProperties) { var expectedValue = prop.GetValue(expected.GetDescendants().First(x => x.Id == changedObject.Node.Id), null); var actualValue = prop.GetValue(changedObject.Node, null); Assert.Fail($"Plans are different. Property {prop.Name} of plan node {changedObject.Node.Id} is expected to has value '{expectedValue}' but has value '{actualValue}'"); } } foreach (var planNodeDo in changes.Insert) { Assert.Fail($"Plans are different. It is not expected to see node {planNodeDo.Id}"); } foreach (var planNodeDo in changes.Delete) { Assert.Fail($"Plans are different. Missing node {planNodeDo.Id}"); } } }
private static bool AreEquals(PlanNodeDO a, PlanNodeDO b) { var snapShotA = new PlanSnapshot(a, false); var snapShotB = new PlanSnapshot(b, false); return(!snapShotB.Compare(snapShotA).HasChanges); }
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 CanDetectInsertion() { var snapshot1 = new PlanSnapshot(GenerateRefTree(), false); var snapshot2 = new PlanSnapshot(GenerateChangedTree_v3(), false); var changes = snapshot2.Compare(snapshot1); Assert.AreEqual(1, changes.Insert.Count); Assert.AreEqual(0, changes.Delete.Count); Assert.AreEqual(0, changes.Update.Count); }
public PlanSnapshot CreateSnapshot() { var snapshot = new PlanSnapshot { Id = Id, Status = _status.Status.ToList(), Versions = _version.Versions.Select(x => x.CreateSnapshot()).ToList() }; return(snapshot); }
public Plan(PlanSnapshot snapshot) { Id = snapshot.Id; _version = new VersionMixin <PlanVersion>(snapshot.Versions.Select(x => new PlanVersion(x))); _status = new StatusMixin <EPlanStatus>(snapshot.Status); }