public void It_returns_one_OdcmEntityClass_for_each_EntityType()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType);

            var entityTypeDescendants = testCase[EdmxTestCase.Keys.EntityType].Element.Descendants();
            var keyCount      = entityTypeDescendants.Count(x => x.Name.LocalName == "PropertyRef");
            var propertyCount = entityTypeDescendants.Count(x => x.Name.LocalName == "Property");

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEntityType = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]);

            odcmEntityType.As <OdcmEntityClass>().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 <OdcmEntityClass>().Properties.Count
            .Should()
            .Be(propertyCount, "because each property added to an entity type should result in an OdcmClass property");
            odcmEntityType.As <OdcmEntityClass>().IsAbstract
            .Should()
            .BeFalse("because an entity type with no Abstract facet should be false in the OdcmModel");
            odcmEntityType.As <OdcmEntityClass>().IsOpen
            .Should()
            .BeFalse("because an entity type with no OpenType facet should be false in the OdcmModel");
        }
        public void When_Property_is_of_TypeDefinitionType_then_it_should_resolve_as_UnderlyingPrimitiveType()
        {
            var underlyingType = Any.Csdl.RandomPrimitiveType();

            var testCase = new EdmxTestCase()
                .AddTypeDefinitionType(EdmxTestCase.Keys.TypeDefinitionType, (_, typeDefinitionType) => typeDefinitionType.AddAttribute("UnderlyingType", underlyingType));

            var typeDefinitionTypeTestNode = testCase[EdmxTestCase.Keys.TypeDefinitionType];

            testCase.AddComplexType(EdmxTestCase.Keys.ComplexType, (_, complexType) => complexType.Add(Any.Csdl.Property(property => property.AddAttribute("Type", typeDefinitionTypeTestNode.FullName()))));

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());
            
            OdcmType odcmComplexType;
            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
                .Should()
                .BeTrue("because a complex type in the schema should result in an OdcmType");

            odcmComplexType
                .Should()
                .BeOfType<OdcmComplexClass>("because complex types should result in an OdcmClass");

            odcmComplexType.As<OdcmComplexClass>().Properties
                .Count(property => property.Type is OdcmTypeDefinition)
                .Should()
                .Be(0, "because OdcmTypeDefinition type should be resolved as underlying OdcmPrimitiveType");
        }
        public void It_returns_one_OdcmEntityClass_for_each_EntityType()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType);

            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];
            var keyCount           = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("PropertyRef") select x).Count();
            var propertyCount      = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Property") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEntityType;

            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
            .Should()
            .BeOfType <OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As <OdcmEntityClass>().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 <OdcmEntityClass>().Properties.Count
            .Should()
            .Be(propertyCount, "because each property added to an entity type should result in an OdcmClass property");
            odcmEntityType.As <OdcmEntityClass>().IsAbstract
            .Should()
            .BeFalse("because an entity type with no Abstract facet should be false in the OdcmModel");
            odcmEntityType.As <OdcmEntityClass>().IsOpen
            .Should()
            .BeFalse("because an entity type with no OpenType facet should be false in the OdcmModel");
        }
        public void It_returns_one_OdcmEntityClass_for_each_EntityType()
        {
            var testCase = new EdmxTestCase()
                .AddEntityType(EdmxTestCase.Keys.EntityType);

            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];
            var keyCount = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("PropertyRef") select x).Count();
            var propertyCount = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Property") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());
            
            OdcmType odcmEntityType;
            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
                .Should()
                .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
                .Should()
                .BeOfType<OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As<OdcmEntityClass>().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<OdcmEntityClass>().Properties.Count
                .Should()
                .Be(propertyCount, "because each property added to an entity type should result in an OdcmClass property");
            odcmEntityType.As<OdcmEntityClass>().IsAbstract
                .Should()
                .BeFalse("because an entity type with no Abstract facet should be false in the OdcmModel");
            odcmEntityType.As<OdcmEntityClass>().IsOpen
                .Should()
                .BeFalse("because an entity type with no OpenType facet should be false in the OdcmModel");
        }
