예제 #1
0
        public void Create_throws_if_name_is_null_or_empty()
        {
            var stringTypeUsage = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var metadataProperty = new MetadataProperty("MetadataProperty", stringTypeUsage, "Value");

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"), 
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(null, (sbyte)5, new [] { metadataProperty }))
                    .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(String.Empty, (sbyte)5, null))
                    .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(null, (byte)5, null))
                    .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(String.Empty, (byte)5, new[] { metadataProperty }))
                    .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(null, (short)5, null))
                    .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(String.Empty, (short)5, null))
                    .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(null, (int)5, null))
                    .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(String.Empty, (int)5, new[] { metadataProperty }))
                    .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(null, (long)5, null))
                    .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(
                    () => EnumMember.Create(String.Empty, (long)5, null))
                    .Message);
        }
        /// <summary>
        /// Adds or updates an annotation with the specified name and value.
        /// </summary>
        /// <remarks>
        /// If an annotation with the given name already exists then the value of that annotation
        /// is updated to the given value. If the given value is null then the annotation will be
        /// removed.
        /// </remarks>
        /// <param name="name">The name of the annotation property.</param>
        /// <param name="value">The value of the annotation property.</param>
        public void AddAnnotation(string name, object value)
        {
            Check.NotEmpty(name, nameof(name));
            MetadataProperty metadataProperty = this.Annotations.FirstOrDefault <MetadataProperty>((Func <MetadataProperty, bool>)(a => a.Name == name));

            if (metadataProperty != null)
            {
                if (value == null)
                {
                    this.RemoveAnnotation(name);
                }
                else
                {
                    metadataProperty.Value = value;
                }
            }
            else
            {
                if (value == null)
                {
                    return;
                }
                this.GetMetadataProperties().Add(MetadataProperty.CreateAnnotation(name, value));
            }
        }
예제 #3
0
        public void Create_throws_if_name_is_null_or_empty()
        {
            var stringTypeUsage  = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var metadataProperty = new MetadataProperty("MetadataProperty", stringTypeUsage, "Value");

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(null, (sbyte)5, new [] { metadataProperty }))
                .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(String.Empty, (sbyte)5, null))
                .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(null, (byte)5, null))
                .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(String.Empty, (byte)5, new[] { metadataProperty }))
                .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(null, (short)5, null))
                .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(String.Empty, (short)5, null))
                .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(null, (int)5, null))
                .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(String.Empty, (int)5, new[] { metadataProperty }))
                .Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(null, (long)5, null))
                .Message);
            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws <ArgumentException>(
                    () => EnumMember.Create(String.Empty, (long)5, null))
                .Message);
        }
        public void Create_throws_argument_exception_when_called_with_invalid_arguments()
        {
            var entityType = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var refType = new RefType(entityType);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            Assert.Throws<ArgumentException>(
                () => AssociationEndMember.Create(
                    null,
                    refType,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty }));

            Assert.Throws<ArgumentException>(
                () => AssociationEndMember.Create(
                    String.Empty,
                    refType,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty }));

            Assert.Throws<ArgumentNullException>(
                () => AssociationEndMember.Create(
                    "AssociationEndMember",
                    null,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty }));
        }
        public void Create_throws_argument_exception_when_called_with_invalid_arguments()
        {
            var entityType       = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var refType          = new RefType(entityType);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            Assert.Throws <ArgumentException>(
                () => AssociationEndMember.Create(
                    null,
                    refType,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty }));

            Assert.Throws <ArgumentException>(
                () => AssociationEndMember.Create(
                    String.Empty,
                    refType,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty }));

            Assert.Throws <ArgumentNullException>(
                () => AssociationEndMember.Create(
                    "AssociationEndMember",
                    null,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty }));
        }
        public void Create_throws_argument_exception_when_called_with_null_or_empty_arguments()
        {
            var source     = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target     = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd  = new AssociationEndMember("SourceEnd", source);
            var targetEnd  = new AssociationEndMember("TargetEnd", target);
            var constraint =
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var associationType =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    Enumerable.Empty <MetadataProperty>());
            var sourceSet        = new EntitySet("SourceSet", "Schema", "Table", "Query", source);
            var targetSet        = new EntitySet("TargetSet", "Schema", "Table", "Query", target);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            // name is null
            Assert.Throws <ArgumentException>(
                () => AssociationSet.Create(
                    null,
                    associationType,
                    sourceSet,
                    targetSet,
                    new [] { metadataProperty }));

            // name is empty
            Assert.Throws <ArgumentException>(
                () => AssociationSet.Create(
                    String.Empty,
                    associationType,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty }));

            // type is null
            Assert.Throws <ArgumentNullException>(
                () => AssociationSet.Create(
                    "AssociationSet",
                    null,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty }));
        }
