public void SynchronizeResetsEntityNewState()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

            ctx.As.Add(a);
            var gr    = new EntityGraph(a, new FullEntityGraphShape());
            var clone = gr.Clone();

            ctxNew.As.Attach(clone.Source);
            Assert.IsTrue(a.EntityState == EntityState.New);
            gr.Synchronize(clone);
            Assert.IsTrue(a.EntityState == EntityState.Unmodified);
        }
        public void PartialSaveTest()
        {
            EntityGraphTestsDomainContext context = new EntityGraphTestsDomainContext();
            var a = new A {
                Id = 1
            };
            var b = new B {
                Id = 1
            };

            context.As.Attach(a);
            context.Bs.Attach(b);
            context.Bs.Attach(new B {
                Id = 2, AId = 1
            });
            context.Bs.Attach(new B {
                Id = 3, AId = 1
            });

            a.name = "Modified Task 1";

            EntityGraphTestsDomainContext tempContext = new EntityGraphTestsDomainContext();

            var shape = new FullEntityGraphShape();

            var graph = new EntityGraph(a, shape);

            Assert.IsTrue(context.HasChanges);
            Assert.IsTrue(graph.HasChanges);
            Assert.IsTrue(graph.IsChanged);

            var clone = graph.Clone(tempContext);

            Assert.IsTrue(tempContext.HasChanges);
            Assert.IsTrue(clone.HasChanges);
            Assert.IsTrue(clone.IsChanged);

            clone.AcceptChanges();
            graph.Synchronize(clone);

            Assert.IsFalse(context.HasChanges);
            Assert.IsFalse(graph.HasChanges);
            Assert.IsFalse(graph.IsChanged);

            Assert.IsFalse(tempContext.HasChanges);
            Assert.IsFalse(clone.HasChanges);
            Assert.IsFalse(clone.IsChanged);
        }
        public void SynchronizeWithMergeIntoCurrentTest()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

            ctx.As.Attach(a);
            var gr    = new EntityGraph(a, new FullEntityGraphShape());
            var clone = gr.Clone();

            ctxNew.As.Attach(clone.Source);
            ((A)clone.Source).name = "Some name";
            a.lastName             = "Some last name";
            Assert.IsTrue(a.EntityState == EntityState.Modified);
            gr.Synchronize(clone, LoadBehavior.MergeIntoCurrent);
            Assert.IsTrue(a.name == "Some name");
            Assert.IsTrue(a.lastName == "Some last name");
        }