public void GetAllRelationshipsForType_returns_collection_relationships_with_navigation_properties() { using (var context = new RelationshipsContext()) { var relationships = EntityProxyTypeInfo.GetAllRelationshipsForType( ((IObjectContextAdapter)context).ObjectContext.MetadataWorkspace, typeof(OneToMany)) .Select(r => r.Name); Assert.Equal("OneToMany_WithNavProps", relationships.Single()); } }
public void GetAllRelationshipsForType_returns_relationships_without_navigation_properties() { using (var context = new RelationshipsContext()) { var relationships = EntityProxyTypeInfo.GetAllRelationshipsForType( ((IObjectContextAdapter)context).ObjectContext.MetadataWorkspace, typeof(NoNavProps)) .Select(r => r.Name); Assert.Equal(2, relationships.Count()); Assert.Contains("NoNavPropsOneToOne_NoNavProps", relationships); Assert.Contains("NoNavPropsOneToMany_NoNavProps", relationships); } }
public void TryGetAssociationTypeFromProxyInfo_can_get_association_using_full_name() { using (var context = new RelationshipsContext()) { var proxy = context.WithRelationships.Create(); var mockWrapper = new Mock <IEntityWrapper>(); mockWrapper.Setup(m => m.Entity).Returns(proxy); AssociationType associationType; Assert.True(EntityProxyFactory.TryGetAssociationTypeFromProxyInfo( mockWrapper.Object, "System.Data.Entity.Core.Objects.Internal.ProxyWithRelationships_ManyToOnes", out associationType)); Assert.Equal("System.Data.Entity.Core.Objects.Internal.ProxyWithRelationships_ManyToOnes", associationType.FullName); } }
public void TryGetAssociationTypeFromProxyInfo_can_get_association_using_full_name() { using (var context = new RelationshipsContext()) { var proxy = context.WithRelationships.Create(); var mockWrapper = new Mock<IEntityWrapper>(); mockWrapper.Setup(m => m.Entity).Returns(proxy); AssociationType associationType; Assert.True(EntityProxyFactory.TryGetAssociationTypeFromProxyInfo( mockWrapper.Object, "System.Data.Entity.Core.Objects.Internal.ProxyManyToOne_WithRelationships", out associationType)); Assert.Equal("System.Data.Entity.Core.Objects.Internal.ProxyManyToOne_WithRelationships", associationType.FullName); } }
// Currently ignored as it was just a scratchpad test to prove constraint integrity is not checked (#2166 of EntityframeworkCore github) public void Scratchpad_Test() { var options = new DbContextOptionsBuilder <RelationshipsContext>().UseInMemoryDatabase().Options; var newContext = new RelationshipsContext(options); newContext.Add(new Employee { Id = 1, Name = "Adam", OfficeId = 14 }); newContext.Add(new Company { Id = 1, Name = "Earth Inc." }); newContext.SaveChanges(); Assert.IsNotNull(newContext.Employees.Find(1).Office); Assert.AreEqual(1, newContext.Employees.Find(1).Office.Id); }
public void TryGetAllAssociationTypesFromProxyInfo_returns_all_associations_with_no_duplicates() { using (var context = new RelationshipsContext()) { var proxy = context.WithRelationships.Create(); var mockWrapper = new Mock <IEntityWrapper>(); mockWrapper.Setup(m => m.Entity).Returns(proxy); var associations = EntityProxyFactory.TryGetAllAssociationTypesFromProxyInfo(mockWrapper.Object).Select(a => a.Name); Assert.Equal(3, associations.Count()); Assert.Contains("ProxyWithRelationships_OneToOne", associations); Assert.Contains("ProxyOneToMany_WithRelationships", associations); Assert.Contains("ProxyWithRelationships_ManyToOnes", associations); } }
public void TryGetAllAssociationTypesFromProxyInfo_returns_all_associations_with_no_duplicates() { using (var context = new RelationshipsContext()) { var proxy = context.WithRelationships.Create(); var mockWrapper = new Mock<IEntityWrapper>(); mockWrapper.Setup(m => m.Entity).Returns(proxy); var associations = EntityProxyFactory.TryGetAllAssociationTypesFromProxyInfo(mockWrapper.Object).Select(a => a.Name); Assert.Equal(3, associations.Count()); Assert.Contains("ProxyWithRelationships_OneToOne", associations); Assert.Contains("ProxyOneToMany_WithRelationships", associations); Assert.Contains("ProxyManyToOne_WithRelationships", associations); } }
public void SetUp() { context = new EffortContext <RelationshipsContext>("data/relationships").GetContext(); }