public void Can_set_name_property()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            property.Name = "Foo";

            Assert.Equal("Foo", property.Name);
        }
Ejemplo n.º 2
0
        public void Primitive_should_create_primitive_property()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.NotNull(property);
            Assert.NotNull(property.TypeUsage);
            Assert.Same(primitiveType, property.TypeUsage.EdmType);
        }
Ejemplo n.º 3
0
        public void IsPrimitiveType_returns_true_when_primitive_property()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.False(property.IsComplexType);
            Assert.False(property.IsEnumType);
            Assert.True(property.IsPrimitiveType);
        }
Ejemplo n.º 4
0
        public void Properties_list_should_be_live_on_reread()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            Assert.Empty(entityType.Properties);

            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);

            Assert.Equal(1, entityType.Properties.Count);
        }
        public void IsPrimaryKeyColumn_should_return_true_when_parent_key_members_contains_member()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.False(property.IsPrimaryKeyColumn);

            new EntityType("E", "N", DataSpace.CSpace).AddKeyMember(property);

            Assert.True(property.IsPrimaryKeyColumn);
        }
Ejemplo n.º 6
0
        public void Can_set_nullable_facet()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.True(property.Nullable);

            property.Nullable = false;

            Assert.False(property.Nullable);
        }
Ejemplo n.º 7
0
        public void Properties_list_should_be_live_on_reread()
        {
            var complexType = new ComplexType("C");

            Assert.Empty(complexType.Properties);

            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            complexType.AddMember(property);

            Assert.Equal(1, complexType.Properties.Count);
        }
        public void Can_set_name_and_parent_notified()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            var entityTypeMock = new Mock <StructuralType>();

            property.ChangeDeclaringTypeWithoutCollectionFixup(entityTypeMock.Object);

            property.Name = "Foo";

            entityTypeMock.Verify(e => e.NotifyItemIdentityChanged(), Times.Once());
        }
Ejemplo n.º 9
0
        public void IsUnderlyingPrimitiveType_returns_true_when_underlying_primitive_property()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.True(property.IsUnderlyingPrimitiveType);

            var enumType = new EnumType();

            property = EdmProperty.CreateEnum("P", enumType);

            Assert.True(property.IsUnderlyingPrimitiveType);
        }
Ejemplo n.º 10
0
        public void Can_get_list_of_declared_properties()
        {
            var rowType = new RowType();

            Assert.Empty(rowType.DeclaredProperties);

            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            rowType.AddMember(property);

            Assert.Equal(1, rowType.DeclaredProperties.Count);

            rowType.RemoveMember(property);
        }
Ejemplo n.º 11
0
        public void Cannot_create_property_of_invalid_type()
        {
            var rowType =
                RowType.Create(
                    new[]
            {
                EdmProperty.CreatePrimitive("property", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))
            },
                    null);

            Assert.Equal(
                Strings.EdmProperty_InvalidPropertyType(rowType.FullName),
                Assert.Throws <ArgumentException>(() => EdmProperty.Create("invalidProperty", TypeUsage.Create(rowType))).Message);
        }
Ejemplo n.º 12
0
        public void EdmModel_NameIsNotAllowed_triggered_for_conceptual_property_with_period()
        {
            var property = EdmProperty.CreatePrimitive("Property.With.Dots", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            var validationContext
                = new EdmModelValidationContext(new EdmModel(DataSpace.CSpace), true);
            DataModelErrorEventArgs errorEventArgs = null;

            validationContext.OnError += (_, e) => errorEventArgs = e;

            EdmModelSyntacticValidationRules
            .EdmModel_NameIsNotAllowed
            .Evaluate(validationContext, property);

            Assert.NotNull(errorEventArgs);
        }
Ejemplo n.º 13
0
        public void Can_remove_member()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            Assert.Empty(entityType.Members);

            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);

            Assert.Equal(1, entityType.Members.Count);

            entityType.RemoveMember(property);

            Assert.Empty(entityType.Members);
        }
Ejemplo n.º 14
0
        public void Can_set_primitive_type_and_new_type_usage_is_create_with_facets()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            property.StoreGeneratedPattern = StoreGeneratedPattern.Computed;
            property.ConcurrencyMode       = ConcurrencyMode.Fixed;
            property.MaxLength             = 42;

            property.PrimitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Binary);

            Assert.Equal(StoreGeneratedPattern.Computed, property.StoreGeneratedPattern);
            Assert.Equal(ConcurrencyMode.Fixed, property.ConcurrencyMode);
            Assert.Equal(42, property.MaxLength);
        }
