public void ChangeSetTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { B existingB = ctx.Bs.Single(); a.BSet.Add(existingB); existingB.name = "Hello"; B newB = new B(); a.BSet.Add(newB); ctx.As.Add(a); var changeSet = a.EntityGraph(EntityGraphs.CircularGraphFull).GetChanges(); Assert.IsTrue(changeSet.ModifiedEntities.Contains(existingB), "ChangeSet.ModifiedEntities should contain b"); Assert.AreEqual(5, changeSet.AddedEntities.Count(), "Incorrect number of added entities"); Assert.IsTrue(changeSet.AddedEntities.Contains(b), "ChangeSet.AddedEntities shoudl contain b"); Assert.IsTrue(changeSet.AddedEntities.Contains(newB), "ChangeSet.AddedEntities shoudl contain newB"); Assert.IsTrue(changeSet.RemovedEntities.Count() == 0, "ChangeSet.RemovedEntities should be 0"); } ); EnqueueTestComplete(); }
public void IEditableObjectAssociationTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { ctx.As.Add(a); B existingB = loadOp.Entities.SingleOrDefault(); B newB = new B { Id = -1 }; var gr = a.EntityGraph(EntityGraphs.CircularGraphFull); a.B = existingB; gr.BeginEdit(); a.B = newB; gr.CancelEdit(); Assert.IsTrue(a.BId == existingB.Id); // Succeeds Assert.IsTrue(a.B == existingB); // Succeeds a.B = newB; gr.BeginEdit(); a.B = existingB; gr.CancelEdit(); // Here we have a bug in IEditableObject (http://forums.silverlight.net/forums/p/204333/478308.aspx#478308) Assert.IsTrue(a.BId == newB.Id); // Succeeds Assert.IsTrue(a.B != newB); // Potential DomainServices.Client bug, (should be equal to newB) Assert.IsTrue(a.B == null); // Potential DomainServices.Client bug, (should be equal to newB) }); EnqueueTestComplete(); }
public void IEditableObjectAssociationSetTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { B existingB = loadOp.Entities.SingleOrDefault(); B b = new B(); var gr = a.EntityGraph(EntityGraphs.CircularGraphFull); gr.BeginEdit(); // Adding a new entity (b) will fail, because this will not correctly raise the proper // collection changed events when CancelEdit is called. (http://forums.silverlight.net/forums/p/204333/478862.aspx#478862) // // Adding to a.BSet directly does change existingB.AId prior to the invocation // of existingB.BeginEdit(). Consequently, existingB.CancelEdit() will not restore existingB.AId. // Calling Add on the entity graph calls existingB.BEginEdit() prior to adding // existingB to a.BSet. ((IEditableObject)existingB).BeginEdit(); a.BSet.Add(existingB); Assert.IsTrue(a.BSet.Count() == 1, "a.BSet has incorrect number of elements"); gr.CancelEdit(); Assert.IsTrue(a.BSet.Count() == 0, "a.BSet has incorrect number of elements"); }); EnqueueTestComplete(); }
public void DetachWithNonIncludedExistingEntityTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphFull); B existingB = ctx.Bs.Single(); ctx.As.Add(a); a.BNotInGraph = existingB; Assert.IsTrue(a.EntityState == EntityState.New); Assert.IsTrue(a.BNotInGraph.EntityState == EntityState.Unmodified); Assert.IsTrue(a.BNotInGraphId == existingB.Id); gr.DetachEntityGraph(ctx.As); Assert.IsTrue(a.EntityState == EntityState.Detached); Assert.IsTrue(a.BNotInGraph.EntityState == EntityState.Unmodified); Assert.IsTrue(a.BNotInGraphId == existingB.Id); }); EnqueueTestComplete(); }
public void CopyIsDetachedFromContextTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { B b = loadOp.Entities.SingleOrDefault(); Assert.IsFalse(ctx.HasChanges); var copy = b.Copy(new RiaServicesContrib.EntityGraphShape().Edge <B, A>(B => B.A).Edge <B, C>(B => B.C)); Assert.IsFalse(ctx.HasChanges); }); EnqueueTestComplete(); }
public void CloneIntoPreservesPrimaryKeyTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { EntityGraphTestsDomainContext ctxNew = new EntityGraphTestsDomainContext(); B existingB = loadOp.Entities.SingleOrDefault(); var gr = existingB.EntityGraph(new FullEntityGraphShape()); var clone = gr.Clone(ctxNew); Assert.IsTrue(((B)clone.Source).Id == existingB.Id); }); EnqueueTestComplete(); }
public void INotifyCollectionChangedUpdatesHasChangesTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { var gr = a.EntityGraph(EntityGraphs.CircularGraphFull); Assert.IsFalse(gr.HasChanges); B existingB = loadOp.Entities.SingleOrDefault(); a.BSet.Add(existingB); Assert.IsTrue(gr.HasChanges); }); EnqueueTestComplete(); }
public void INotifyPropertyChangeUpdatesHasChangesTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { B existingB = loadOp.Entities.SingleOrDefault(); var gr = existingB.EntityGraph(EntityGraphs.CircularGraphFull); Assert.IsFalse(gr.HasChanges); ((IEditableObject)existingB).BeginEdit(); existingB.name = "Some Name"; Assert.IsTrue(gr.HasChanges); ((IEditableObject)existingB).CancelEdit(); Assert.IsFalse(gr.HasChanges); }); EnqueueTestComplete(); }
public void RemoveTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { EntityGraph gr = a.EntityGraph(EntityGraphs.CircularGraphFull); B existingB = ctx.Bs.Single(); ctx.As.Add(a); a.BSet.Add(new B()); a.BSet.Add(existingB); gr.RemoveEntityGraph(ctx.As); var changeSet = ctx.EntityContainer.GetChanges(); Assert.IsTrue(changeSet.AddedEntities.Count() == 0, "Added entities should be zero"); Assert.IsTrue(changeSet.RemovedEntities.Count() == 2, "Removed entities should be 2"); }); EnqueueTestComplete(); }
public void EntityCollectionWithExistingEntityTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { A a = new A(); B b = loadOp.Entities.SingleOrDefault(); b.ASet.Add(a); Assert.IsTrue(a.B == b); Assert.IsTrue(b.ASet.Count() == 1); Assert.IsTrue(b.ASet.SingleOrDefault() == a); a.BId = null; Assert.IsTrue(a.B == null); Assert.IsTrue(b.ASet.Count() == 0); Assert.IsTrue(b.ASet.SingleOrDefault() == null); }); EnqueueTestComplete(); }
public void IEditableObjectAssociationSetAndRemoveTest() { EntityGraphTestsDomainContext ctx = new EntityGraphTestsDomainContext(); LoadOperation <B> loadOp = ctx.Load(ctx.GetBSetQuery()); EnqueueConditional(() => loadOp.IsComplete); EnqueueCallback( () => { B existingB = loadOp.Entities.SingleOrDefault(); B b = new B(); var gr = a.EntityGraph(EntityGraphs.CircularGraphFull); gr.BeginEdit(); ((IEditableObject)b).BeginEdit(); a.BSet.Add(b); a.BSet.Remove(b); Assert.IsTrue(a.BSet.Count() == 0, "a.BSet has incorrect number of elements"); gr.CancelEdit(); Assert.IsTrue(a.BSet.Count() == 0, "a.BSet has incorrect number of elements"); }); EnqueueTestComplete(); }