예제 #7
0
        /// <summary>
        ///     The factory method for constructing the MetadataProperty object.
        /// </summary>
        /// <param name="name">The name of the metadata property.</param>
        /// <param name="typeUsage">The type usage of the metadata property.</param>
        /// <param name="value">The value of the metadata property.</param>
        /// <exception cref="System.NullReferenceException">
        ///     Thrown <paramref name="typeUsage" /> is <c>null</c>.
        /// </exception>
        /// <notes>The newly created MetadataProperty will be read only.</notes>
        public static MetadataProperty Create(string name, TypeUsage typeUsage, object value)
        {
            Check.NotNull(typeUsage, "typeUsage");

            var metadataProperty = new MetadataProperty(name, typeUsage, value);

            metadataProperty.SetReadOnly();
            return(metadataProperty);
        }
        public void Can_get_and_set_value_property()
        {
            var metadataProperty
                = new MetadataProperty
                      {
                          Value = "Foo"
                      };

            Assert.Equal("Foo", metadataProperty.Value);
        }
예제 #9
0
        public void Create_sets_properties_and_seals_MetadataProperty()
        {
            var typeUsage        = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var metadataProperty = MetadataProperty.Create("property", typeUsage, "value");

            Assert.Equal("property", metadataProperty.Name);
            Assert.Same(typeUsage, metadataProperty.TypeUsage);
            Assert.Equal("value", metadataProperty.Value);
            Assert.True(metadataProperty.IsReadOnly);
        }
예제 #10
0
        public void Can_get_and_set_value_property()
        {
            var metadataProperty
                = new MetadataProperty
                {
                Value = "Foo"
                };

            Assert.Equal("Foo", metadataProperty.Value);
        }
예제 #11
0
        public void CreateAnnotation_creates_correct_metdata_property()
        {
            var value      = new object();
            var annotation = MetadataProperty.CreateAnnotation("name", value);

            Assert.Equal("name", annotation.Name);
            Assert.Equal(value, annotation.Value);
            Assert.Null(annotation.TypeUsage);
            Assert.Equal(PropertyKind.Extended, annotation.PropertyKind);
            Assert.True(annotation.IsAnnotation);
        }
