Exemplo n.º 1
0
        public void ExceptionThrowForInvalidPropertyPath()
        {
            EdmModel model = new EdmModel();

            EdmEntityType personType = new EdmEntityType("MyNs", "Person", null, false, false, true);

            personType.AddKeys(personType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true));

            var container = new EdmEntityContainer("MyNs", "Container");

            model.AddElement(personType);
            container.AddEntitySet("People", personType);
            model.AddElement(container);
            IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");

            IEdmPathExpression nameExpression = new EdmPropertyPathExpression("NameName");

            IEdmCollectionExpression collection = new EdmCollectionExpression(new[] { nameExpression });
            IEdmValueTerm            term       = null;

            foreach (var referencedModel in model.ReferencedModels)
            {
                term = referencedModel.FindDeclaredValueTerm("Org.OData.Core.V1.OptimisticConcurrencyControl");

                if (term != null)
                {
                    break;
                }
            }

            Assert.IsNotNull(term);

            EdmAnnotation valueAnnotationOnEntitySet = new EdmAnnotation(peopleSet, term, collection);

            valueAnnotationOnEntitySet.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotationOnEntitySet);

            ODataEntry entry = new ODataEntry
            {
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "ID", Value = 123
                    },
                    new ODataProperty {
                        Name = "Name", Value = "lucy"
                    },
                }
            };

            Action action = () => GetWriterOutputForContentTypeAndKnobValue(entry, model, peopleSet, personType);

            action.ShouldThrow <ODataException>().WithMessage(ErrorStrings.EdmValueUtils_PropertyDoesntExist("MyNs.Person", "NameName"));
        }
Exemplo n.º 2
0
        public void FindPropertyTest_ThrowsForResourceTypeNotInModel()
        {
            // Arrange
            EdmPropertyPathExpression path    = new EdmPropertyPathExpression("Location/NS.AnotherType");
            IEdmEntityType            company = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Company");

            Assert.NotNull(company);

            // Act & Assert
            Action test = () => _model.FindProperty(company, path);

            ExceptionAssert.Throws <ODataException>(test, "Cannot find the resource type 'NS.AnotherType' in the model.");
        }
Exemplo n.º 3
0
        public void FindPropertyTest_ThrowsForPropertyNotFoundOnPathExpression()
        {
            // Arrange
            EdmPropertyPathExpression path    = new EdmPropertyPathExpression("OtherPath");
            IEdmEntityType            company = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Company");

            Assert.NotNull(company);

            // Act & Assert
            Action test = () => _model.FindProperty(company, path);

            ExceptionAssert.Throws <ODataException>(test, "Can not resolve the property using property path 'OtherPath' from type 'NS.Company'.");
        }
Exemplo n.º 4
0
        public void BuildEdmExpression_Works_ForPropertyPathValue()
        {
            // Arrange
            IEdmPathType pathType = EdmCoreModel.Instance.GetPathType(EdmPathTypeKind.PropertyPath);

            // Act
            IEdmExpression exp = IEdmTermExtensions.BuildEdmExpression(pathType, "HomeAddress/City");

            // Assert
            Assert.NotNull(exp);
            EdmPropertyPathExpression constant = Assert.IsType <EdmPropertyPathExpression>(exp);

            Assert.Equal("HomeAddress/City", constant.Path);
        }
Exemplo n.º 5
0
        public void FindPropertyTest_WorksForDirectPropertyOnType(string pathStr, string name)
        {
            // Arrange
            EdmPropertyPathExpression path    = new EdmPropertyPathExpression(pathStr);
            IEdmEntityType            company = _model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Company");

            Assert.NotNull(company);

            // Act
            IEdmProperty property = _model.FindProperty(company, path);

            // Assert
            Assert.NotNull(property);
            Assert.Equal(name, property.Name);
        }
 /// <summary>
 /// Path to the restricted property
 /// </summary>
 /// <param name="property">The value to set</param>
 /// <returns><see cref="FilterExpressionRestrictionTypeConfiguration"/></returns>
 public FilterExpressionRestrictionTypeConfiguration HasProperty(EdmPropertyPathExpression property)
 {
     _property = property;
     return(this);
 }
 /// <summary>
 /// Restricted Collection-valued property
 /// </summary>
 /// <param name="collectionProperty">The value to set</param>
 /// <returns><see cref="CollectionPropertyRestrictionsTypeConfiguration"/></returns>
 public CollectionPropertyRestrictionsTypeConfiguration HasCollectionProperty(EdmPropertyPathExpression collectionProperty)
 {
     _collectionProperty = collectionProperty;
     return(this);
 }