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");
        }
예제 #2
0
        private OdcmModel GetOdcmModel(XElement edmxElement)
        {
            var serviceMetadata = new List <TextFile>
            {
                new TextFile("$metadata", edmxElement.ToString())
            };

            var odcmModel = _odcmReader.GenerateOdcmModel(serviceMetadata);

            return(odcmModel);
        }
예제 #3
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");
        }
        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");
        }
예제 #5
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 DeleteRestrictions_should_be_properly_parsed()
        {
            OdcmReader odata4Reader = new OdcmReader();
            OdcmModel model = odata4Reader.GenerateOdcmModel(GetOneNoteEdmModel());

            model.EntityContainer.Properties.Should().Contain(prop => prop.Name == "notebooks");

            var notebookProperty = model.EntityContainer.Properties.First(prop => prop.Name == "notebooks");

            var deleteRestriction = notebookProperty.Annotations.Should()
                .Contain(an => an.Name == "DeleteRestrictions" && an.Namespace == "Org.OData.Capabilities.V1").Which;

            var annotationValue = deleteRestriction.Value.Should().BeOfType<DeleteRestrictionsType>().Which;

            annotationValue.Deletable.Should().BeFalse();
            annotationValue.NonDeletableNavigationProperties.Should().HaveCount(2).And.Contain("sectionGroups").And.Contain("sections");
        }
        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 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");
        }