Ejemplo n.º 15
0
        public void Declared_members_should_be_accessible_by_name()
        {
            var entityType =
                EntityType.Create(
                    "Blog",
                    "BlogModel",
                    DataSpace.CSpace,
                    new[] { "Id", "Title" },
                    new[] {
                EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)),
                EdmProperty.CreatePrimitive("Title", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))
            },
                    null);

            Assert.NotNull(entityType.DeclaredMembers["Id"]);
            Assert.NotNull(entityType.DeclaredMembers["Title"]);
        }
Ejemplo n.º 16
0
        public void Create_entity_type_having_base_type_with_key_members()
        {
            var baseType =
                EntityType.Create(
                    "Base",
                    "MyModel",
                    DataSpace.CSpace,
                    new[] { "Id" },
                    new[]
            {
                EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)),
            },
                    null);

            var entity =
                EntityType.Create(
                    "Derived",
                    "MyModel",
                    DataSpace.CSpace,
                    baseType,
                    null,
                    new[]
            {
                EdmProperty.CreatePrimitive("Name", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))
            },
                    new[]
            {
                new MetadataProperty(
                    "TestProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value")
            });

            Assert.Same(baseType, entity.BaseType);
            Assert.Equal("MyModel.Derived", entity.FullName);
            Assert.Equal(DataSpace.CSpace, entity.DataSpace);
            Assert.True(new[] { "Id" }.SequenceEqual(entity.KeyMemberNames));
            Assert.True(new[] { "Id", "Name" }.SequenceEqual(entity.Members.Select(m => m.Name)));
            Assert.True(entity.IsReadOnly);

            var metadataProperty = entity.MetadataProperties.SingleOrDefault(p => p.Name == "TestProperty");

            Assert.NotNull(metadataProperty);
            Assert.Equal("value", metadataProperty.Value);
        }
Ejemplo n.º 17
0
        public void IsKeyMember_should_return_true_when_part_of_key()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.False(property.IsKeyMember);

            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            entityType.AddMember(property);

            Assert.False(property.IsKeyMember);

            entityType.AddKeyMember(property);

            Assert.True(property.IsKeyMember);
        }
        private DataModelErrorEventArgs ValidateAssociationTypeWithNonFkeyReference(DataSpace dataSpace)
        {
            var model = new EdmModel(dataSpace, 1.0);

            var intType =
                dataSpace == DataSpace.CSpace
                    ? PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)
                    : FakeSqlProviderServices.Instance.GetProviderManifest("2008").GetStoreTypes().Single(t => t.Name == "int");

            var principal =
                new EntityType("P", "ns", dataSpace, new [] { "Id" }, new[] { EdmProperty.CreatePrimitive("Id", intType) });
            var dependent =
                new EntityType("P", "ns", dataSpace, new [] { "Id" },
                               new[] { EdmProperty.CreatePrimitive("Id", intType), EdmProperty.CreatePrimitive("NonKeyProperty", intType) });

            foreach (var property in principal.Properties.Concat(dependent.Properties))
            {
                property.Nullable = false;
            }

            var associationType =
                new AssociationType("AT", "ns", false, dataSpace)
            {
                Constraint = new ReferentialConstraint(
                    new AssociationEndMember("P", principal.GetReferenceType(), RelationshipMultiplicity.One),
                    new AssociationEndMember("C", dependent.GetReferenceType(), RelationshipMultiplicity.Many),
                    principal.KeyProperties,
                    dependent.Properties.Where(p => p.Name == "NonKeyProperty"))
            };

            model.AddAssociationType(associationType);

            var validationContext = new EdmModelValidationContext(model, true);

            DataModelErrorEventArgs errorEventArgs = null;

            validationContext.OnError += (_, e) => errorEventArgs = e;

            EdmModelSemanticValidationRules
            .EdmAssociationType_ValidateReferentialConstraint
            .Evaluate(validationContext, model.AssociationTypes.Single());

            return(errorEventArgs);
        }
        public void Can_set_and_get_to_role()
        {
            var toRole = new AssociationEndMember("D", new EntityType("E", "N", DataSpace.CSpace));

            var referentialConstraint
                = new ReferentialConstraint(
                      new AssociationEndMember("P", new EntityType("E", "N", DataSpace.CSpace)),
                      toRole,
                      new[] { EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)) },
                      new[] { EdmProperty.CreatePrimitive("D", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)) });

            Assert.Same(toRole, referentialConstraint.ToRole);

            var toRole2 = new AssociationEndMember("D2", new EntityType("E", "N", DataSpace.CSpace));

            referentialConstraint.ToRole = toRole2;

            Assert.Same(toRole2, referentialConstraint.ToRole);
        }