Ejemplo n.º 5
0
        public void When_Property_is_of_TypeDefinitionType_then_it_should_resolve_as_UnderlyingPrimitiveType()
        {
            var underlyingType = Any.Csdl.RandomPrimitiveType();

            var testCase = new EdmxTestCase()
                           .AddTypeDefinitionType(EdmxTestCase.Keys.TypeDefinitionType, (_, typeDefinitionType) => typeDefinitionType.AddAttribute("UnderlyingType", underlyingType));

            var typeDefinitionTypeTestNode = testCase[EdmxTestCase.Keys.TypeDefinitionType];

            testCase.AddComplexType(EdmxTestCase.Keys.ComplexType, (_, complexType) => complexType.Add(Any.Csdl.Property(property => property.AddAttribute("Type", typeDefinitionTypeTestNode.FullName()))));

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;

            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");

            odcmComplexType
            .Should()
            .BeOfType <OdcmComplexClass>("because complex types should result in an OdcmClass");

            odcmComplexType.As <OdcmComplexClass>().Properties
            .Count(property => property.Type is OdcmTypeDefinition)
            .Should()
            .Be(0, "because OdcmTypeDefinition type should be resolved as underlying OdcmPrimitiveType");
        }
        public void When_IsFlags_is_set_it_returns_an_OdcmEnum_with_IsFlags_set()
        {
            var testCase = new EdmxTestCase()
                .AddEnumType(EdmxTestCase.Keys.EnumType, (_, enumType) =>
                {
                    var count = 0;
                    foreach (var descendent in enumType.Descendants())
                    {
                        if (descendent.Name.LocalName.Equals("Member"))
                        {
                            descendent.AddAttribute("Value", (int)Math.Pow(count++, 2));
                        }
                    }
                    enumType.AddAttribute("IsFlags", true);
                });

            var enumTypeTestNode = testCase[EdmxTestCase.Keys.EnumType];
            var enumMemberCount = (from x in enumTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Member") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEnum;
            odcmModel.TryResolveType(enumTypeTestNode.Name, enumTypeTestNode.Namespace, 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");
            odcmEnum.As<OdcmEnum>()
                .IsFlags.Should()
                .BeTrue(
                    "because an enum type in the schema with the IsFlags facet set to true should result in an OdcmEnum with the IsFlags property set to true");
        }
Ejemplo n.º 7
0
        public void When_IsFlags_is_set_it_returns_an_OdcmEnum_with_IsFlags_set()
        {
            var testCase = new EdmxTestCase()
                           .AddEnumType(EdmxTestCase.Keys.EnumType, (_, enumType) =>
            {
                var count = 0;
                foreach (var descendent in enumType.Descendants())
                {
                    if (descendent.Name.LocalName.Equals("Member"))
                    {
                        descendent.AddAttribute("Value", (int)Math.Pow(count++, 2));
                    }
                }
                enumType.AddAttribute("IsFlags", true);
            });

            var enumTypeTestNode = testCase[EdmxTestCase.Keys.EnumType];
            var enumMemberCount  = (from x in enumTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Member") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEnum;

            odcmModel.TryResolveType(enumTypeTestNode.Name, enumTypeTestNode.Namespace, 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");
            odcmEnum.As <OdcmEnum>()
            .IsFlags.Should()
            .BeTrue(
                "because an enum type in the schema with the IsFlags facet set to true should result in an OdcmEnum with the IsFlags property set to true");
        }
        public void When_a_function_is_bound_to_an_entity_type_there_is_a_method_on_the_OdcmClass()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType)
                           .AddBoundFunction(EdmxTestCase.Keys.Function, EdmxTestCase.Keys.EntityType);

            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];
            var functionTestNode   = testCase[EdmxTestCase.Keys.Function];
            var parameterCount     = (from x in functionTestNode.Element.Descendants() where x.Name.LocalName.Equals("Parameter") select x).Count() - 1;
            var odcmModel          = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());


            OdcmType odcmEntityType;

            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
            .Should()
            .BeOfType <OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As <OdcmEntityClass>().Methods
            .Should()
            .Contain(odcmMethod => odcmMethod.Name == functionTestNode.Name, "because a function bound to an entity type should result in a method in the OdcmClass");
            odcmEntityType.As <OdcmEntityClass>()
            .Methods.Find(odcmMethod => odcmMethod.Name == functionTestNode.Name)
            .Parameters.Count
            .Should()
            .Be(parameterCount,
                "because for each parameter in the action there should be a OdcmParameter in the OdcmMethod");
        }
