public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.PropertyMappings);

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.PropertyMappings.Single());

            mappingFragment.RemovePropertyMapping(scalarPropertyMapping);

            Assert.Empty(mappingFragment.PropertyMappings);
        }
        public void Cannot_add_property_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            mappingFragment.SetReadOnly();

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => mappingFragment.AddPropertyMapping(scalarPropertyMapping)).Message);
        }
Ejemplo n.º 3
0
        public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.PropertyMappings);

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.PropertyMappings.Single());

            mappingFragment.RemovePropertyMapping(scalarPropertyMapping);

            Assert.Empty(mappingFragment.PropertyMappings);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);
            mappingFragment.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            mappingFragment.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
Ejemplo n.º 5
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);
            mappingFragment.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            mappingFragment.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
Ejemplo n.º 6
0
        public void Cannot_remove_property_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            mappingFragment.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => mappingFragment.RemovePropertyMapping(scalarPropertyMapping)).Message);
        }