예제 #12
0
        /// <summary>
        /// The factory method for constructing the MetadataProperty object.
        /// </summary>
        /// <param name="name">The name of the metadata property.</param>
        /// <param name="typeUsage">The type usage of the metadata property.</param>
        /// <param name="value">The value of the metadata property.</param>
        /// <returns>The MetadataProperty object.</returns>
        /// <exception cref="T:System.NullReferenceException">
        /// Thrown <paramref name="typeUsage" /> is <c>null</c>.
        /// </exception>
        /// <remarks>The newly created MetadataProperty will be read only.</remarks>
        public static MetadataProperty Create(
            string name,
            TypeUsage typeUsage,
            object value)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull <TypeUsage>(typeUsage, nameof(typeUsage));
            MetadataProperty metadataProperty = new MetadataProperty(name, typeUsage, value);

            metadataProperty.SetReadOnly();
            return(metadataProperty);
        }
        private static void EdmSerializationVisitor_writes_expected_xml <T>(
            Func <T> constructor,
            bool invalid,
            Action <EdmSerializationVisitor, T> visitAction,
            string expectedFormat)
            where T : MetadataItem
        {
            var errors = new List <EdmSchemaError>()
            {
                new EdmSchemaError("Message1.", 1, EdmSchemaErrorSeverity.Error),
                new EdmSchemaError("Message2.", 2, EdmSchemaErrorSeverity.Warning)
            };

            var typeUsage1 = TypeUsage.CreateDefaultTypeUsage(
                PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Boolean));
            var property1 = MetadataProperty.Create(
                MetadataItemHelper.SchemaInvalidMetadataPropertyName, typeUsage1, invalid);

            var typeUsage2 = TypeUsage.CreateDefaultTypeUsage(
                PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType());
            var property2 = MetadataProperty.Create(
                MetadataItemHelper.SchemaErrorsMetadataPropertyName, typeUsage2, errors);

            var item = constructor();

            item.AddMetadataProperties(new List <MetadataProperty>()
            {
                property1, property2
            });

            var builder  = new StringBuilder();
            var settings = new XmlWriterSettings {
                ConformanceLevel = ConformanceLevel.Fragment
            };

            using (var writer = XmlWriter.Create(builder, settings))
            {
                visitAction(new EdmSerializationVisitor(writer, 3.0), item);
            }

            var errorsString = String.Concat(
                Strings.MetadataItemErrorsFoundDuringGeneration,
                errors[0].ToString(),
                errors[1].ToString());

            var expectedXml = String.Format(
                CultureInfo.InvariantCulture,
                expectedFormat,
                errorsString);

            AssertEqual(expectedXml, builder.ToString());
        }
예제 #14
0
            public void Contains_is_implemented()
            {
                var typeUsage    = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
                var metadataItem = new EntityType("E", "N", DataSpace.CSpace);
                var annotation   = MetadataProperty.CreateAnnotation("AN", "AV");

                metadataItem.MetadataProperties.Source.Add(MetadataProperty.Create("PN", typeUsage, "PV"));

                Assert.False(metadataItem.Annotations.Contains(annotation));

                metadataItem.Annotations.Add(annotation);

                Assert.True(metadataItem.Annotations.Contains(annotation));
            }
예제 #15
0
        public void Can_set_and_get_annotation_value()
        {
            var value1 = new object();
            var value2 = new object();

            var annotation = MetadataProperty.CreateAnnotation("name", value1);

            Assert.Equal("name", annotation.Name);
            Assert.Same(value1, annotation.Value);

            annotation.Value = value2;

            Assert.Equal("name", annotation.Name);
            Assert.Same(value2, annotation.Value);
        }
예제 #16
0
            public void Add_is_implemented()
            {
                var typeUsage    = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
                var metadataItem = new EntityType("E", "N", DataSpace.CSpace);

                metadataItem.MetadataProperties.Source.Add(MetadataProperty.Create("PN", typeUsage, "PV"));
                var count = metadataItem.MetadataProperties.Count;

                var annotation = MetadataProperty.CreateAnnotation("AN", "AV");

                metadataItem.Annotations.Add(annotation);

                Assert.Same(annotation, metadataItem.MetadataProperties.ElementAt(count));
                Assert.Same(annotation, metadataItem.Annotations.Single());
            }
예제 #17
0
            public void Count_is_implemented()
            {
                var typeUsage    = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
                var metadataItem = new EntityType("E", "N", DataSpace.CSpace);

                metadataItem.MetadataProperties.Source.Add(MetadataProperty.Create("PN", typeUsage, "PV"));

                var count = metadataItem.MetadataProperties.Count;

                Assert.Equal(0, metadataItem.Annotations.Count);

                metadataItem.Annotations.Add(MetadataProperty.CreateAnnotation("AN", "AV"));

                Assert.Equal(count + 1, metadataItem.MetadataProperties.Count);
                Assert.Equal(1, metadataItem.Annotations.Count);
            }