Ejemplo n.º 9
0
        public void When_An_Underlying_Type_is_set_it_returns_an_OdcmEnum_with_the_specified_UnderlyingType()
        {
            var underlyingType = Any.Csdl.RandomEnumUnderlyingType();

            var testCase = new EdmxTestCase()
                           .AddEnumType(EdmxTestCase.Keys.EnumType, (_, enumType) => enumType.AddAttribute("UnderlyingType", underlyingType));

            var enumTypeTestNode = testCase[EdmxTestCase.Keys.EnumType];
            var enumMemberCount  = (from x in enumTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Member") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEnum;

            odcmModel.TryResolveType(enumTypeTestNode.Name, enumTypeTestNode.Namespace, 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");
            odcmEnum.As <OdcmEnum>().UnderlyingType.FullName
            .Should()
            .Be(underlyingType,
                "because an enum type with an explicit underlying type in the schema should have the specified underlying type in an OdcmEnum");
        }
        public void When_an_action_is_bound_to_an_entity_type_there_is_a_method_on_the_OdcmClass()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType)
                           .AddBoundAction(EdmxTestCase.Keys.Action, EdmxTestCase.Keys.EntityType);

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            VerifyMethodTestCase(odcmModel, testCase, EdmxTestCase.Keys.Action);
        }
        public void When_a_function_is_bound_to_an_entity_type_in_a_different_namespace_there_is_a_method_on_the_OdcmClass()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType)
                           .AddBoundFunction(EdmxTestCase.Keys.Function, EdmxTestCase.Keys.EntityType, Any.Csdl.Schema());

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            VerifyMethodTestCase(odcmModel, testCase, EdmxTestCase.Keys.Function);
        }
        public void It_returns_an_odcm_model()
        {
            var testCase = new EdmxTestCase();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            odcmModel
            .Should()
            .NotBeNull("because a valid edmx should yield a valid model");
        }
        public void It_returns_an_odcm_model()
        {
            var testCase = new EdmxTestCase();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            odcmModel
                .Should()
                .NotBeNull("because a valid edmx should yield a valid model");
        }
