public void It_returns_an_odcm_model()
        {
            var edmxElement = Any.Csdl.EdmxToSchema(schema =>
                                                    schema.Add(Any.Csdl.EntityContainer()));

            var serviceMetadata = new Dictionary <string, string>()
            {
                { "$metadata", edmxElement.ToString() }
            };
            var odcmModel = reader.GenerateOdcmModel(serviceMetadata);

            odcmModel
            .Should()
            .NotBeNull("because a valid edmx should yield a valid model");
        }
Esempio n. 2
0
        public void It_returns_one_OdcmClass_for_each_ComplexType()
        {
            var complexTypeName = string.Empty;
            var schemaNamespace = string.Empty;
            var propertyCount   = 0;

            var edmxElement = Any.Csdl.EdmxToSchema(schema =>
            {
                schema.Add(Any.Csdl.ComplexType(complexType =>
                {
                    foreach (
                        var property in
                        Any.Sequence(
                            i =>
                            Any.Csdl.Property(
                                property => property.AddAttribute("Type", Any.Csdl.RandomPrimitiveType())),
                            Any.Int(1, 5)))
                    {
                        complexType.Add(property);
                        propertyCount++;
                    }

                    complexTypeName = complexType.Attribute("Name").Value;
                }));
                schema.Add(Any.Csdl.EntityContainer());
                schemaNamespace = schema.Attribute("Namespace").Value;
            });

            var serviceMetadata = new Dictionary <string, string>()
            {
                { "$metadata", edmxElement.ToString() }
            };
            var odcmModel = reader.GenerateOdcmModel(serviceMetadata);

            OdcmType odcmComplexType;

            odcmModel.TryResolveType(complexTypeName, schemaNamespace, out odcmComplexType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
            .Should()
            .BeOfType <OdcmClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As <OdcmClass>().Properties.Count
            .Should()
            .Be(propertyCount, "because each property added to a complex type should result in an OdcmClass property");
        }
        public void It_returns_one_OdcmType_for_each_EnumType()
        {
            var schemaNamespace = string.Empty;
            var enumName        = string.Empty;
            var enumMemberCount = 0;

            var edmxElement = Any.Csdl.EdmxToSchema(schema =>
            {
                schema.Add(Any.Csdl.EnumType(enumType =>
                {
                    foreach (var member in Any.Sequence((i) => Any.Csdl.Member(), Any.Int(1, 5)))
                    {
                        enumType.Add(member);
                        enumMemberCount++;
                    }
                    enumName = enumType.Attribute("Name").Value;
                }));
                schema.Add(Any.Csdl.EntityContainer());
                schemaNamespace = schema.Attribute("Namespace").Value;
            });

            var serviceMetadata = new Dictionary <string, string>()
            {
                { "$metadata", edmxElement.ToString() }
            };
            var odcmModel = reader.GenerateOdcmModel(serviceMetadata);

            OdcmType odcmEnum;

            odcmModel.TryResolveType(enumName, schemaNamespace, out odcmEnum)
            .Should()
            .BeTrue("because an enum type in the schema should result in an OdcmType");
            odcmEnum.Should().BeOfType <OdcmEnum>("because an enum type in the schema should result in an OdcmEnum");
            odcmEnum.As <OdcmEnum>()
            .Members.Count.Should()
            .Be(enumMemberCount, "because each member added to the schema should result in an OdcmMember");
        }
Esempio n. 4
0
        public void It_returns_one_OdcmClass_for_each_EntityType()
        {
            var entityTypeName  = string.Empty;
            var schemaNamespace = string.Empty;
            var propertyCount   = 0;
            var keyCount        = 0;

            var edmxElement = Any.Csdl.EdmxToSchema(schema =>
            {
                schema.Add(Any.Csdl.EntityType(entityType =>
                {
                    entityType.Add(Any.Csdl.Key(key =>
                    {
                        foreach (
                            var property in
                            Any.Sequence(
                                i => Any.Csdl.Property(Any.Csdl.RandomPrimitiveType()),
                                Any.Int(1, 2)))
                        {
                            entityType.Add(property);
                            key.Add(Any.Csdl.PropertyRef(property.Attribute("Name").Value));
                            keyCount++;
                        }
                    }));
                    foreach (
                        var property in
                        Any.Sequence(
                            i => Any.Csdl.Property(Any.Csdl.RandomPrimitiveType()),
                            Any.Int(1, 3)))
                    {
                        entityType.Add(property);
                        propertyCount++;
                    }

                    entityTypeName = entityType.Attribute("Name").Value;
                }));
                schema.Add(Any.Csdl.EntityContainer());
                schemaNamespace = schema.Attribute("Namespace").Value;
            });

            var serviceMetadata = new Dictionary <string, string>()
            {
                { "$metadata", edmxElement.ToString() }
            };
            var odcmModel = reader.GenerateOdcmModel(serviceMetadata);

            OdcmType odcmEntityType;

            odcmModel.TryResolveType(entityTypeName, schemaNamespace, out odcmEntityType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
            .Should()
            .BeOfType <OdcmClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As <OdcmClass>().Key.Count
            .Should()
            .Be(keyCount, "because each property reference added to the key of an entity type should result in an OdcmClass property");
            odcmEntityType.As <OdcmClass>().Properties.Count
            .Should()
            .Be(propertyCount + keyCount, "because each property added to an entity type should result in an OdcmClass property");
            odcmEntityType.As <OdcmClass>().IsAbstract
            .Should()
            .BeFalse("because an entity type with no Abstract facet should be false in the OdcmModel");
            odcmEntityType.As <OdcmClass>().IsOpen
            .Should()
            .BeFalse("because an entity type with no OpenType facet should be false in the OdcmModel");
        }