示例#1
0
        public void CreateStoreModel_sets_container()
        {
            var container = new EntityContainer("MyContainer", DataSpace.SSpace);

            var model = EdmModel.CreateStoreModel(container, null, null);

            Assert.Same(container, model.Containers.Single());
            Assert.Null(model.ProviderManifest);
            Assert.Null(model.ProviderInfo);
        }
示例#2
0
        public void CreateStoreModel_creates_model_with_SSpace()
        {
            var providerInfo     = ProviderRegistry.Sql2008_ProviderInfo;
            var providerManifest = ProviderRegistry.Sql2008_ProviderManifest;
            var model            = EdmModel.CreateStoreModel(providerInfo, providerManifest);

            Assert.Equal(DataSpace.SSpace, model.DataSpace);
            Assert.Same(providerInfo, model.ProviderInfo);
            Assert.Same(providerManifest, model.ProviderManifest);
        }
示例#3
0
        public void CreateStoreModel_sets_provider_info_and_manifest()
        {
            var container        = new EntityContainer("MyContainer", DataSpace.SSpace);
            var providerInfo     = ProviderRegistry.Sql2008_ProviderInfo;
            var providerManifest = ProviderRegistry.Sql2008_ProviderManifest;

            var model = EdmModel.CreateStoreModel(container, providerInfo, providerManifest);

            Assert.Same(container, model.Containers.Single());
            Assert.Same(providerInfo, model.ProviderInfo);
            Assert.Same(providerManifest, model.ProviderManifest);
        }
        public void Can_initialize_and_provider_fields_set()
        {
            var model = EdmModel.CreateStoreModel(
                ProviderRegistry.Sql2008_ProviderInfo,
                new SqlProviderManifest("2008"));

            var itemCollection = new StoreItemCollection(model);

            Assert.Same(model.ProviderInfo.ProviderManifestToken, itemCollection.ProviderManifestToken);
            Assert.NotNull(itemCollection.ProviderFactory);
            Assert.Same(model.ProviderManifest, itemCollection.ProviderManifest);
            Assert.Same(model.ProviderInfo.ProviderInvariantName, itemCollection.ProviderInvariantName);
        }
        public void Visit_should_not_write_store_schema_generator_namespace_on_Schema_if_entity_sets_do_not_use_it()
        {
            var entityType = new EntityType("MyEntity", "Model", DataSpace.SSpace);
            var entitySet  = new EntitySet("Entities", null, "Entities", null, entityType);
            var container  = new EntityContainer("Container.Store", DataSpace.SSpace);

            container.AddEntitySetBase(entitySet);
            var model = EdmModel.CreateStoreModel(container, null, null);

            var schemaWriterMock = new Mock <EdmXmlSchemaWriter>();

            new EdmSerializationVisitor(schemaWriterMock.Object).Visit(model, "fakeProvider", "42");

            schemaWriterMock.Verify(sw => sw.WriteSchemaElementHeader(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), true), Times.Never());
            schemaWriterMock.Verify(sw => sw.WriteSchemaElementHeader(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), false), Times.Once());
        }
示例#6
0
        public void WriteFunctionImportMappingElement_writes_result_mapping_for_non_composable_functions_mapped_explicitly_to_EntityType()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var entityTypeProperty1 = new EdmProperty("ETProperty1", typeUsage);
            var entityTypeProperty2 = new EdmProperty("ETProperty2", typeUsage);

            var entityType = new EntityType("ET", "Ns", DataSpace.CSpace);

            entityType.AddMember(entityTypeProperty1);
            entityType.AddMember(entityTypeProperty2);

            var functionImport =
                new EdmFunction(
                    "f_c", "Ns", DataSpace.CSpace,
                    new EdmFunctionPayload
            {
                IsComposable     = false,
                IsFunctionImport = true,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "ReturnValue",
                        TypeUsage.CreateDefaultTypeUsage(entityType.GetCollectionType()),
                        ParameterMode.ReturnValue)
                },
            });

            typeUsage = ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(typeUsage);
            var rowTypeProperty1 = new EdmProperty("RTProperty1", typeUsage);
            var rowTypeProperty2 = new EdmProperty("RTProperty2", typeUsage);
            var rowType          = new RowType(new[] { rowTypeProperty1, rowTypeProperty2 });

            var storeFunction =
                new EdmFunction(
                    "f_s", "Ns.Store", DataSpace.SSpace,
                    new EdmFunctionPayload
            {
                IsComposable     = false,
                ReturnParameters =
                    new[]
                {
                    new FunctionParameter(
                        "Return",
                        TypeUsage.CreateDefaultTypeUsage(rowType),
                        ParameterMode.ReturnValue)
                },
            });

            var functionImportResultMapping = new FunctionImportResultMapping();

            functionImportResultMapping.AddTypeMapping(
                new FunctionImportEntityTypeMapping(
                    new EntityType[0],
                    new [] { entityType },
                    new Collections.ObjectModel.Collection <FunctionImportReturnTypePropertyMapping>()
            {
                new FunctionImportReturnTypeScalarPropertyMapping("ETProperty1", "RTProperty1"),
                new FunctionImportReturnTypeScalarPropertyMapping("ETProperty2", "RTProperty2")
            },
                    new FunctionImportEntityTypeMappingCondition[]
            {
                new FunctionImportEntityTypeMappingConditionIsNull("RTProperty1", false),
                new FunctionImportEntityTypeMappingConditionValue("RTProperty2", 4),
                new FunctionImportEntityTypeMappingConditionValue("FakeCondition", true)
            }
                    ));

            var mappingItemCollection =
                new StorageMappingItemCollection(
                    new EdmItemCollection(EdmModel.CreateConceptualModel()),
                    new StoreItemCollection(
                        EdmModel.CreateStoreModel(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest)),
                    new string[0]);

            var containerMapping =
                new EntityContainerMapping(
                    new EntityContainer("C", DataSpace.CSpace), new EntityContainer("S", DataSpace.SSpace), mappingItemCollection, false);

            var functionImportMapping =
                new FunctionImportMappingNonComposable(
                    functionImport,
                    storeFunction,
                    new []
            {
                functionImportResultMapping
            },
                    containerMapping);

            containerMapping.AddFunctionImportMapping(functionImportMapping);

            var fixture = new Fixture();

            fixture.Writer.WriteFunctionImportMappingElement(functionImportMapping);
            Assert.Equal(
                @"<FunctionImportMapping FunctionName=""Ns.Store.f_s"" FunctionImportName=""f_c"">
  <ResultMapping>
    <EntityTypeMapping TypeName=""Ns.ET"">
      <ScalarProperty Name=""ETProperty1"" ColumnName=""RTProperty1"" />
      <ScalarProperty Name=""ETProperty2"" ColumnName=""RTProperty2"" />
      <Condition ColumnName=""RTProperty1"" IsNull=""false"" />
      <Condition ColumnName=""RTProperty2"" Value=""4"" />
      <Condition ColumnName=""FakeCondition"" Value=""1"" />
    </EntityTypeMapping>
  </ResultMapping>
</FunctionImportMapping>",
                fixture.ToString());
        }