Ejemplo n.º 14
0
        public void When_TypeDefinitionType_is_declared_with_UnderlyingComplexType_then_it_should_raise_exception()
        {
            var testCase = new EdmxTestCase()
                           .AddComplexType(EdmxTestCase.Keys.ComplexType);

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];
            var underlyingType      = complexTypeTestNode.FullName();

            testCase.AddTypeDefinitionType(EdmxTestCase.Keys.TypeDefinitionType, (_, typeDefinitionType) => typeDefinitionType.AddAttribute("UnderlyingType", underlyingType));

            Exception ex = Assert.Throws <InvalidOperationException>(() => _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata()));
        }
        public void When_TypeDefinitionType_is_declared_with_UnderlyingComplexType_then_it_should_raise_exception()
        {
            var testCase = new EdmxTestCase()
                    .AddComplexType(EdmxTestCase.Keys.ComplexType);

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];
            var underlyingType = complexTypeTestNode.FullName();
            
            testCase.AddTypeDefinitionType(EdmxTestCase.Keys.TypeDefinitionType, (_, typeDefinitionType) => typeDefinitionType.AddAttribute("UnderlyingType", underlyingType));
            
            Exception ex=Assert.Throws<InvalidOperationException>(() => _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata()));
        }
        public void When_HasStream_is_set_it_returns_an_OdcmMediaClass()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("HasStream", true));

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEntityType = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]);

            odcmEntityType
            .Should()
            .BeOfType <OdcmMediaClass>("because an entity type with the HasStream facet set should be an OdcmMediaClass");
        }
        public void When_OpenType_is_set_it_returns_an_OdcmEntityClass_with_IsOpen_set()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("OpenType", true));

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEntityType = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]);

            odcmEntityType.As <OdcmEntityClass>().IsOpen
            .Should()
            .BeTrue("because an entity type with the OpenType facet set should be open in the OdcmModel");
        }
        public void When_BaseType_is_set_it_returns_an_OdcmEntityClass_with_a_BaseType()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityTypeBase, (_, entityType) => entityType.AddAttribute("Abstract", true))
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("BaseType", _[EdmxTestCase.Keys.EntityTypeBase].FullName()));

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            var odcmBaseType   = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityTypeBase]);
            var odcmEntityType = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]);

            VerifyInheritanceLink(odcmBaseType, odcmEntityType);
        }
        public void It_results_an_OdcmNamespace_for_the_Schema()
        {
            var testCase = new EdmxTestCase();

            var schemaTestNode = testCase[EdmxTestCase.Keys.Schema];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            odcmModel.Namespaces
                .FindAll(
                    @namespace => @namespace.Name.Equals(schemaTestNode.Namespace, StringComparison.InvariantCultureIgnoreCase))
                .Count
                .Should()
                .Be(1, "because only one namespace shoud be created per schema element");
        }
        public void It_results_an_OdcmNamespace_for_the_Schema()
        {
            var testCase = new EdmxTestCase();

            var schemaTestNode = testCase[EdmxTestCase.Keys.Schema];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            odcmModel.Namespaces
            .FindAll(
                @namespace => @namespace.Name.Equals(schemaTestNode.Namespace, StringComparison.InvariantCultureIgnoreCase))
            .Count
            .Should()
            .Be(1, "because only one namespace shoud be created per schema element");
        }
        public void It_results_in_an_OdcmClass_for_the_EntityContainer()
        {
            var testCase = new EdmxTestCase();

            var entityContainerTestNode = testCase[EdmxTestCase.Keys.EntityContainer];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmClass;
            odcmModel.TryResolveType(entityContainerTestNode.Name, entityContainerTestNode.Namespace, out odcmClass)
                .Should()
                .BeTrue("because an EntityContainer should result in a matching OdcmType");
            odcmClass
                .Should()
                .BeOfType<OdcmServiceClass>("because an EntityContainer should result in a matching OdcmServiceClass");
        }
        private void VerifyMethodTestCase(OdcmModel odcmModel, EdmxTestCase testCase, string methodKey)
        {
            var functionTestNode = testCase[methodKey];
            var parameterCount   = functionTestNode.Element.Descendants().Count(x => x.Name.LocalName == "Parameter") - 1;

            OdcmType odcmEntityType = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]);

            odcmEntityType.As <OdcmEntityClass>().Methods
            .Should()
            .Contain(odcmMethod => odcmMethod.Name == functionTestNode.Name, "because a function bound to an entity type should result in a method in the OdcmClass");
            odcmEntityType.As <OdcmEntityClass>()
            .Methods.Single(odcmMethod => odcmMethod.Name == functionTestNode.Name)
            .Parameters.Count
            .Should()
            .Be(parameterCount,
                "because for each parameter in the action there should be a OdcmParameter in the OdcmMethod");
        }
        public void When_a_Property_references_a_ComplexType_it_returns_an_OdcmEntityClass_with_a_property_having_the_corresponding_OdcmComplexType()
        {
            string complexTypePropertyName = string.Empty;

            var testCase = new EdmxTestCase()
                           .AddComplexType(EdmxTestCase.Keys.ComplexType)
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) =>
            {
                var property            = Any.Csdl.Property(_[EdmxTestCase.Keys.ComplexType].FullName());
                complexTypePropertyName = property.Attribute("Name").Value;
                entityType.Add(property);
            });

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];
            var entityTypeTestNode  = testCase[EdmxTestCase.Keys.EntityType];
            var keyCount            = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("PropertyRef") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;

            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
            .Should()
            .BeOfType <OdcmComplexClass>("because complex types should result in an OdcmComplexClass");
            OdcmType odcmEntityType;

            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
            .Should()
            .BeOfType <OdcmEntityClass>("because entity types should result in an OdcmEntityClass");
            var complexProperty = (from property in odcmEntityType.As <OdcmEntityClass>().Properties
                                   where property.Name.Equals(complexTypePropertyName)
                                   select property).FirstOrDefault();

            complexProperty
            .Should()
            .NotBeNull("because a property referencing a complex type should result in a property in the OdcmEntityClass");
            complexProperty.Type
            .Should()
            .Be(odcmComplexType, "because a property referencing a complex type should result in a property with a type matching the OdcmComplexClass of the property");
        }
        public void It_results_in_an_OdcmClass_for_the_EntityContainer()
        {
            var testCase = new EdmxTestCase();

            var entityContainerTestNode = testCase[EdmxTestCase.Keys.EntityContainer];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmClass;

            odcmModel.TryResolveType(entityContainerTestNode.Name, entityContainerTestNode.Namespace, out odcmClass)
            .Should()
            .BeTrue("because an EntityContainer should result in a matching OdcmType");
            odcmClass
            .Should()
            .BeOfType <OdcmServiceClass>("because an EntityContainer should result in a matching OdcmServiceClass");
        }
        public void When_BaseType_is_set_and_both_have_Keys_it_returns_an_OdcmEntityClass_using_Key_of_derived_EntityType()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityTypeBase, (_, entityType) => entityType.AddAttribute("Abstract", true))
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("BaseType", _[EdmxTestCase.Keys.EntityTypeBase].FullName()));

            var baseEntityTypeTestNode = testCase[EdmxTestCase.Keys.EntityTypeBase];
            var entityTypeTestNode     = testCase[EdmxTestCase.Keys.EntityType];
            var keyCount = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("PropertyRef") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmBaseType;

            odcmModel.TryResolveType(baseEntityTypeTestNode.Name, baseEntityTypeTestNode.Namespace, out odcmBaseType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmBaseType
            .Should()
            .BeOfType <OdcmEntityClass>("because entity types should result in an OdcmClass");
            OdcmType odcmEntityType;

            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
            .Should()
            .BeOfType <OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As <OdcmEntityClass>().Base
            .Should()
            .Be(odcmBaseType,
                "because an entity type with a base type set should have a corresponding OdcmClass and base OdcmClass");
            odcmBaseType.As <OdcmEntityClass>().Derived
            .Should()
            .Contain(odcmEntityType.As <OdcmEntityClass>(),
                     "because an entity type with a base type set should have a correspond OdcmClass that derives from a base OdcmClass");
            odcmEntityType.As <OdcmEntityClass>().Key
            .Count().Should().Be(keyCount, "because the Key of an OdcmEntityClass should have the same number of OdcmProperties as there are properties in the entity type key");
            (from key in odcmEntityType.As <OdcmEntityClass>().Key
             where
             (from x in entityTypeTestNode.Element.Descendants()
              where x.Name.LocalName.Equals("PropertyRef") && x.GetAttribute("Name").Equals(key.CanonicalName())
              select x).Any()
             select key).Count().Should().Be(keyCount, "because the Key of an OdcmEntityClass should have the corresponding OdcmProperties as in the entity type key");
        }
        public void When_HasStream_is_set_it_returns_an_OdcmMediaClass()
        {
            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("HasStream", true));

            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEntityType;

            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
            .Should()
            .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
            .Should()
            .BeOfType <OdcmMediaClass>("because an entity type with the HasStream facet set should be an OdcmMediaClass");
        }
        public void It_returns_one_OdcmType_for_each_EnumType()
        {
            var testCase = new EdmxTestCase()
                .AddEnumType(EdmxTestCase.Keys.EnumType);

            var enumTypeTestNode = testCase[EdmxTestCase.Keys.EnumType];
            var enumMemberCount = (from x in enumTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Member") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEnum;
            odcmModel.TryResolveType(enumTypeTestNode.Name, enumTypeTestNode.Namespace, 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");
        }
        public void When_Abstract_is_set_it_returns_an_OdcmEntityClass_with_IsAbstract_set()
        {
            var testCase = new EdmxTestCase()
                .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("Abstract", true));

            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());
            
            OdcmType odcmEntityType;
            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
                .Should()
                .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
                .Should()
                .BeOfType<OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As<OdcmEntityClass>().IsAbstract
                .Should()
                .BeTrue("because an entity type with the Abstract facet set should be abstract in the OdcmModel");
        }