예제 #18
0
        public void SetMetadataProperties_sets_metadata_properties()
        {
            var typeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            var property = EdmProperty.Create("foo", typeUsage);

            property.SetMetadataProperties(
                new List <MetadataProperty>
            {
                MetadataProperty.Create(
                    "foo", TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), "bar")
            });

            Assert.NotNull(property.MetadataProperties.SingleOrDefault(p => p.Name == "foo" && (string)p.Value == "bar"));
        }
예제 #19
0
        public void Create_sets_properties_and_seals_the_instance()
        {
            var source     = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target     = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd  = new AssociationEndMember("SourceEnd", source);
            var targetEnd  = new AssociationEndMember("TargetEnd", target);
            var constraint =
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var associationType =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    Enumerable.Empty <MetadataProperty>());
            var sourceSet        = new EntitySet("SourceSet", "Schema", "Table", "Query", source);
            var targetSet        = new EntitySet("TargetSet", "Schema", "Table", "Query", target);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");
            var associationSet =
                AssociationSet.Create(
                    "AssociationSet",
                    associationType,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty });

            Assert.Equal("AssociationSet", associationSet.Name);
            Assert.Same(associationType, associationSet.ElementType);
            Assert.Same(sourceSet, associationSet.SourceSet);
            Assert.Same(targetSet, associationSet.TargetSet);
            Assert.Same(source, associationSet.SourceEnd.GetEntityType());
            Assert.Same(target, associationSet.TargetEnd.GetEntityType());
            Assert.Same(metadataProperty, associationSet.MetadataProperties.SingleOrDefault(p => p.Name == "MetadataProperty"));
            Assert.True(associationSet.IsReadOnly);
        }
예제 #20
0
            public void CopyTo_is_implemented()
            {
                var typeUsage    = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
                var metadataItem = new EntityType("E", "N", DataSpace.CSpace);
                var annotation1  = MetadataProperty.CreateAnnotation("AN1", "AV1");
                var annotation2  = MetadataProperty.CreateAnnotation("AN2", "AV2");

                metadataItem.MetadataProperties.Source.Add(MetadataProperty.Create("PN", typeUsage, "PV"));
                metadataItem.Annotations.Add(annotation1);
                metadataItem.Annotations.Add(annotation2);

                var annotations = new MetadataProperty[2];

                metadataItem.Annotations.CopyTo(annotations, 0);

                Assert.Same(annotation1, annotations[0]);
                Assert.Same(annotation2, annotations[1]);
            }
예제 #21
0
        public void WriteExtendedProperties_does_not_write_annotations_that_do_not_have_a_name_containing_a_colon()
        {
            var property = MetadataProperty.CreateAnnotation("Foo", "true");

            var mockEntityType = new Mock <EntityType>("E", "ns", DataSpace.CSpace);

            mockEntityType.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                property
            }));

            var fixture = new Fixture(2.0);

            fixture.UnderlyingWriter.WriteStartElement(XmlConstants.EntityType);
            fixture.Writer.WriteExtendedProperties(mockEntityType.Object);

            Assert.Equal(@"<EntityType", fixture.ToString());
        }
예제 #22
0
        public void WriteExtendedProperties_does_not_write_store_generated_annotations()
        {
            var annotation = MetadataProperty.CreateAnnotation(XmlConstants.StoreGeneratedPatternAnnotation, "Identity");

            var mockProperty = new Mock <MetadataProperty>();

            mockProperty.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                annotation
            }));

            var fixture = new Fixture(2.0);

            fixture.UnderlyingWriter.WriteStartElement(XmlConstants.Property);
            fixture.Writer.WriteExtendedProperties(mockProperty.Object);

            Assert.Equal(@"<Property", fixture.ToString());
        }
