public void Cannot_set__modification_function_mapping_when_read_only()
        {
            var entitySet      = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));
            var associationSetMapping
                = new AssociationSetMapping(associationSet, entitySet);
            var modificationFunctionMapping = new AssociationSetModificationFunctionMapping(associationSet, null, null);

            associationSetMapping.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => (associationSetMapping.ModificationFunctionMapping = modificationFunctionMapping)).Message);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var entityType                  = new EntityType("ET", "N", DataSpace.SSpace);
            var entitySet                   = new EntitySet("ES", "S", "T", "Q", entityType);
            var associationSet              = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));
            var associationSetMapping       = new AssociationSetMapping(associationSet, entitySet, null);
            var modificationFunctionMapping = new AssociationSetModificationFunctionMapping(associationSet, null, null);

            associationSetMapping.ModificationFunctionMapping = modificationFunctionMapping;

            Assert.False(associationSetMapping.AssociationTypeMapping.IsReadOnly);
            Assert.False(modificationFunctionMapping.IsReadOnly);
            associationSetMapping.SetReadOnly();
            Assert.True(associationSetMapping.AssociationTypeMapping.IsReadOnly);
            Assert.True(modificationFunctionMapping.IsReadOnly);
        }
        public void Can_retrieve_properties_and_set_read_only()
        {
            var associationType = new AssociationType("A", "N", false, DataSpace.CSpace);
            var associationSet  = new AssociationSet("AS", associationType);

            associationSet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace));

            var deleteModificationFunctionMapping
                = new ModificationFunctionMapping(
                      associationSet,
                      new EntityType("E", "N", DataSpace.CSpace),
                      new EdmFunction("F", "N", DataSpace.SSpace),
                      new[]
            {
                new ModificationFunctionParameterBinding(
                    new FunctionParameter(),
                    new ModificationFunctionMemberPath(
                        new EdmMember[]
                {
                    new EdmProperty("M")
                },
                        null),
                    false)
            },
                      null,
                      null);

            var insertModificationFunctionMapping
                = new ModificationFunctionMapping(
                      associationSet,
                      new EntityType("E", "N", DataSpace.CSpace),
                      new EdmFunction("F", "N", DataSpace.SSpace),
                      new[]
            {
                new ModificationFunctionParameterBinding(
                    new FunctionParameter(),
                    new ModificationFunctionMemberPath(
                        new EdmMember[]
                {
                    new EdmProperty("M")
                },
                        null),
                    false)
            },
                      null,
                      null);


            var associationSetModificationFunctionMapping
                = new AssociationSetModificationFunctionMapping(
                      associationSet,
                      deleteModificationFunctionMapping,
                      insertModificationFunctionMapping);

            Assert.Same(associationSetModificationFunctionMapping.AssociationSet, associationSet);
            Assert.Same(associationSetModificationFunctionMapping.DeleteFunctionMapping, deleteModificationFunctionMapping);
            Assert.Same(associationSetModificationFunctionMapping.InsertFunctionMapping, insertModificationFunctionMapping);

            Assert.False(associationSetModificationFunctionMapping.IsReadOnly);
            Assert.False(deleteModificationFunctionMapping.IsReadOnly);
            Assert.False(insertModificationFunctionMapping.IsReadOnly);

            associationSetModificationFunctionMapping.SetReadOnly();

            Assert.True(associationSetModificationFunctionMapping.IsReadOnly);
            Assert.True(deleteModificationFunctionMapping.IsReadOnly);
            Assert.True(insertModificationFunctionMapping.IsReadOnly);
        }
        private void WriteModificationFunctionMapping(AssociationSetModificationFunctionMapping modificationFunctionMapping)
        {
            DebugCheck.NotNull(modificationFunctionMapping);

            _xmlWriter.WriteStartElement(MslConstructs.ModificationFunctionMappingElement);

            WriteFunctionMapping(
                MslConstructs.InsertFunctionElement,
                modificationFunctionMapping.InsertFunctionMapping,
                associationSetMapping: true);

            WriteFunctionMapping(
                MslConstructs.DeleteFunctionElement,
                modificationFunctionMapping.DeleteFunctionMapping,
                associationSetMapping: true);

            _xmlWriter.WriteEndElement();
        }
        public void Can_retrieve_properties_and_set_read_only()
        {
            var associationType = new AssociationType("A", "N", false, DataSpace.CSpace);
            var associationSet = new AssociationSet("AS", associationType);

            associationSet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace));

            var deleteModificationFunctionMapping
                = new ModificationFunctionMapping(
                    associationSet,
                    new EntityType("E", "N", DataSpace.CSpace),
                    new EdmFunction("F", "N", DataSpace.SSpace),
                    new[]
                        {
                            new ModificationFunctionParameterBinding(
                                new FunctionParameter(),
                                new ModificationFunctionMemberPath(
                                new EdmMember[]
                                    {
                                        new EdmProperty("M")
                                    },
                                null),
                                false)
                        },
                    null,
                    null);

            var insertModificationFunctionMapping
                = new ModificationFunctionMapping(
                    associationSet,
                    new EntityType("E", "N", DataSpace.CSpace),
                    new EdmFunction("F", "N", DataSpace.SSpace),
                    new[]
                        {
                            new ModificationFunctionParameterBinding(
                                new FunctionParameter(),
                                new ModificationFunctionMemberPath(
                                new EdmMember[]
                                    {
                                        new EdmProperty("M")
                                    },
                                null),
                                false)
                        },
                    null,
                    null);


            var associationSetModificationFunctionMapping
                = new AssociationSetModificationFunctionMapping(
                    associationSet,
                    deleteModificationFunctionMapping,
                    insertModificationFunctionMapping);

            Assert.Same(associationSetModificationFunctionMapping.AssociationSet, associationSet);
            Assert.Same(associationSetModificationFunctionMapping.DeleteFunctionMapping, deleteModificationFunctionMapping);
            Assert.Same(associationSetModificationFunctionMapping.InsertFunctionMapping, insertModificationFunctionMapping);

            Assert.False(associationSetModificationFunctionMapping.IsReadOnly);
            Assert.False(deleteModificationFunctionMapping.IsReadOnly);
            Assert.False(insertModificationFunctionMapping.IsReadOnly);

            associationSetModificationFunctionMapping.SetReadOnly();

            Assert.True(associationSetModificationFunctionMapping.IsReadOnly);
            Assert.True(deleteModificationFunctionMapping.IsReadOnly);
            Assert.True(insertModificationFunctionMapping.IsReadOnly);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var entityType = new EntityType("ET", "N", DataSpace.SSpace);
            var entitySet = new EntitySet("ES", "S", "T", "Q", entityType);
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));
            var associationSetMapping = new AssociationSetMapping(associationSet, entitySet, null);
            var modificationFunctionMapping = new AssociationSetModificationFunctionMapping(associationSet, null, null);

            associationSetMapping.ModificationFunctionMapping = modificationFunctionMapping;

            Assert.False(associationSetMapping.AssociationTypeMapping.IsReadOnly);
            Assert.False(modificationFunctionMapping.IsReadOnly);
            associationSetMapping.SetReadOnly();
            Assert.True(associationSetMapping.AssociationTypeMapping.IsReadOnly);
            Assert.True(modificationFunctionMapping.IsReadOnly);
        }
        public void Cannot_set__modification_function_mapping_when_read_only()
        {
            var entitySet = new EntitySet();
            var associationSet = new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));
            var associationSetMapping
                = new AssociationSetMapping(associationSet, entitySet);
            var modificationFunctionMapping = new AssociationSetModificationFunctionMapping(associationSet, null, null);

            associationSetMapping.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => (associationSetMapping.ModificationFunctionMapping = modificationFunctionMapping)).Message);
        }
        public void Configure(
            AssociationSetModificationFunctionMapping modificationStoredProcedureMapping,
            DbProviderManifest providerManifest)
        {
            DebugCheck.NotNull(modificationStoredProcedureMapping);
            DebugCheck.NotNull(providerManifest);

            if (_insertModificationStoredProcedureConfiguration != null)
            {
                _insertModificationStoredProcedureConfiguration
                    .Configure(modificationStoredProcedureMapping.InsertFunctionMapping, providerManifest);
            }

            if (_deleteModificationStoredProcedureConfiguration != null)
            {
                _deleteModificationStoredProcedureConfiguration
                    .Configure(modificationStoredProcedureMapping.DeleteFunctionMapping, providerManifest);
            }
        }