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");
        }
 private void VerifyInheritanceLink(OdcmType odcmBaseType, OdcmType odcmEntityType)
 {
     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");
 }
        private void VerifyKey(EdmxTestCase.TestNode entityTypeNode, OdcmType odcmEntityType)
        {
            var entityTypeDescendants = entityTypeNode.Element.Descendants();
            var properties            = entityTypeDescendants.Where(x => x.Name.LocalName == "PropertyRef");
            var keyCount = properties.Count();

            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");

            odcmEntityType.As <OdcmEntityClass>().Key
            .Count(key => properties.Any(x => x.GetName() == key.CanonicalName()))
            .Should().Be(keyCount, "because the Key of an OdcmEntityClass should have the corresponding OdcmProperties as in the entity type key");
        }
        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_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_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 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 = VerifyEntityType(odcmModel, testCase[EdmxTestCase.Keys.EntityType]);

            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");
        }