예제 #23
0
            public void GetEnumerator_is_implemented()
            {
                var typeUsage    = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
                var metadataItem = new EntityType("E", "N", DataSpace.CSpace);
                var annotation1  = MetadataProperty.CreateAnnotation("AN1", "AV1");
                var annotation2  = MetadataProperty.CreateAnnotation("AN2", "AV2");

                metadataItem.MetadataProperties.Source.Add(MetadataProperty.Create("PN", typeUsage, "PV"));
                metadataItem.Annotations.Add(annotation1);
                metadataItem.Annotations.Add(annotation2);

                var enumerator = metadataItem.Annotations.GetEnumerator();

                Assert.True(enumerator.MoveNext());
                Assert.Same(annotation1, enumerator.Current);
                Assert.True(enumerator.MoveNext());
                Assert.Same(annotation2, enumerator.Current);
                Assert.False(enumerator.MoveNext());
            }
예제 #24
0
        public void WriteExtendedProperties_writes_annotations_using_ToString_if_serializer_not_available()
        {
            var property = MetadataProperty.CreateAnnotation(XmlConstants.UseClrTypesAnnotationWithPrefix, "true");

            var mockEntityType = new Mock <EntityType>("E", "ns", DataSpace.CSpace);

            mockEntityType.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                property
            }));

            var fixture = new Fixture(2.0);

            fixture.UnderlyingWriter.WriteStartElement(XmlConstants.EntityType);
            fixture.Writer.WriteExtendedProperties(mockEntityType.Object);

            Assert.Equal(@"<EntityType p1:UseClrTypes=""true""", fixture.ToString());
        }
예제 #25
0
        public void WriteExtendedProperties_writes_annotations_on_properties()
        {
            var annotation = MetadataProperty.CreateAnnotation(XmlConstants.CustomAnnotationPrefix + "Foo", "Goo");

            var mockProperty = new Mock <MetadataProperty>();

            mockProperty.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                annotation
            }));

            var fixture = new Fixture(2.0);

            fixture.UnderlyingWriter.WriteStartElement(XmlConstants.Property);
            fixture.Writer.WriteExtendedProperties(mockProperty.Object);

            Assert.Equal(@"<Property p1:Foo=""Goo""", fixture.ToString());
        }
예제 #26
0
        public void WriteExtendedProperties_writes_annotations_using_serializer_to_serialize_if_available()
        {
            var property = MetadataProperty.CreateAnnotation(XmlConstants.ClrTypeAnnotationWithPrefix, typeof(Random));

            var mockEntityType = new Mock <EntityType>("E", "ns", DataSpace.CSpace);

            mockEntityType.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                property
            }));

            var fixture = new Fixture(2.0);

            fixture.UnderlyingWriter.WriteStartElement(XmlConstants.EntityType);
            fixture.Writer.WriteExtendedProperties(mockEntityType.Object);

            Assert.Equal(
                @"<EntityType p1:ClrType=""System.Random, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""",
                fixture.ToString());
        }