Ejemplo n.º 20
0
        public void EdmModel_NameIsNotAllowed_not_triggered_for_row_and_collection_types()
        {
            var rowType =
                new RowType(new[] { EdmProperty.CreatePrimitive("Property", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)) });

            foreach (var type in new EdmType[] { rowType, rowType.GetCollectionType() })
            {
                var validationContext
                    = new EdmModelValidationContext(new EdmModel(DataSpace.SSpace), true);
                DataModelErrorEventArgs errorEventArgs = null;
                validationContext.OnError += (_, e) => errorEventArgs = e;

                EdmModelSyntacticValidationRules
                .EdmModel_NameIsNotAllowed
                .Evaluate(validationContext, type);

                Assert.Null(errorEventArgs);
            }
        }
Ejemplo n.º 21
0
        public void UnderlyingPrimitiveType_returns_type_when_underlying_primitive_property()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property = EdmProperty.CreatePrimitive("P", primitiveType);

            Assert.Same(primitiveType, property.UnderlyingPrimitiveType);

            var enumType = new EnumType();

            property = EdmProperty.CreateEnum("P", enumType);

            Assert.Same(primitiveType, property.UnderlyingPrimitiveType);

            var complexType = new ComplexType();

            property = EdmProperty.CreateComplex("P", complexType);

            Assert.Null(property.UnderlyingPrimitiveType);
        }
Ejemplo n.º 22
0
        public void Item_setter_sets_member_of_base_type()
        {
            var baseEntityType = new EntityType("B", "N", DataSpace.CSpace);
            var entityType     = new EntityType("E", "N", DataSpace.CSpace);

            entityType.BaseType = baseEntityType;

            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);
            var property1     = EdmProperty.CreatePrimitive("P1", primitiveType);
            var property2     = EdmProperty.CreatePrimitive("P2", primitiveType);
            var property3     = EdmProperty.CreatePrimitive("P3", primitiveType);

            entityType.AddMember(property2);
            baseEntityType.AddMember(property1);

            Assert.Equal(1, baseEntityType.Members.Count);
            Assert.Equal(2, entityType.Members.Count);
            Assert.Equal(0, baseEntityType.Members.IndexOf(property1));
            Assert.Equal(0, entityType.Members.IndexOf(property1));
            Assert.Equal(1, entityType.Members.IndexOf(property2));

            entityType.Members.Source[0] = property3;

            Assert.False(baseEntityType.Members.Contains(property1));
            Assert.False(entityType.Members.Contains(property1));
            Assert.Equal(1, baseEntityType.Members.Count);
            Assert.Equal(2, entityType.Members.Count);
            Assert.Equal(0, baseEntityType.Members.IndexOf(property3));
            Assert.Equal(0, entityType.Members.IndexOf(property3));
            Assert.Equal(1, entityType.Members.IndexOf(property2));

            baseEntityType.Members.Source[0] = property1;

            Assert.False(baseEntityType.Members.Contains(property3));
            Assert.False(entityType.Members.Contains(property3));
            Assert.Equal(1, baseEntityType.Members.Count);
            Assert.Equal(2, entityType.Members.Count);
            Assert.Equal(0, baseEntityType.Members.IndexOf(property1));
            Assert.Equal(0, entityType.Members.IndexOf(property1));
            Assert.Equal(1, entityType.Members.IndexOf(property2));
        }
        public void Identity_uniquified_when_duplicate_name_set()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property1 = EdmProperty.CreatePrimitive("Foo", primitiveType);
            var property2 = EdmProperty.CreatePrimitive("Bar", primitiveType);
            var property3 = EdmProperty.CreatePrimitive("Boo", primitiveType);

            var entityType = new EntityType("T", "S", DataSpace.CSpace);

            entityType.AddMember(property1);
            entityType.AddMember(property2);
            entityType.AddMember(property3);

            property2.Name = "Foo";
            property3.Name = "Foo";

            Assert.Equal("Foo1", property2.Identity);
            Assert.Equal("Foo2", property3.Identity);
            Assert.Equal(3, entityType.Properties.Count);
        }
