Example #1
0
        public void Can_clear_modification_function_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet  = new EntitySet("S", "N", null, null, entityType);
            var function   = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());

            var container = new EntityContainer("C", DataSpace.CSpace);

            container.AddEntitySetBase(entitySet);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty <ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);

            Assert.Equal(1, entitySetMapping.ModificationFunctionMappings.Count());

            entitySetMapping.ClearModificationFunctionMappings();

            Assert.Equal(0, entitySetMapping.ModificationFunctionMappings.Count());
        }
        public void Can_clear_modification_function_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("S", "N", null, null, entityType);
            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddEntitySetBase(entitySet);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty<ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);

            Assert.Equal(1, entitySetMapping.ModificationFunctionMappings.Count());

            entitySetMapping.ClearModificationFunctionMappings();

            Assert.Equal(0, entitySetMapping.ModificationFunctionMappings.Count());
        }
        public void WriteEntitySetMappingElement_should_write_modification_function_mappings()
        {
            var fixture = new Fixture();

            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", null, null, entityType);
            var entityContainer = new EntityContainer("EC", DataSpace.SSpace);

            entityContainer.AddEntitySetBase(entitySet);

            var storageEntitySetMapping
                = new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(entityContainer));

            var storageModificationFunctionMapping
                = new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload()),
                    Enumerable.Empty<ModificationFunctionParameterBinding>(),
                    null,
                    null);

            storageEntitySetMapping.AddModificationFunctionMapping(
                new EntityTypeModificationFunctionMapping(
                    entityType,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping));

            fixture.Writer.WriteEntitySetMappingElement(storageEntitySetMapping);

            Assert.Equal(
                @"<EntitySetMapping Name=""ES"">
  <EntityTypeMapping TypeName="".E"">
    <ModificationFunctionMapping>
      <InsertFunction FunctionName=""N.F"" />
      <UpdateFunction FunctionName=""N.F"" />
      <DeleteFunction FunctionName=""N.F"" />
    </ModificationFunctionMapping>
  </EntityTypeMapping>
</EntitySetMapping>",
                fixture.ToString());
        }
Example #4
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet  = new EntitySet("S", "N", null, null, entityType);
            var function   = new EdmFunction(
                "F", "N", DataSpace.CSpace,
                new EdmFunctionPayload
            {
                IsFunctionImport = true
            });

            var container = new EntityContainer("C", DataSpace.CSpace);

            container.AddEntitySetBase(entitySet);
            container.AddFunctionImport(function);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty <ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMapping =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMapping);

            var entityTypeMapping = new EntityTypeMapping(entitySetMapping);

            entitySetMapping.AddTypeMapping(entityTypeMapping);

            Assert.False(entityTypeMapping.IsReadOnly);
            Assert.False(entityFunctionMapping.IsReadOnly);
            entitySetMapping.SetReadOnly();
            Assert.True(entityTypeMapping.IsReadOnly);
            Assert.True(entityFunctionMapping.IsReadOnly);
        }
Example #5
0
        public void Can_add_get_remove_modification_function_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet  = new EntitySet("S", "N", null, null, entityType);
            var function   = new EdmFunction(
                "F", "N", DataSpace.CSpace,
                new EdmFunctionPayload
            {
                IsFunctionImport = true
            });

            var container = new EntityContainer("C", DataSpace.CSpace);

            container.AddEntitySetBase(entitySet);
            container.AddFunctionImport(function);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty <ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);

            Assert.Same(entityFunctionMappings, entitySetMapping.ModificationFunctionMappings.Single());

            entitySetMapping.RemoveModificationFunctionMapping(entityFunctionMappings);

            Assert.Empty(entitySetMapping.ModificationFunctionMappings);
        }
Example #6
0
        public void Cannot_remove_modification_function_mapping_when_read_only()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet  = new EntitySet("S", "N", null, null, entityType);
            var function   = new EdmFunction(
                "F", "N", DataSpace.CSpace,
                new EdmFunctionPayload
            {
                IsFunctionImport = true
            });

            var container = new EntityContainer("C", DataSpace.CSpace);

            container.AddEntitySetBase(entitySet);
            container.AddFunctionImport(function);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty <ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);
            entitySetMapping.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => entitySetMapping.RemoveModificationFunctionMapping(entityFunctionMappings)).Message);
        }
        public void Can_add_get_remove_modification_function_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("S", "N", null, null, entityType);
            var function = new EdmFunction(
                "F", "N", DataSpace.CSpace,
                new EdmFunctionPayload
                    {
                        IsFunctionImport = true
                    });

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddEntitySetBase(entitySet);
            container.AddFunctionImport(function);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty<ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);

            Assert.Same(entityFunctionMappings, entitySetMapping.ModificationFunctionMappings.Single());

            entitySetMapping.RemoveModificationFunctionMapping(entityFunctionMappings);

            Assert.Empty(entitySetMapping.ModificationFunctionMappings);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("S", "N", null, null, entityType);
            var function = new EdmFunction(
                "F", "N", DataSpace.CSpace,
                new EdmFunctionPayload
                {
                    IsFunctionImport = true
                });

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddEntitySetBase(entitySet);
            container.AddFunctionImport(function);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty<ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMapping =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMapping);

            var entityTypeMapping = new EntityTypeMapping(entitySetMapping);

            entitySetMapping.AddTypeMapping(entityTypeMapping);

            Assert.False(entityTypeMapping.IsReadOnly);
            Assert.False(entityFunctionMapping.IsReadOnly);
            entitySetMapping.SetReadOnly();
            Assert.True(entityTypeMapping.IsReadOnly);
            Assert.True(entityFunctionMapping.IsReadOnly);
        }
        public void Cannot_remove_modification_function_mapping_when_read_only()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("S", "N", null, null, entityType);
            var function = new EdmFunction(
                "F", "N", DataSpace.CSpace,
                new EdmFunctionPayload
                {
                    IsFunctionImport = true
                });

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddEntitySetBase(entitySet);
            container.AddFunctionImport(function);

            var entitySetMapping =
                new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(container));

            var functionMapping =
                new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty<ModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new EntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);
            entitySetMapping.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => entitySetMapping.RemoveModificationFunctionMapping(entityFunctionMappings)).Message);
        }