예제 #27
0
        public void WriteEnumTypeElementHeader_writes_annotations()
        {
            var property = MetadataProperty.CreateAnnotation(XmlConstants.ClrTypeAnnotationWithPrefix, typeof(Random));

            var mockEnumType = new Mock <EnumType>();

            mockEnumType.Setup(m => m.Name).Returns("E");
            mockEnumType.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                property
            }));

            var fixture = new Fixture(2.0);

            fixture.Writer.WriteEnumTypeElementHeader(mockEnumType.Object);

            Assert.Equal(
                @"<EnumType Name=""E"" IsFlags=""false"" p1:ClrType=""System.Random, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" UnderlyingType=""Int32""",
                fixture.ToString());
        }
예제 #28
0
        public void Validation_error_not_reported_for_types_marked_as_invalid()
        {
            var invalidAttribute =
                MetadataProperty.Create(
                    "EdmSchemaInvalid",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    true);

            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(
                EntityType.Create("E", "N", DataSpace.SSpace, new string[0], new EdmMember[0], new[] { invalidAttribute }));

            using (var writer = XmlWriter.Create(new StringBuilder()))
            {
                var ssdlSerializer = new SsdlSerializer();
                ssdlSerializer.OnError += (_, e) => { throw new Exception("Should not be invoked."); };

                Assert.True(ssdlSerializer.Serialize(model, "N", "invName", "42", writer));
            }
        }
예제 #29
0
            public void Remove_is_implemented()
            {
                var typeUsage    = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
                var metadataItem = new EntityType("E", "N", DataSpace.CSpace);
                var annotation   = MetadataProperty.CreateAnnotation("AN", "AV");

                metadataItem.MetadataProperties.Source.Add(MetadataProperty.Create("PN", typeUsage, "PV"));
                metadataItem.Annotations.Add(annotation);
                var count = metadataItem.MetadataProperties.Count;

                Assert.Equal(1, metadataItem.Annotations.Count);

                metadataItem.Annotations.Remove(annotation);

                Assert.Equal(count - 1, metadataItem.MetadataProperties.Count);
                Assert.Equal(0, metadataItem.Annotations.Count);
                foreach (var p in metadataItem.MetadataProperties)
                {
                    Assert.False(p.IsAnnotation);
                }
            }
        public void WriteComplexTypeElementHeader_writes_annotations()
        {
            var property = MetadataProperty.CreateAnnotation(XmlConstants.ClrTypeAnnotation, typeof(Random));

            var mockComplexType = new Mock <ComplexType>("C", "ns", DataSpace.CSpace);

            mockComplexType.Setup(m => m.Name).Returns("C");
            mockComplexType.Setup(m => m.MetadataProperties).Returns(
                new ReadOnlyMetadataCollection <MetadataProperty>(new List <MetadataProperty>()
            {
                property
            }));

            var fixture = new Fixture(2.0);

            fixture.Writer.WriteComplexTypeElementHeader(mockComplexType.Object);

            Assert.Equal(
                @"<ComplexType Name=""C"" p1:ClrType=""System.Random, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""",
                fixture.ToString());
        }
예제 #31
0
        public void Can_create_enumeration_member()
        {
            var stringTypeUsage  = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var metadataProperty = new MetadataProperty("MetadataProperty", stringTypeUsage, "Value");

            var member = EnumMember.Create("MemberName", (sbyte)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (sbyte)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (byte)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (byte)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (short)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (short)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (int)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (int)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (long)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (long)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);
        }
예제 #32
0
        public void Can_create_enumeration_member()
        {
            var stringTypeUsage = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var metadataProperty = new MetadataProperty("MetadataProperty", stringTypeUsage, "Value");

            var member = EnumMember.Create("MemberName", (sbyte)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (sbyte)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (byte)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (byte)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (short)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (short)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (int)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (int)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);

            member = EnumMember.Create("MemberName", (long)5, new[] { metadataProperty });

            Assert.Equal("MemberName", member.Name);
            Assert.Equal(5, (long)member.Value);
            Assert.Same(metadataProperty, member.MetadataProperties.Last());
            Assert.True(member.IsReadOnly);
        }
예제 #33
0
        /// <summary>
        /// Adds or updates an annotation with the specified name and value.
        /// </summary>
        /// <remarks>
        /// If an annotation with the given name already exists then the value of that annotation
        /// is updated to the given value. If the given value is null then the annotation will be
        /// removed.
        /// </remarks>
        /// <param name="name">The name of the annotation property.</param>
        /// <param name="value">The value of the annotation property.</param>
        public void AddAnnotation(string name, object value)
        {
            Check.NotEmpty(name, "name");

            var existingAnnotation = Annotations.FirstOrDefault(a => a.Name == name);

            if (existingAnnotation != null)
            {
                if (value == null)
                {
                    RemoveAnnotation(name);
                }
                else
                {
                    existingAnnotation.Value = value;
                }
            }
            else if (value != null)
            {
                GetMetadataProperties().Add(MetadataProperty.CreateAnnotation(name, value));
            }
        }