Ejemplo n.º 24
0
        public void KeyProperties_is_thread_safe()
        {
            var baseType   = new EntityType("E", "N", DataSpace.CSpace);
            var entityType = new EntityType("F", "N", DataSpace.CSpace);
            var property   = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            baseType.AddKeyMember(property);
            entityType.BaseType = baseType;
            const int cycles      = 100;
            const int threadCount = 30;

            Action readKeyProperty = () =>
            {
                for (var i = 0; i < cycles; ++i)
                {
                    var keys = entityType.KeyProperties;

                    //touching KeyMembers.Source triggers a reset to KeyProperties
                    var sourceCount = entityType.KeyMembers.Source.Count;
                    Assert.True(sourceCount == 1);

                    var keysAfterReset = entityType.KeyProperties;

                    Assert.True(keys != null, "First reference to key properties should not be null");
                    Assert.True(keysAfterReset != null, "Second reference to key properties should not be null");
                    Assert.False(ReferenceEquals(keys, keysAfterReset), "The key properties instances should be different");
                }
            };

            var tasks = new List <Thread>();

            for (var i = 0; i < threadCount; ++i)
            {
                var thread = new Thread(new ThreadStart(readKeyProperty));
                tasks.Add(thread);
            }

            tasks.ForEach(t => t.Start());
            tasks.ForEach(t => t.Join());
        }
Ejemplo n.º 25
0
        public void Can_get_list_of_declared_properties()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);

            Assert.Empty(entityType.DeclaredProperties);

            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);

            Assert.Equal(1, entityType.DeclaredProperties.Count);

            entityType.RemoveMember(property);

            var baseType = new EntityType("E", "N", DataSpace.CSpace);

            baseType.AddMember(property);

            entityType.BaseType = baseType;

            Assert.Empty(entityType.DeclaredProperties);
            Assert.Equal(1, entityType.Members.Count);
        }
        public void BuildConstraintExceptionMessage_returns_message_for_single_property_constraint()
        {
            var principalType     = new EntityType("Principal", "N", DataSpace.CSpace);
            var principalProperty = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            principalType.AddMember(principalProperty);

            var dependentType     = new EntityType("Dependent", "N", DataSpace.CSpace);
            var dependentProperty = EdmProperty.CreatePrimitive("D1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));

            dependentType.AddMember(dependentProperty);

            var referentialConstraint
                = new ReferentialConstraint(
                      new AssociationEndMember("P", principalType),
                      new AssociationEndMember("D", dependentType),
                      new[] { principalProperty },
                      new[] { dependentProperty });

            Assert.Equal(
                Strings.RelationshipManager_InconsistentReferentialConstraintProperties("Principal.P1", "Dependent.D1"),
                referentialConstraint.BuildConstraintExceptionMessage());
        }
Ejemplo n.º 27
0
        public void Can_get_and_set_facet_wrappers()
        {
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            property.ConcurrencyMode = ConcurrencyMode.Fixed;
            property.CollectionKind  = CollectionKind.List;

            Assert.Equal(ConcurrencyMode.Fixed, property.ConcurrencyMode);
            Assert.Equal(CollectionKind.List, property.CollectionKind);

            property.MaxLength = 42;

            Assert.Equal(42, property.MaxLength.Value);

            property.IsMaxLength = true;

            Assert.Null(property.MaxLength);
            Assert.True(property.IsMaxLength);

            property.IsFixedLength = true;
            property.IsUnicode     = true;

            Assert.True(property.IsFixedLength.Value);
            Assert.True(property.IsUnicode.Value);

            property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Decimal));

            property.Precision = 42;
            property.Scale     = 42;

            Assert.Equal(42, property.Precision.Value);
            Assert.Equal(42, property.Scale.Value);

            property.StoreGeneratedPattern = StoreGeneratedPattern.Identity;

            Assert.Equal(StoreGeneratedPattern.Identity, property.StoreGeneratedPattern);
        }
        public void Identity_synced_when_member_goes_readonly_and_parent_notified()
        {
            var primitiveType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var property1 = EdmProperty.CreatePrimitive("Foo", primitiveType);
            var property2 = EdmProperty.CreatePrimitive("Bar", primitiveType);
            var property3 = EdmProperty.CreatePrimitive("Boo", primitiveType);

            var entityTypeMock = new Mock <EntityType>("T", "S", DataSpace.CSpace)
            {
                CallBase = true
            };

            entityTypeMock.Setup(e => e.NotifyItemIdentityChanged());

            entityTypeMock.Object.AddMember(property1);
            entityTypeMock.Object.AddMember(property2);
            entityTypeMock.Object.AddMember(property3);

            property2.Name = "Foo";
            property3.Name = "Foo";

            Assert.Equal("Foo1", property2.Identity);
            Assert.Equal("Foo2", property3.Identity);
            entityTypeMock.Verify(e => e.NotifyItemIdentityChanged(), Times.Exactly(2));

            property2.SetReadOnly();

            Assert.Equal("Foo", property2.Identity);
            entityTypeMock.Verify(e => e.NotifyItemIdentityChanged(), Times.Exactly(3));

            property3.SetReadOnly();

            Assert.Equal("Foo", property3.Identity);
            entityTypeMock.Verify(e => e.NotifyItemIdentityChanged(), Times.Exactly(4));
        }