public void Create_should_return_only_fk_associations() { var filter = new ViewgenContext.OneToOneFkAssociationsForEntitiesFilter(); var associationType1 = new AssociationType("A1", EdmConstants.TransientNamespace, true, DataSpace.CSpace); var entityType = new EntityType(); associationType1.AddMember( new AssociationEndMember("S", entityType) { RelationshipMultiplicity = RelationshipMultiplicity.One }); associationType1.AddMember( new AssociationEndMember("T", entityType) { RelationshipMultiplicity = RelationshipMultiplicity.One }); associationType1.SetReadOnly(); var associationSet1 = new AssociationSet("AS1", associationType1); var associationType2 = new AssociationType("A2", EdmConstants.TransientNamespace, false, DataSpace.CSpace); associationType2.AddMember( new AssociationEndMember("S", entityType) { RelationshipMultiplicity = RelationshipMultiplicity.One }); associationType2.AddMember( new AssociationEndMember("T", entityType) { RelationshipMultiplicity = RelationshipMultiplicity.One }); associationType2.SetReadOnly(); var associationSet2 = new AssociationSet("AS2", associationType2); var query = filter.Filter( new[] { entityType }, new[] { associationSet1, associationSet2 }); Assert.Same(associationSet1, query.Single()); }
public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_associations() { var metadataWorkspaceMock = new Mock <MetadataWorkspace>(); metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create()); var codeFirstOSpaceTypeFactory = new CodeFirstOSpaceTypeFactory(); var refEntityColumnMap = (EntityColumnMap)BuildSimpleEntitySetColumnMap(metadataWorkspaceMock, codeFirstOSpaceTypeFactory).Element; var cSpaceEntityType = new EntityType(typeof(RefEntity).Name, "N", DataSpace.CSpace); cSpaceEntityType.AddMember(new EdmProperty("Id", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)))); var navigationProperty = new NavigationProperty("SimpleEntity", TypeUsage.Create(refEntityColumnMap.Type.EdmType)); var associationType = new AssociationType("A", "N", false, DataSpace.CSpace); associationType.AddMember( new AssociationEndMember("From", new RefType(cSpaceEntityType), RelationshipMultiplicity.One)); associationType.AddMember( new AssociationEndMember("To", new RefType((EntityType)navigationProperty.TypeUsage.EdmType), RelationshipMultiplicity.One)); associationType.SetReadOnly(); navigationProperty.RelationshipType = associationType; navigationProperty.FromEndMember = associationType.RelationshipEndMembers[0]; navigationProperty.ToEndMember = associationType.RelationshipEndMembers[1]; cSpaceEntityType.AddMember(navigationProperty); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); var oSpaceEntityType = codeFirstOSpaceTypeFactory.TryCreateType(typeof(RefEntity), cSpaceEntityType); codeFirstOSpaceTypeFactory.CspaceToOspace.Add(cSpaceEntityType, oSpaceEntityType); var associations = new EdmItemCollection(); associations.AddInternal(associationType); codeFirstOSpaceTypeFactory.CreateRelationships(associations); foreach (var resolve in codeFirstOSpaceTypeFactory.ReferenceResolutions) { resolve(); } var idScalarMap = new ScalarColumnMap(TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), "Id", 0, 1); var refColumnMap = new RefColumnMap( associationType.RelationshipEndMembers[1].TypeUsage, "E", new SimpleEntityIdentity(null, new SimpleColumnMap[] { idScalarMap })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", refColumnMap, null, null); metadataWorkspaceMock.Setup(m => m.GetItem <EdmType>("N.RefEntity", DataSpace.OSpace)) .Returns(oSpaceEntityType); var factory = new Translator().TranslateColumnMap <object>( collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false); Assert.NotNull(factory); Assert.Equal(new[] { null, typeof(int) }, factory.ColumnTypes); Assert.Equal(new[] { false, true }, factory.NullableColumns); }