예제 #34
0
        public void Can_create_enumeration_type()
        {
            var stringTypeUsage  = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var metadataProperty = MetadataProperty.Create("MetadataProperty", stringTypeUsage, "Value");
            var underlyingType   = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);
            var members
                = new[]
                {
                EnumMember.Create("M1", 1, null),
                EnumMember.Create("M2", 2, null)
                };

            var enumType = EnumType.Create("EnumName", "N", underlyingType, true, members, new[] { metadataProperty });

            Assert.Equal("EnumName", enumType.Name);
            Assert.Equal("N", enumType.NamespaceName);
            Assert.True(enumType.IsFlags);
            Assert.Equal(DataSpace.CSpace, enumType.DataSpace);
            Assert.Equal(members, enumType.Members);
            Assert.Same(metadataProperty, enumType.MetadataProperties.Last());
            Assert.True(enumType.IsReadOnly);
        }
        public void Create_sets_properties_and_seals_the_instance()
        {
            var entityType = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var refType = new RefType(entityType);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");
            var associationEnd =
                AssociationEndMember.Create(
                    "AssociationEndMember",
                    refType,
                    RelationshipMultiplicity.Many,
                    OperationAction.Cascade,
                    new[] { metadataProperty });

            Assert.Equal("AssociationEndMember", associationEnd.Name);
            Assert.Same(entityType, associationEnd.GetEntityType());
            Assert.Equal(RelationshipMultiplicity.Many, associationEnd.RelationshipMultiplicity);
            Assert.Equal(OperationAction.Cascade, associationEnd.DeleteBehavior);
            Assert.Same(metadataProperty, associationEnd.MetadataProperties.SingleOrDefault(p => p.Name == "MetadataProperty"));
            Assert.True(associationEnd.IsReadOnly);
        }
        public void Create_throws_argument_exception_when_called_with_null_or_empty_arguments()
        {
            var source = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var constraint =
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var associationType =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    Enumerable.Empty<MetadataProperty>());
            var sourceSet = new EntitySet("SourceSet", "Schema", "Table", "Query", source);
            var targetSet = new EntitySet("TargetSet", "Schema", "Table", "Query", target);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            // name is null
            Assert.Throws<ArgumentException>(
                () => AssociationSet.Create(
                    null,
                    associationType,
                    sourceSet,
                    targetSet,
                    new [] { metadataProperty }));

            // name is empty
            Assert.Throws<ArgumentException>(
                () => AssociationSet.Create(
                    String.Empty,
                    associationType,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty }));

            // type is null
            Assert.Throws<ArgumentNullException>(
                () => AssociationSet.Create(
                    "AssociationSet",
                    null,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty }));
        }
        public void Create_sets_properties_and_seals_the_instance()
        {
            var source = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var constraint =
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var associationType =
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    Enumerable.Empty<MetadataProperty>());
            var sourceSet = new EntitySet("SourceSet", "Schema", "Table", "Query", source);
            var targetSet = new EntitySet("TargetSet", "Schema", "Table", "Query", target);
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");
            var associationSet = 
                AssociationSet.Create(
                    "AssociationSet",
                    associationType,
                    sourceSet,
                    targetSet,
                    new[] { metadataProperty });

            Assert.Equal("AssociationSet", associationSet.Name);
            Assert.Same(associationType, associationSet.ElementType);
            Assert.Same(sourceSet, associationSet.SourceSet);
            Assert.Same(targetSet, associationSet.TargetSet);
            Assert.Same(source, associationSet.SourceEnd.GetEntityType());
            Assert.Same(target, associationSet.TargetEnd.GetEntityType());
            Assert.Same(metadataProperty, associationSet.MetadataProperties.SingleOrDefault(p => p.Name == "MetadataProperty"));
            Assert.True(associationSet.IsReadOnly);
        }
        public void Create_sets_properties_and_seals_the_instance()
        {
            var source = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var constraint = 
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var metadataProperty = 
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");
            var associationType = 
                AssociationType.Create(
                    "AssociationType",
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    new[] { metadataProperty });

            Assert.Equal("Namespace.AssociationType", associationType.FullName);
            Assert.Equal(true, associationType.IsForeignKey);
            Assert.Equal(DataSpace.CSpace, associationType.DataSpace);
            Assert.Same(sourceEnd, associationType.SourceEnd);
            Assert.Same(targetEnd, associationType.TargetEnd);
            Assert.Same(constraint, associationType.Constraint);
            Assert.Same(metadataProperty, associationType.MetadataProperties.SingleOrDefault(p => p.Name == "MetadataProperty"));
            Assert.True(associationType.IsReadOnly);
        }
        public void Create_throws_argument_exception_when_called_with_invalid_arguments()
        {
            var source = new EntityType("Source", "Namespace", DataSpace.CSpace);
            var target = new EntityType("Target", "Namespace", DataSpace.CSpace);
            var sourceEnd = new AssociationEndMember("SourceEnd", source);
            var targetEnd = new AssociationEndMember("TargetEnd", target);
            var constraint =
                new ReferentialConstraint(
                    sourceEnd,
                    targetEnd,
                    new[] { new EdmProperty("SourceProperty") },
                    new[] { new EdmProperty("TargetProperty") });
            var metadataProperty =
                new MetadataProperty(
                    "MetadataProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            Assert.Throws<ArgumentException>(
                () => AssociationType.Create(
                    null,
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    new[] { metadataProperty }));

            Assert.Throws<ArgumentException>(
                () => AssociationType.Create(
                    String.Empty,
                    "Namespace",
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    new[] { metadataProperty }));

            Assert.Throws<ArgumentException>(
                () => AssociationType.Create(
                    "AssociationType",
                    null,
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    new[] { metadataProperty }));

            Assert.Throws<ArgumentException>(
                () => AssociationType.Create(
                    "AssociationType",
                    String.Empty,
                    true,
                    DataSpace.CSpace,
                    sourceEnd,
                    targetEnd,
                    constraint,
                    new[] { metadataProperty }));
        }
