public void Deleting_object_when_relationships_have_not_been_all_enumerated_should_not_cause_collection_modified_exception_71937() { try { ProviderAgnosticConfiguration.SuspendExecutionStrategy = true; using (var context = new GranniesContext()) { using (context.Database.BeginTransaction()) { var g = context.Grannys.Add(context.Grannys.Create()); var c = context.Children.Add(context.Children.Create()); c.Name = "Child"; var h = context.Houses.Add(context.Houses.Create()); g.Children.Add(c); g.House = h; context.SaveChanges(); context.Children.Remove(c); // This would previously throw Assert.Equal(EntityState.Deleted, context.Entry(c).State); Assert.Equal(EntityState.Unchanged, context.Entry(g).State); Assert.Equal(EntityState.Unchanged, context.Entry(h).State); Assert.Null(c.House); Assert.Null(c.Granny); Assert.Equal(0, g.Children.Count); Assert.Same(h, g.House); Assert.Equal(0, h.Children.Count); Assert.Same(g, h.Granny); context.SaveChanges(); Assert.Equal(EntityState.Detached, context.Entry(c).State); Assert.Equal(EntityState.Unchanged, context.Entry(g).State); Assert.Equal(EntityState.Unchanged, context.Entry(h).State); Assert.Null(c.House); Assert.Null(c.Granny); Assert.Equal(0, g.Children.Count); Assert.Same(h, g.House); Assert.Equal(0, h.Children.Count); Assert.Same(g, h.Granny); } } } finally { ProviderAgnosticConfiguration.SuspendExecutionStrategy = false; } }
public void SetChangeTracker_can_be_called_by_casting_proxy_entity_to_IEntityWithChangeTracker() { using (var context = new GranniesContext()) { var granny = context.Grannys.Create(); context.Grannys.Attach(granny); ((IEntityWithChangeTracker)granny).SetChangeTracker(null); } }
public void RelationshipManager_can_be_accessed_by_casting_proxy_entity_to_IEntityWithRelationships() { using (var context = new GranniesContext()) { var granny = context.Grannys.Create(); context.Grannys.Attach(granny); var relationshipManager = ((IEntityWithRelationships)granny).RelationshipManager; Assert.NotNull(relationshipManager); } }
public ChangeTrackingProxyTests() { using (var context = new GranniesContext()) { context.Database.Initialize(force: false); } using (var context = new HaveToDoContext()) { context.Database.Initialize(force: false); } }
public ChangeTrackingProxyTests() { using (var context = new GranniesContext()) { context.Database.Initialize(force: false); } using (var context = new HaveToDoContext()) { _isSqlAzure = DatabaseTestHelpers.IsSqlAzure(context.Database.Connection.ConnectionString); if (!_isSqlAzure) { context.Database.Initialize(force: false); } } }
public void Deleting_object_when_relationships_have_not_been_all_enumerated_should_not_cause_collection_modified_exception_71937() { using (var context = new GranniesContext()) { var g = context.Grannys.Add(context.Grannys.Create()); var c = context.Children.Add(context.Children.Create()); c.Name = "Child"; var h = context.Houses.Add(context.Houses.Create()); g.Children.Add(c); g.House = h; context.SaveChanges(); context.Children.Remove(c); // This would previously throw Assert.Equal(EntityState.Deleted, context.Entry(c).State); Assert.Equal(EntityState.Unchanged, context.Entry(g).State); Assert.Equal(EntityState.Unchanged, context.Entry(h).State); Assert.Null(c.House); Assert.Null(c.Granny); Assert.Equal(0, g.Children.Count); Assert.Same(h, g.House); Assert.Equal(0, h.Children.Count); Assert.Same(g, h.Granny); context.SaveChanges(); Assert.Equal(EntityState.Detached, context.Entry(c).State); Assert.Equal(EntityState.Unchanged, context.Entry(g).State); Assert.Equal(EntityState.Unchanged, context.Entry(h).State); Assert.Null(c.House); Assert.Null(c.Granny); Assert.Equal(0, g.Children.Count); Assert.Same(h, g.House); Assert.Equal(0, h.Children.Count); Assert.Same(g, h.Granny); } }
[Fact] // CodePlex #2435 public void IsPropertyChanged_returns_modified_status_for_change_tracking_entities() { using (var context = new GranniesContext()) { var objectContext = ((IObjectContextAdapter)context).ObjectContext; var objectSet = objectContext.CreateObjectSet <Child>(); var entity = objectSet.CreateObject(); objectSet.Attach(entity); var entry = objectContext.ObjectStateManager.GetObjectStateEntry(entity); Assert.False(entry.IsPropertyChanged("Name")); entity.Name = "Nolan Sorrento"; Assert.True(entry.IsPropertyChanged("Name")); } }
public void SetChangeTracker_can_be_called_by_casting_proxy_entity_to_IEntityWithChangeTracker() { try { ProviderAgnosticConfiguration.SuspendExecutionStrategy = true; using (var context = new GranniesContext()) { using (context.Database.BeginTransaction()) { var granny = context.Grannys.Create(); context.Grannys.Attach(granny); ((IEntityWithChangeTracker)granny).SetChangeTracker(null); } } } finally { ProviderAgnosticConfiguration.SuspendExecutionStrategy = false; } }
public void RelationshipManager_can_be_accessed_by_casting_proxy_entity_to_IEntityWithRelationships() { try { ProviderAgnosticConfiguration.SuspendExecutionStrategy = true; using (var context = new GranniesContext()) { using (context.Database.BeginTransaction()) { var granny = context.Grannys.Create(); context.Grannys.Attach(granny); var relationshipManager = ((IEntityWithRelationships)granny).RelationshipManager; Assert.NotNull(relationshipManager); } } } finally { ProviderAgnosticConfiguration.SuspendExecutionStrategy = false; } }