예제 #1
0
        public void CloneIntoPreservesEntityStateNewTest()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

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

            Assert.IsTrue(a.EntityState == EntityState.New);
            Assert.IsTrue(clone.Source.EntityState == EntityState.New);
        }
        public void SynchronizePreservesEntityStateUnmodifiedTest()
        {
            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);
            clone.Synchronize(gr);
            Assert.IsTrue(a.EntityState == EntityState.Unmodified);
            Assert.IsTrue(clone.Source.EntityState == EntityState.Unmodified);
        }
예제 #3
0
        public void CloneIntoPreservesEntityStateModifiedTest()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

            ctx.As.Attach(a);
            a.name = "Hello World";

            var gr    = new EntityGraph(a, new FullEntityGraphShape());
            var clone = gr.Clone(ctxNew);

            Assert.IsTrue(a.EntityState == EntityState.Modified);
            Assert.IsTrue(clone.Source.EntityState == EntityState.Modified);
        }
        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 SynchronizeResetsEntityModifiedState()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

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

            ctxNew.As.Attach(clone.Source);

            Assert.IsTrue(a.EntityState == EntityState.Modified);
            gr.Synchronize(clone);
            Assert.IsTrue(a.EntityState == EntityState.Unmodified);
        }
        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");
        }
예제 #7
0
        public void CloneIntoPreservesAllEntityStates()
        {
            EntityGraphTestsDomainContext ctx    = new EntityGraphTestsDomainContext();
            EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext();

            ctx.As.Add(a);
            var gr     = new EntityGraph(a, new FullEntityGraphShape());
            var clone  = gr.Clone(ctxNew);
            var result =
                from source in gr
                from cloned in clone
                where source.GetType() == cloned.GetType()
                where source.EntityState == cloned.EntityState
                select cloned;

            Assert.IsTrue(result.Count() == gr.Count());
        }