Ejemplo n.º 29
0
        public void When_property_is_invalid_it_skips_addition()
        {
            var entityNamespace = Any.Csdl.EntityContainer().Attribute("Name").Value.ToString();

            var customPropertyName = string.Empty;

            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) =>
            {
                var property       = Any.Csdl.Property(entityNamespace + ".invalid");
                customPropertyName = property.Attribute("Name").Value;
                entityType.Add(property);
            });

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            var createdType = odcmModel.EntityContainer.Namespace.Types.Where(x => x.FullName == customPropertyName);

            createdType.Should().BeEmpty("because the invalid property should have been skipped");
        }
        public void When_OpenType_is_set_it_returns_an_OdcmClass_with_IsOpen_set()
        {
            var testCase = new EdmxTestCase()
                .AddComplexType(EdmxTestCase.Keys.ComplexType, (_, complexType) => complexType.AddAttribute("OpenType", true));

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;
            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
                .Should()
                .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
                .Should()
                .BeOfType<OdcmComplexClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As<OdcmComplexClass>().IsOpen
                .Should()
                .BeTrue("because a complex type with the OpenType facet set should be open in the OdcmModel");
        }
Ejemplo n.º 31
0
        public void It_returns_one_OdcmType_for_each_EnumType()
        {
            var testCase = new EdmxTestCase()
                           .AddEnumType(EdmxTestCase.Keys.EnumType);

            var enumTypeTestNode = testCase[EdmxTestCase.Keys.EnumType];
            var enumMemberCount  = (from x in enumTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Member") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEnum;

            odcmModel.TryResolveType(enumTypeTestNode.Name, enumTypeTestNode.Namespace, 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");
        }
Ejemplo n.º 32
0
        public void When_primitive_does_not_exist_it_skips_addition()
        {
            var customPropertyName = string.Empty;

            var testCase = new EdmxTestCase()
                           .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) =>
            {
                var property       = Any.Csdl.Property("Edm.Boolean!");
                customPropertyName = property.Attribute("Name").Value;
                entityType.Add(property);
            });

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            var createdType = odcmModel.EntityContainer.Namespace.Types.Where(x => x.FullName == customPropertyName);

            var createdPrimitive = odcmModel.EntityContainer.Namespace.Classes.Where(x => x.Properties.Where(y => y.Type.FullName == "Edm.Boolean!").Count() > 0);

            createdType.Should().BeEmpty("because the invalid property should have been skipped");
            createdPrimitive.Should().BeEmpty("because the invalid primitive should have been skipped");
        }
        public void When_OpenType_is_set_it_returns_an_OdcmClass_with_IsOpen_set()
        {
            var testCase = new EdmxTestCase()
                           .AddComplexType(EdmxTestCase.Keys.ComplexType, (_, complexType) => complexType.AddAttribute("OpenType", true));

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;

            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
            .Should()
            .BeOfType <OdcmComplexClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As <OdcmComplexClass>().IsOpen
            .Should()
            .BeTrue("because a complex type with the OpenType facet set should be open in the OdcmModel");
        }
        public void It_returns_one_OdcmComplexClass_for_each_ComplexType()
        {
            var testCase = new EdmxTestCase()
                .AddComplexType(EdmxTestCase.Keys.ComplexType);

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];
            var propertyCount = (from x in complexTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Property") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;
            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
                .Should()
                .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
                .Should()
                .BeOfType<OdcmComplexClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As<OdcmComplexClass>().Properties.Count
                .Should()
                .Be(propertyCount, "because each property added to a complex type should result in an OdcmClass property");
        }
        public void It_returns_one_OdcmComplexClass_for_each_ComplexType()
        {
            var testCase = new EdmxTestCase()
                           .AddComplexType(EdmxTestCase.Keys.ComplexType);

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];
            var propertyCount       = (from x in complexTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Property") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;

            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
            .Should()
            .BeOfType <OdcmComplexClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As <OdcmComplexClass>().Properties.Count
            .Should()
            .Be(propertyCount, "because each property added to a complex type should result in an OdcmClass property");
        }
        public void When_No_Underlying_Type_is_set_it_returns_an_OdcmEnum_with_a_Default_UnderlyingType()
        {
            var testCase = new EdmxTestCase()
                .AddEnumType(EdmxTestCase.Keys.EnumType);

            var enumTypeTestNode = testCase[EdmxTestCase.Keys.EnumType];
            var enumMemberCount = (from x in enumTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("Member") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmEnum;
            odcmModel.TryResolveType(enumTypeTestNode.Name, enumTypeTestNode.Namespace, 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");
            odcmEnum.As<OdcmEnum>().UnderlyingType.FullName
                .Should()
                .Be(Any.Csdl.DefaultEnumUnderlyingType(),
                    "because an enum type without an explicit underlying type in the schema should have the default underlying type in an OdcmEnum");
        }
        public void It_returns_one_OdcmType_for_each_TypeDefinitionType()
        {
            var underlyingType = Any.Csdl.RandomPrimitiveType();

            var testCase = new EdmxTestCase()
                .AddTypeDefinitionType(EdmxTestCase.Keys.TypeDefinitionType, (_, typeDefinitionType) => typeDefinitionType.AddAttribute("UnderlyingType", underlyingType));

            var typeDefinitionTypeTestNode = testCase[EdmxTestCase.Keys.TypeDefinitionType];
            
            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmTypeDefinition;
            odcmModel.TryResolveType(typeDefinitionTypeTestNode.Name, typeDefinitionTypeTestNode.Namespace, out odcmTypeDefinition)
                .Should()
                .BeTrue("because a typedefinition type in the schema should result in an OdcmType");

            odcmTypeDefinition.Should().BeOfType<OdcmTypeDefinition>("because a typedefinition type in the schema should result in an OdcmTypeDefinition");
            
            odcmTypeDefinition.As<OdcmTypeDefinition>().BaseType.FullName
                .Should()
                .Be(underlyingType,
                    "because a typedefintion type with a underlying type in the schema should have the specified underlying type in an OdcmTypeDefinition");
        }
        public void When_BaseType_is_set_it_returns_an_OdcmClass_with_a_BaseType_set()
        {
            var testCase = new EdmxTestCase()
                           .AddComplexType(EdmxTestCase.Keys.ComplexTypeBase, (_, complexType) => complexType.AddAttribute("Abstract", true))
                           .AddComplexType(EdmxTestCase.Keys.ComplexType, (_, complexType) => complexType.AddAttribute("BaseType", _[EdmxTestCase.Keys.ComplexTypeBase].FullName()));

            var baseComplexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexTypeBase];
            var complexTypeTestNode     = testCase[EdmxTestCase.Keys.ComplexType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());


            OdcmType odcmBaseType;

            odcmModel.TryResolveType(baseComplexTypeTestNode.Name, baseComplexTypeTestNode.Namespace, out odcmBaseType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmBaseType
            .Should()
            .BeOfType <OdcmComplexClass>("because complex types should result in an OdcmClass");
            OdcmType odcmComplexType;

            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
            .Should()
            .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
            .Should()
            .BeOfType <OdcmComplexClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As <OdcmComplexClass>().Base
            .Should()
            .Be(odcmBaseType,
                "because a complex type with a base type set should have a corresponding OdcmClass and base OdcmClass");
            odcmBaseType.As <OdcmComplexClass>().Derived
            .Should()
            .Contain(odcmComplexType.As <OdcmComplexClass>(),
                     "because a complex type with a base type set should have a correspond OdcmClass that derives from a base OdcmClass");
        }
Ejemplo n.º 39
0
        public void It_returns_one_OdcmType_for_each_TypeDefinitionType()
        {
            var underlyingType = Any.Csdl.RandomPrimitiveType();

            var testCase = new EdmxTestCase()
                           .AddTypeDefinitionType(EdmxTestCase.Keys.TypeDefinitionType, (_, typeDefinitionType) => typeDefinitionType.AddAttribute("UnderlyingType", underlyingType));

            var typeDefinitionTypeTestNode = testCase[EdmxTestCase.Keys.TypeDefinitionType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmTypeDefinition;

            odcmModel.TryResolveType(typeDefinitionTypeTestNode.Name, typeDefinitionTypeTestNode.Namespace, out odcmTypeDefinition)
            .Should()
            .BeTrue("because a typedefinition type in the schema should result in an OdcmType");

            odcmTypeDefinition.Should().BeOfType <OdcmTypeDefinition>("because a typedefinition type in the schema should result in an OdcmTypeDefinition");

            odcmTypeDefinition.As <OdcmTypeDefinition>().BaseType.FullName
            .Should()
            .Be(underlyingType,
                "because a typedefintion type with a underlying type in the schema should have the specified underlying type in an OdcmTypeDefinition");
        }
        public void When_BaseType_is_set_it_returns_an_OdcmClass_with_a_BaseType_set()
        {
            var testCase = new EdmxTestCase()
                .AddComplexType(EdmxTestCase.Keys.ComplexTypeBase, (_, complexType) => complexType.AddAttribute("Abstract", true))
                .AddComplexType(EdmxTestCase.Keys.ComplexType, (_, complexType) => complexType.AddAttribute("BaseType", _[EdmxTestCase.Keys.ComplexTypeBase].FullName()));

            var baseComplexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexTypeBase];
            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());


            OdcmType odcmBaseType;
            odcmModel.TryResolveType(baseComplexTypeTestNode.Name, baseComplexTypeTestNode.Namespace, out odcmBaseType)
                .Should()
                .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmBaseType
                .Should()
                .BeOfType<OdcmComplexClass>("because complex types should result in an OdcmClass");
            OdcmType odcmComplexType;
            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
                .Should()
                .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
                .Should()
                .BeOfType<OdcmComplexClass>("because complex types should result in an OdcmClass");
            odcmComplexType.As<OdcmComplexClass>().Base
                .Should()
                .Be(odcmBaseType,
                    "because a complex type with a base type set should have a corresponding OdcmClass and base OdcmClass");
            odcmBaseType.As<OdcmComplexClass>().Derived
                .Should()
                .Contain(odcmComplexType.As<OdcmComplexClass>(),
                    "because a complex type with a base type set should have a correspond OdcmClass that derives from a base OdcmClass");
        }
        public void When_a_Property_references_a_ComplexType_it_returns_an_OdcmEntityClass_with_a_property_having_the_corresponding_OdcmComplexType()
        {
            string complexTypePropertyName = string.Empty;

            var testCase = new EdmxTestCase()
                .AddComplexType(EdmxTestCase.Keys.ComplexType)
                .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) =>
                {
                    var property = Any.Csdl.Property(_[EdmxTestCase.Keys.ComplexType].FullName());
                    complexTypePropertyName = property.Attribute("Name").Value;
                    entityType.Add(property);
                });

            var complexTypeTestNode = testCase[EdmxTestCase.Keys.ComplexType];
            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];
            var keyCount = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("PropertyRef") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());

            OdcmType odcmComplexType;
            odcmModel.TryResolveType(complexTypeTestNode.Name, complexTypeTestNode.Namespace, out odcmComplexType)
                .Should()
                .BeTrue("because a complex type in the schema should result in an OdcmType");
            odcmComplexType
                .Should()
                .BeOfType<OdcmComplexClass>("because complex types should result in an OdcmComplexClass");
            OdcmType odcmEntityType;
            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
                .Should()
                .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
                .Should()
                .BeOfType<OdcmEntityClass>("because entity types should result in an OdcmEntityClass");
            var complexProperty = (from property in odcmEntityType.As<OdcmEntityClass>().Properties
                                   where property.Name.Equals(complexTypePropertyName)
                                   select property).FirstOrDefault();
            complexProperty
                .Should()
                .NotBeNull("because a property referencing a complex type should result in a property in the OdcmEntityClass");
            complexProperty.Type
                .Should()
                .Be(odcmComplexType, "because a property referencing a complex type should result in a property with a type matching the OdcmComplexClass of the property");
        }
        public void When_a_function_is_bound_to_an_entity_type_there_is_a_method_on_the_OdcmClass()
        {
            var testCase = new EdmxTestCase()
                .AddEntityType(EdmxTestCase.Keys.EntityType)
                .AddBoundFunction(EdmxTestCase.Keys.Function, EdmxTestCase.Keys.EntityType);

            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];
            var functionTestNode = testCase[EdmxTestCase.Keys.Function];
            var parameterCount = (from x in functionTestNode.Element.Descendants() where x.Name.LocalName.Equals("Parameter") select x).Count() - 1;
            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());


            OdcmType odcmEntityType;
            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
                .Should()
                .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
                .Should()
                .BeOfType<OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As<OdcmEntityClass>().Methods
                .Should()
                .Contain(odcmMethod => odcmMethod.Name == functionTestNode.Name, "because a function bound to an entity type should result in a method in the OdcmClass");
            odcmEntityType.As<OdcmEntityClass>()
                .Methods.Find(odcmMethod => odcmMethod.Name == functionTestNode.Name)
                .Parameters.Count
                .Should()
                .Be(parameterCount,
                    "because for each parameter in the action there should be a OdcmParameter in the OdcmMethod");
        }
        public void When_BaseType_is_set_and_both_have_Keys_it_returns_an_OdcmEntityClass_using_Key_of_derived_EntityType()
        {
            var testCase = new EdmxTestCase()
                .AddEntityType(EdmxTestCase.Keys.EntityTypeBase, (_, entityType) => entityType.AddAttribute("Abstract", true))
                .AddEntityType(EdmxTestCase.Keys.EntityType, (_, entityType) => entityType.AddAttribute("BaseType", _[EdmxTestCase.Keys.EntityTypeBase].FullName()));

            var baseEntityTypeTestNode = testCase[EdmxTestCase.Keys.EntityTypeBase];
            var entityTypeTestNode = testCase[EdmxTestCase.Keys.EntityType];
            var keyCount = (from x in entityTypeTestNode.Element.Descendants() where x.Name.LocalName.Equals("PropertyRef") select x).Count();

            var odcmModel = _odcmReader.GenerateOdcmModel(testCase.ServiceMetadata());
            
            OdcmType odcmBaseType;
            odcmModel.TryResolveType(baseEntityTypeTestNode.Name, baseEntityTypeTestNode.Namespace, out odcmBaseType)
                .Should()
                .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmBaseType
                .Should()
                .BeOfType<OdcmEntityClass>("because entity types should result in an OdcmClass");
            OdcmType odcmEntityType;
            odcmModel.TryResolveType(entityTypeTestNode.Name, entityTypeTestNode.Namespace, out odcmEntityType)
                .Should()
                .BeTrue("because an entity type in the schema should result in an OdcmType");
            odcmEntityType
                .Should()
                .BeOfType<OdcmEntityClass>("because entity types should result in an OdcmClass");
            odcmEntityType.As<OdcmEntityClass>().Base
                .Should()
                .Be(odcmBaseType,
                    "because an entity type with a base type set should have a corresponding OdcmClass and base OdcmClass");
            odcmBaseType.As<OdcmEntityClass>().Derived
                .Should()
                .Contain(odcmEntityType.As<OdcmEntityClass>(),
                    "because an entity type with a base type set should have a correspond OdcmClass that derives from a base OdcmClass");
            odcmEntityType.As<OdcmEntityClass>().Key
                .Count().Should().Be(keyCount, "because the Key of an OdcmEntityClass should have the same number of OdcmProperties as there are properties in the entity type key");
            (from key in odcmEntityType.As<OdcmEntityClass>().Key
             where
                 (from x in entityTypeTestNode.Element.Descendants()
                  where x.Name.LocalName.Equals("PropertyRef") && x.GetAttribute("Name").Equals(key.CanonicalName())
                  select x).Any()
             select key).Count().Should().Be(keyCount, "because the Key of an OdcmEntityClass should have the corresponding OdcmProperties as in the entity type key");
        }