private void ValidateChanges(ExpectedChanges expectedChanges, PlanSnapshot.Changes actualChanges)
        {
            ValidateChanges(expectedChanges.Inserted, actualChanges.Insert);
            ValidateChanges(expectedChanges.Deleted, actualChanges.Delete);

            Assert.AreEqual(expectedChanges.Updates.Count, actualChanges.Update.Count);

            foreach (var update in expectedChanges.Updates.GroupBy(x => x.ObjectId))
            {
                var updateId       = update.Key;
                var expectedUpdate = update.ToArray();
                var actualUpdate   = actualChanges.Update.FirstOrDefault(x => x.Node.Id == updateId);

                Assert.NotNull(actualUpdate);
                Assert.AreEqual(expectedUpdate.Length, actualUpdate.ChangedProperties.Count);

                foreach (var propUpdate in expectedUpdate)
                {
                    var name       = propUpdate.PropertyName;
                    var actualProp = actualUpdate.ChangedProperties.FirstOrDefault(x => x.Name == name);

                    Assert.NotNull(actualProp);
                    Assert.AreEqual(propUpdate.Value, actualProp.GetValue(actualUpdate.Node));
                }
            }
        }
        public void CanUpdateProperties()
        {
            var provider        = new PlanStorageProviderMonitor(GenerateRefTree());
            var repository      = new PlanRepository(new PlanStorage(new PlanCache(new ExpirationStrategyMock()), provider));
            var expectedChanges = new ExpectedChanges
            {
                Updates =
                {
                    new ExpectedObjectChange(NewGuid(2), "Label", "newName"),
                    new ExpectedObjectChange(NewGuid(3), "Label", "newName3")
                }
            };

            repository.GetById <ActivityDO>(NewGuid(2)).Label = "newName";
            repository.GetById <ActivityDO>(NewGuid(3)).Label = "newName3";

            repository.SaveChanges();

            ValidateChanges(expectedChanges, provider.SubmittedChanges);
        }
        public void CanUpdateStructure()
        {
            var provider        = new PlanStorageProviderMonitor(GenerateRefTree());
            var repository      = new PlanRepository(new PlanStorage(new PlanCache(new ExpirationStrategyMock()), provider));
            var expectedChanges = new ExpectedChanges
            {
                Inserted = { NewGuid(4) },
                Deleted  = { NewGuid(3) }
            };

            repository.GetById <ActivityDO>(NewGuid(3)).Label = "newName";
            repository.GetById <ActivityDO>(NewGuid(3)).RemoveFromParent();
            repository.GetById <ActivityDO>(NewGuid(1)).ChildNodes.Add(new ActivityDO
            {
                Id    = NewGuid(4),
                Label = "Base4",
            });

            repository.SaveChanges();

            ValidateChanges(expectedChanges, provider.SubmittedChanges);
        }