예제 #40
0
        /// <summary>
        /// The factory method for constructing the MetadataProperty object.
        /// </summary>
        /// <param name="name">The name of the metadata property.</param>
        /// <param name="typeUsage">The type usage of the metadata property.</param>
        /// <param name="value">The value of the metadata property.</param>
        /// <returns>The MetadataProperty object.</returns>
        /// <exception cref="System.NullReferenceException">
        /// Thrown <paramref name="typeUsage" /> is <c>null</c>.
        /// </exception>
        /// <remarks>The newly created MetadataProperty will be read only.</remarks>
        public static MetadataProperty Create(string name, TypeUsage typeUsage, object value)
        {
            Check.NotEmpty(name, "name");
            Check.NotNull(typeUsage, "typeUsage");

            var metadataProperty = new MetadataProperty(name, typeUsage, value);
            metadataProperty.SetReadOnly();
            return metadataProperty;
        }
예제 #41
0
 internal static MetadataProperty CreateMetadataPropertyFromOtherNamespaceXmlArtifact(
     string xmlNamespaceUri, string artifactName, object value)
 {
     MetadataProperty property;
     property = new MetadataProperty(
         xmlNamespaceUri + ":" + artifactName,
         TypeUsage.Create(EdmProviderManifest.Instance.GetPrimitiveType(PrimitiveTypeKind.String)),
         value);
     return property;
 }