public ODataSingletonDeserializerTest()
        {
            EdmModel model = new EdmModel();
            var employeeType = new EdmEntityType("NS", "Employee");
            employeeType.AddStructuralProperty("EmployeeId", EdmPrimitiveTypeKind.Int32);
            employeeType.AddStructuralProperty("EmployeeName", EdmPrimitiveTypeKind.String);
            model.AddElement(employeeType);

            EdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "Default");
            model.AddElement(defaultContainer);

            _singleton = new EdmSingleton(defaultContainer, "CEO", employeeType);
            defaultContainer.AddElement(_singleton);

            model.SetAnnotationValue<ClrTypeAnnotation>(employeeType, new ClrTypeAnnotation(typeof(EmployeeModel)));

            _edmModel = model;
            _edmContainer = defaultContainer;

            _readContext = new ODataDeserializerContext
            {
                Path = new ODataPath(new SingletonPathSegment(_singleton)),
                Model = _edmModel,
                ResourceType = typeof(EmployeeModel)
            }; 

            _deserializerProvider = new DefaultODataDeserializerProvider();
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmActionImport"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="name">The name.</param>
        /// <param name="action">The action.</param>
        /// <param name="entitySetExpression">The entity set expression.</param>
        public EdmActionImport(IEdmEntityContainer container, string name, IEdmAction action, IEdmExpression entitySetExpression)
            : base(container, action, name, entitySetExpression)
        {
            EdmUtil.CheckArgumentNull(action, "action");

            this.Action = action;
        }
Пример #3
0
 public static bool IsDefaultEntityContainer(this IEdmModel model, IEdmEntityContainer entityContainer)
 {
     bool flag;
     ExceptionUtils.CheckArgumentNotNull<IEdmModel>(model, "model");
     ExceptionUtils.CheckArgumentNotNull<IEdmEntityContainer>(entityContainer, "entityContainer");
     return (TryGetBooleanAnnotation(model, entityContainer, "IsDefaultEntityContainer", out flag) && flag);
 }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmFunctionImport"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="name">The name.</param>
        /// <param name="function">The function.</param>
        /// <param name="entitySetExpression">The entity set expression.</param>
        /// <param name="includeInServiceDocument">The value indicates if the function is to be include in the service document or not.</param>
        public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmFunction function, IEdmExpression entitySetExpression, bool includeInServiceDocument)
            : base(container, function, name, entitySetExpression)
        {
            EdmUtil.CheckArgumentNull(function, "function");

            this.Function = function;
            this.IncludeInServiceDocument = includeInServiceDocument;
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmEntitySet"/> class.
        /// </summary>
        /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this entity set.</param>
        /// <param name="name">Name of the entity set.</param>
        /// <param name="elementType">The entity type of the elements in this entity set.</param>
        public EdmEntitySet(IEdmEntityContainer container, string name, IEdmEntityType elementType)
            : base(name, elementType)
        {
            EdmUtil.CheckArgumentNull(container, "container");

            this.container = container;
            this.type = new EdmCollectionType(new EdmEntityTypeReference(elementType, false));
            this.path = new EdmPathExpression(this.container.FullName() + "." + this.Name);
        }
        public void Initialize()
        {
            this.model = Utils.BuildModel("Default.ExtendedNamespace");
            this.defaultContainer = model.EntityContainer;

            this.peopleSet = this.defaultContainer.FindEntitySet("People");
            this.placesSet = this.defaultContainer.FindEntitySet("Places");
            this.organizationsSet = this.defaultContainer.FindEntitySet("Organizations");
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmEntitySet"/> class.
        /// </summary>
        /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this entity set.</param>
        /// <param name="name">Name of the entity set.</param>
        /// <param name="elementType">The entity type of the elements in this entity set.</param>
        public EdmEntitySet(IEdmEntityContainer container, string name, IEdmEntityType elementType)
            : base(name)
        {
            EdmUtil.CheckArgumentNull(container, "container");
            EdmUtil.CheckArgumentNull(elementType, "elementType");

            this.container = container;
            this.elementType = elementType;
        }
        public MetadataUriRoundTripTests()
        {
            this.model = Utils.BuildModel("Default.ExtendedNamespace");
            this.defaultContainer = model.EntityContainer;

            this.peopleSet = this.defaultContainer.FindEntitySet("People");
            this.placesSet = this.defaultContainer.FindEntitySet("Places");
            this.organizationsSet = this.defaultContainer.FindEntitySet("Organizations");
        }
Пример #9
0
		public EdmEntitySet(IEdmEntityContainer container, string name, IEdmEntityType elementType) : base(name)
		{
			this.navigationPropertyMappings = new Dictionary<IEdmNavigationProperty, IEdmEntitySet>();
			this.navigationTargetsCache = new Cache<EdmEntitySet, IEnumerable<IEdmNavigationTargetMapping>>();
			EdmUtil.CheckArgumentNull<IEdmEntityContainer>(container, "container");
			EdmUtil.CheckArgumentNull<IEdmEntityType>(elementType, "elementType");
			this.container = container;
			this.elementType = elementType;
		}
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmSingleton"/> class.
        /// </summary>
        /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this entity set.</param>
        /// <param name="name">Name of the singleton.</param>
        /// <param name="entityType">The entity type of the element of this singleton.</param>
        public EdmSingleton(IEdmEntityContainer container, string name, IEdmEntityType entityType)
            : base(name)
        {
            EdmUtil.CheckArgumentNull(container, "container");
            EdmUtil.CheckArgumentNull(entityType, "entityType");

            this.container = container;
            this.entityType = entityType;
            this.path = new EdmPathExpression(name);
        }
Пример #11
0
		public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmTypeReference returnType, IEdmExpression entitySet, bool isSideEffecting, bool isComposable, bool isBindable) : base(name, returnType)
		{
			EdmUtil.CheckArgumentNull<IEdmEntityContainer>(container, "container");
			EdmUtil.CheckArgumentNull<string>(name, "name");
			this.container = container;
			this.entitySet = entitySet;
			this.isSideEffecting = isSideEffecting;
			this.isComposable = isComposable;
			this.isBindable = isBindable;
		}
Пример #12
0
		public BadEntitySet(string name, IEdmEntityContainer container, IEnumerable<EdmError> errors) : base(errors)
		{
			string str = name;
			string empty = str;
			if (str == null)
			{
				empty = string.Empty;
			}
			this.name = empty;
			this.container = container;
		}
 public UnboundFunctionPathSegmentTest()
 {
     ODataModelBuilder builder = new ODataModelBuilder();
     builder.EntityType<MyCustomer>().HasKey(c => c.Id).Property(c => c.Name);
     builder.EntitySet<MyCustomer>("Customers");
     FunctionConfiguration function = builder.Function("TopCustomer");
     function.ReturnsFromEntitySet<MyCustomer>("Customers");
     builder.Function("MyFunction").Returns<string>();
     _model = builder.GetEdmModel();
     _container = _model.EntityContainers().Single();
 }
 public UnboundActionPathSegmentTest()
 {
     ODataModelBuilder builder = new ODataModelBuilder();
     builder.EntityType<MyCustomer>().HasKey(c => c.Id).Property(c => c.Name);
     builder.EntitySet<MyCustomer>("Customers");
     ActionConfiguration action = builder.Action("CreateCustomer");
     action.ReturnsFromEntitySet<MyCustomer>("Customers");
     builder.Action("MyAction").Returns<string>();
     builder.Action("ActionWithoutReturn");
     _model = builder.GetEdmModel();
     _container = _model.EntityContainer;
 }
        public static void SetConformanceLevelCapabilitiesAnnotation(this EdmModel model, IEdmEntityContainer container, CapabilitiesConformanceLevelType level)
        {
            if (model == null) throw new ArgumentNullException("model");
            if (container == null) throw new ArgumentNullException("container");

            var target = container;
            var term = ConformanceLevelTerm;
            var name = new EdmEnumTypeReference(ConformanceLevelTypeType, false).ToStringLiteral((long)level);
            var expression = new EdmEnumMemberReferenceExpression(ConformanceLevelTypeType.Members.Single(m => m.Name == name));
            var annotation = new EdmAnnotation(target, term, expression);
            annotation.SetSerializationLocation(model, container.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
		protected override void ProcessEntityContainer(IEdmEntityContainer element)
		{
			EdmSchema edmSchema = null;
			string @namespace = element.Namespace;
			if (!this.modelSchemas.TryGetValue(@namespace, out edmSchema))
			{
				edmSchema = new EdmSchema(@namespace);
				this.modelSchemas.Add(edmSchema.Namespace, edmSchema);
			}
			edmSchema.AddEntityContainer(element);
			this.activeSchema = edmSchema;
			base.ProcessEntityContainer(element);
		}
Пример #17
0
        /// <summary>
        /// Initializes a new instance of <see cref="EdmOperationImport"/> class.
        /// </summary>
        /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this operation import.</param>
        /// <param name="operation">The operation of the import.</param>
        /// <param name="name">Name of the operation import.</param>
        /// <param name="entitySet">An entity set containing entities returned by this operation import. 
        /// The two expression kinds supported are <see cref="IEdmEntitySetReferenceExpression"/> and <see cref="IEdmPathExpression"/>.</param>
        protected EdmOperationImport(
            IEdmEntityContainer container,
            IEdmOperation operation,
            string name,
            IEdmExpression entitySet)
            : base(name)
        {
            EdmUtil.CheckArgumentNull(container, "container");
            EdmUtil.CheckArgumentNull(operation, this.OperationArgumentNullParameterName());

            this.Container = container;
            this.Operation = operation;
            this.EntitySet = entitySet;
        }
        public void TestInitialize()
        {
            this.testModel = Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            this.defaultContainer = this.testModel.EntityContainer;

            this.personSet = this.defaultContainer.FindEntitySet("Persons");
            this.personType = (IEdmEntityType)this.testModel.FindType("TestModel.Person");
            this.employeeType = (IEdmEntityType)this.testModel.FindType("TestModel.Employee");
            this.officeType = (IEdmEntityType)this.testModel.FindType("TestModel.OfficeType");
            this.addressType = (IEdmComplexType)this.testModel.FindType("TestModel.Address");
            this.metropolitanCitySet = this.defaultContainer.FindEntitySet("MetropolitanCities");
            this.metropolitanCityType = (IEdmEntityType)this.testModel.FindType("TestModel.MetropolitanCityType");
            this.boss = this.defaultContainer.FindSingleton("Boss");
            this.containedOfficeNavigationProperty = (IEdmNavigationProperty)this.metropolitanCityType.FindProperty("ContainedOffice");
            this.containedOfficeSet = (IEdmContainedEntitySet)metropolitanCitySet.FindNavigationTarget(this.containedOfficeNavigationProperty);
            this.containedMetropolitanCityNavigationProperty = (IEdmNavigationProperty)this.officeType.FindProperty("ContainedCity");
            this.containedMetropolitanCitySet = (IEdmContainedEntitySet)containedOfficeSet.FindNavigationTarget(this.containedMetropolitanCityNavigationProperty);
        }
Пример #19
0
        internal string GetElementTypeName(IEdmEntityType elementType, IEdmEntityContainer container)
        {
            var elementTypeName = elementType.Name;

            if (Context.EnableNamingAlias)
            {
                elementTypeName = Customization.CustomizeNaming(elementTypeName);
            }

            if (elementType.Namespace != container.Namespace)
            {
                elementTypeName = Context.GetPrefixedFullName(elementType, GetFixedName(elementTypeName), this);
            }

            return elementTypeName;
        }
Пример #20
0
        public void FeedReaderErrorTest()
        {
            IEdmModel           model           = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container       = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet = container.FindEntitySet("Cities");
            IEdmType            cityType        = model.FindType("TestModel.CityType") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                #region Test cases
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with OData property annotation before top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with OData property annotation after top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with invalid feed property value.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":{}" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_CannotReadFeedContentStart", "StartObject")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with primitive item in feed property value.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1 ]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_InvalidNodeTypeForItemsInFeed", "PrimitiveValue")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with array item in feed property value.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ [] ]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_InvalidNodeTypeForItemsInFeed", "StartArray")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"other\":\"42\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_InvalidPropertyInTopLevelFeed", "other", JsonLightConstants.ODataValuePropertyName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName("other", JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"other\":\"42\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_InvalidPropertyInTopLevelFeed", "other", JsonLightConstants.ODataValuePropertyName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName("other", JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with missing feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_ExpectedFeedPropertyNotFound", "value")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with odata.count annotation with null value before top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":null," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with odata.nextLink annotation with null value before top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":null," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataNextLinkAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with odata.nextLink annotation with null value after top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":null" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataNextLinkAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with duplicate feed properties.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", JsonLightConstants.ODataValuePropertyName)
                },
                #endregion Test cases
            };

            // TODO: all of the above for feeds in expanded navigation links

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Пример #21
0
        internal static IEdmEntityContainer CreateAmbiguousEntityContainerBinding(IEdmEntityContainer first, IEdmEntityContainer second)
        {
            var ambiguous = first as AmbiguousEntityContainerBinding;

            if (ambiguous != null)
            {
                ambiguous.AddBinding(second);
                return(ambiguous);
            }

            return(new AmbiguousEntityContainerBinding(first, second));
        }
Пример #22
0
		public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmTypeReference returnType, IEdmExpression entitySet) : this(container, name, returnType, entitySet, true, false, false)
		{
		}
Пример #23
0
        private static void VerifyEntitySetsAndTypes(
            IEdmModel annotatedModel, 
            out IEdmEntityContainer customersContainer, 
            out IEdmEntitySet customersSet, 
            out IEdmEntityType customerType)
        {
            customersContainer = annotatedModel.EntityContainer;
            Assert.AreEqual("CustomersContainer", customersContainer.Name);

            Assert.AreEqual(1, customersContainer.EntitySets().Count());
            customersSet = customersContainer.FindEntitySet("Customers");
            Assert.IsNotNull(customersSet);

            IEnumerable<IEdmEntityType> entityTypes = annotatedModel.SchemaElements.OfType<IEdmEntityType>();
            Assert.AreEqual(1, entityTypes.Count());
            customerType = (IEdmEntityType) annotatedModel.FindDeclaredType("MyModel.Customer");
        }
Пример #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmFunctionImport"/> class.
 /// </summary>
 /// <param name="container">The container.</param>
 /// <param name="name">The name.</param>
 /// <param name="function">The function.</param>
 public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmFunction function)
     : this(container, name, function, null, false)
 {
 }
 private static IEdmFunctionImport CreateFakeFunctionImport(IEdmEntityContainer container, string name)
 {
     Mock<IEdmFunctionImport> mock = new Mock<IEdmFunctionImport>();
     mock.Setup(o => o.Container).Returns(container);
     mock.Setup(o => o.Name).Returns(name);
     return mock.Object;
 }
Пример #26
0
 protected virtual void ProcessEntityContainer(IEdmEntityContainer container)
 {
     this.ProcessVocabularyAnnotatable(container);
     this.ProcessNamedElement(container);
     this.VisitEntityContainerElements(container.Elements);
 }
Пример #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmEntitySet"/> class.
 /// </summary>
 /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this entity set.</param>
 /// <param name="name">Name of the entity set.</param>
 /// <param name="elementType">The entity type of the elements in this entity set.</param>
 /// <param name="includeInServiceDocument">Indicates whether the entity set is advertised in the service document.</param>
 public EdmEntitySet(IEdmEntityContainer container, string name, IEdmEntityType elementType, bool includeInServiceDocument)
     : base(name, elementType)
 {
     this.includeInServiceDocument = includeInServiceDocument;
 }
Пример #28
0
        public void FeedReaderWithSubContextUriTest()
        {
            IEdmModel           model            = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container        = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet  = container.FindEntitySet("Cities");
            IEdmType            cityType         = model.FindType("TestModel.CityType") as IEdmType;
            IEdmEntitySet       personsEntitySet = container.FindEntitySet("Persons");
            IEdmType            personType       = model.FindType("TestModel.Person") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                #region Test cases
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containing entries with and without sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities/$entity\"," +
                        "\"Id\":1" +
                        "}," +
                        "{" +
                        "\"Id\":2" +
                        "}," +
                        "]" +
                        "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containing entries with expanded navigation properties with sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[] {
                        PayloadBuilder
                        .Entity("TestModel.CityType")
                        .PrimitiveProperty("Id", 1)
                        .ExpandedNavigationProperty(
                            "CityHall",
                            PayloadBuilder.EntitySet(new EntityInstance[]
                        {
                            PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                            {
                                TypeName = null
                            }),
                        }))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        })
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id,CityHall(Id))/$entity\"," +
                        "\"Id\":1," +
                        "\"CityHall\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Offices/$entity\"," +
                        "\"Id\":1" +
                        "}" +
                        "]" +
                        "}" +
                        "]" +
                        "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containg entries with mismatch sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Offices/$entity\"," +
                        "\"Id\":1" +
                        "}," +
                        "]" +
                        "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException(
                        "ReaderValidationUtils_ContextUriValidationInvalidExpectedEntitySet",
                        "http://odata.org/test/$metadata#Offices/$entity",
                        "TestModel.DefaultContainer.Offices",
                        "TestModel.DefaultContainer.Cities")
                },

                /* TODO: Enable this case after updating SelectedPropertiesNode class to adapt to V4
                 * new PayloadReaderTestDescriptor(this.Settings)
                 * {
                 *  DebugDescription = "Empty feed without next link or inline count.",
                 *  PayloadElement = PayloadBuilder.EntitySet( new EntityInstance[]
                 *  {
                 *      PayloadBuilder.Entity("TestModel.CityType")
                 *          .PrimitiveProperty("Id", 1)
                 *          .NavigationProperty(new NavigationPropertyInstance("PoliceStation",null))
                 *          .AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }),
                 *      PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }),
                 *  })
                 *      .JsonRepresentation(
                 *          "{" +
                 *              "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.CityType)\"," +
                 *              "\"" + JsonLightConstants.ODataValuePropertyName + "\":[" +
                 *                  "{" +
                 *                      "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities/$entity\"," +
                 *                      "\"Id\":1" +
                 *                  "}," +
                 *                  "{" +
                 *                      "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities/$entity\"," +
                 *                      "\"Id\":2" +
                 *                  "}," +
                 *              "]" +
                 *          "}")
                 *      .ExpectedEntityType(cityType, citiesEntitySet),
                 *  PayloadEdmModel = model
                 * },
                 */
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed without next link or inline count.",
                    PayloadElement   = PayloadBuilder.EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.Person")
                        .PrimitiveProperty("Id", 1)
                        .ExpandedNavigationProperty(
                            "Friend",
                            PayloadBuilder.EntitySet(new EntityInstance[] {}))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.Person")
                        .PrimitiveProperty("Id", 2)
                        .ExpandedNavigationProperty(
                            "Friend",
                            PayloadBuilder.EntitySet(new EntityInstance[] {}))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.Person")
                        .PrimitiveProperty("Id", 3)
                        .ExpandedNavigationProperty(
                            "Friend",
                            PayloadBuilder.EntitySet(new EntityInstance[] {}))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Collection(TestModel.Person)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"$metadata#TestModel.DefaultContainer.Persons/$entity\"," +
                        "\"Id\":1," +
                        "\"Friend\":[]" +
                        "}," +
                        "{" +
                        "\"@odata.context\":\"#Persons/$entity\"," +
                        "\"Id\":2," +
                        "\"Friend\":[]" +
                        "}," +
                        "{" +
                        "\"@odata.context\":\"#TestModel.Person\"," +
                        "\"Id\":3," +
                        "\"Friend\":[]" +
                        "}," +
                        "]" +
                        "}")
                                       .ExpectedEntityType(personType, personsEntitySet),
                    PayloadEdmModel = model
                },
                #endregion Test cases
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                if (testConfiguration.IsRequest && testDescriptor.ExpectedException != null)
                {
                    return;
                }

                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Пример #29
0
        internal void WriteEntityContainer(IEdmEntityContainer container, string fullNamespace)
        {
            var camelCaseContainerName = container.Name;
            if (Context.EnableNamingAlias)
            {
                camelCaseContainerName = Customization.CustomizeNaming(camelCaseContainerName);
            }

            WriteClassStartForEntityContainer(container.Name, camelCaseContainerName, GetFixedName(camelCaseContainerName));
            WriteEntityContainerConstructor(container);

            if (Context.NeedResolveNameFromType)
            {
                WritePropertyRootNamespace(GetFixedName(camelCaseContainerName), Context.GetPrefixedNamespace(fullNamespace, this, false, false));
            }

            WriteResolveTypeFromName();
            WriteResolveNameFromType(camelCaseContainerName, fullNamespace);

            foreach (var entitySet in container.EntitySets())
            {
                var entitySetElementType = entitySet.EntityType();
                var entitySetElementTypeName = GetElementTypeName(entitySetElementType, container);

                var camelCaseEntitySetName = entitySet.Name;
                if (Context.EnableNamingAlias)
                {
                    camelCaseEntitySetName = Customization.CustomizeNaming(camelCaseEntitySetName);
                }

                WriteContextEntitySetProperty(camelCaseEntitySetName, GetFixedName(camelCaseEntitySetName), entitySet.Name, GetFixedName(entitySetElementTypeName));
                List<IEdmNavigationSource> edmNavigationSourceList = null;
                if (!Context.ElementTypeToNavigationSourceMap.TryGetValue(entitySet.EntityType(), out edmNavigationSourceList))
                {
                    edmNavigationSourceList = new List<IEdmNavigationSource>();
                    Context.ElementTypeToNavigationSourceMap.Add(entitySet.EntityType(), edmNavigationSourceList);
                }

                edmNavigationSourceList.Add(entitySet);
            }

            foreach (var entitySet in container.EntitySets())
            {
                var entitySetElementType = entitySet.EntityType();

                var entitySetElementTypeName = GetElementTypeName(entitySetElementType, container);

                var uniqueIdentifierService = new UniqueIdentifierService(/*IsLanguageCaseSensitive*/true);
                var parameterName = GetFixedName(uniqueIdentifierService.GetUniqueParameterName(entitySetElementType.Name));

                var camelCaseEntitySetName = entitySet.Name;
                if (Context.EnableNamingAlias)
                {
                    camelCaseEntitySetName = Customization.CustomizeNaming(camelCaseEntitySetName);
                }

                WriteContextAddToEntitySetMethod(camelCaseEntitySetName, entitySet.Name, GetFixedName(entitySetElementTypeName), parameterName);
            }

            foreach (var singleton in container.Singletons())
            {
                var singletonElementType = singleton.EntityType();
                var singletonElementTypeName = GetElementTypeName(singletonElementType, container);
                var camelCaseSingletonName = singleton.Name;
                if (Context.EnableNamingAlias)
                {
                    camelCaseSingletonName = Customization.CustomizeNaming(camelCaseSingletonName);
                }

                WriteContextSingletonProperty(camelCaseSingletonName, GetFixedName(camelCaseSingletonName), singleton.Name, singletonElementTypeName + "Single");

                List<IEdmNavigationSource> edmNavigationSourceList = null;
                if (Context.ElementTypeToNavigationSourceMap.TryGetValue(singleton.EntityType(), out edmNavigationSourceList))
                {
                    edmNavigationSourceList.Add(singleton);
                }
            }

            WriteGeneratedEdmModel(Utils.SerializeToString(Context.Edmx).Replace("\"", "\"\""));

            var hasOperationImport = container.OperationImports().OfType<IEdmOperationImport>().Any();
            foreach (var functionImport in container.OperationImports().OfType<IEdmFunctionImport>())
            {
                string parameterString, parameterTypes, parameterExpressionString, parameterValues;
                bool useEntityReference;
                GetParameterStrings(false, false, functionImport.Function.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference);
                var returnTypeName = GetSourceOrReturnTypeName(functionImport.Function.ReturnType);
                var fixedContainerName = GetFixedName(functionImport.Container.Name);
                var isCollectionResult = functionImport.Function.ReturnType.IsCollection();
                var functionImportName = functionImport.Name;
                if (Context.EnableNamingAlias)
                {
                    functionImportName = Customization.CustomizeNaming(functionImportName);
                    fixedContainerName = Customization.CustomizeNaming(fixedContainerName);
                }

                if (functionImport.Function.ReturnType.IsCollection())
                {
                    WriteFunctionImportReturnCollectionResult(GetFixedName(functionImportName), functionImport.Name, returnTypeName, parameterString, parameterValues, functionImport.Function.IsComposable, useEntityReference);
                }
                else
                {
                    WriteFunctionImportReturnSingleResult(GetFixedName(functionImportName), functionImport.Name, returnTypeName, parameterString, parameterValues, functionImport.Function.IsComposable, functionImport.Function.ReturnType.IsEntity(), useEntityReference);
                }
            }

            foreach (var actionImport in container.OperationImports().OfType<IEdmActionImport>())
            {
                string parameterString, parameterTypes, parameterExpressionString, parameterValues;
                bool useEntityReference;
                GetParameterStrings(false, true, actionImport.Action.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference);
                string returnTypeName = null;
                var fixedContainerName = GetFixedName(actionImport.Container.Name);

                if (actionImport.Action.ReturnType != null)
                {
                    returnTypeName = GetSourceOrReturnTypeName(actionImport.Action.ReturnType);
                    if (actionImport.Action.ReturnType.IsCollection())
                    {
                        returnTypeName = string.Format(DataServiceActionQueryOfTStructureTemplate, returnTypeName);
                    }
                    else
                    {
                        returnTypeName = string.Format(DataServiceActionQuerySingleOfTStructureTemplate, returnTypeName);
                    }
                }
                else
                {
                    returnTypeName = DataServiceActionQueryTypeName;
                }

                var actionImportName = actionImport.Name;
                if (Context.EnableNamingAlias)
                {
                    actionImportName = Customization.CustomizeNaming(actionImportName);
                    fixedContainerName = Customization.CustomizeNaming(fixedContainerName);
                }

                WriteActionImport(GetFixedName(actionImportName), actionImport.Name, returnTypeName, parameterString, parameterValues);
            }

            WriteClassEndForEntityContainer();
        }
        public void CollectionReaderTest()
        {
            IEdmModel           model     = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container = model.FindEntityContainer("DefaultContainer");
            EdmOperationImport  primitiveCollectionResultOperation = container.FindOperationImports("PrimitiveCollectionResultOperation").Single() as EdmOperationImport;
            EdmOperationImport  complexCollectionResultOperation   = container.FindOperationImports("ComplexCollectionResultOperation").Single() as EdmOperationImport;

            var primitiveCollection = PayloadBuilder.PrimitiveCollection("PrimitiveCollectionResultOperation");

            primitiveCollection.Add(PayloadBuilder.PrimitiveValue(1));
            primitiveCollection.Add(PayloadBuilder.PrimitiveValue(2));
            primitiveCollection.Add(PayloadBuilder.PrimitiveValue(3));

            var complexCollection = PayloadBuilder.ComplexCollection("ComplexCollectionResultOperation");
            var complexValue1     = PayloadBuilder.ComplexValue("TestModel.Address")
                                    .PrimitiveProperty("Street", "Am Euro Platz")
                                    .AddAnnotation(new SerializationTypeNameTestAnnotation()
            {
                TypeName = null
            });

            complexCollection.Add(complexValue1);

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Primitive collection - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Complex collection - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.Address)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\":\"Am Euro Platz\" } ] }")
                                       .ExpectedFunctionImport(complexCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null collection - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy().JsonRepresentation("null")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Primitive value for collection - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy().JsonRepresentation("42")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Array value for collection - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy().JsonRepresentation("[]")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Extra property before collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"extra\": null, \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_InvalidTopLevelPropertyName", "extra", "value")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Extra property after collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ], \"extra\": null }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_CannotReadCollectionEnd", "extra")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Custom instance annotation before collection property - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"@my.extra\": null, \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Custom instance annotation after collection property - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ], \"@my.extra\": null }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "OData instance annotations before collection property - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":3," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://next-link\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "OData instance annotations after collection property - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://next-link\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":3}")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Custom property annotation before collection property - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"[email protected]\": null, \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Custom property annotation on 'value' after collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ], \"[email protected]\": null }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_CannotReadCollectionEnd", "value")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Custom property annotation on 'extra' before collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"[email protected]\": null, \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_TopLevelPropertyAnnotationWithoutProperty", "extra")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Custom property annotation on 'extra' after collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ], \"[email protected]\": null }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_CannotReadCollectionEnd", "extra")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Invalid collection property name - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"invalid\":[ 1, 2, 3 ] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_InvalidTopLevelPropertyName", "invalid", JsonLightConstants.ODataValuePropertyName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Missing collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\" }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_ExpectedCollectionPropertyNotFound", JsonLightConstants.ODataValuePropertyName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Invalid collection property value - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", \"" + JsonLightConstants.ODataValuePropertyName + "\":{} }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_CannotReadCollectionContentStart", "StartObject")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Invalid OData instance annotation before collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataEditLinkAnnotationName + "\":null, " +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[] }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataEditLinkAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Invalid OData instance annotation after collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[], " +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataEditLinkAnnotationName + "\":null }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_CannotReadCollectionEnd", JsonLightConstants.ODataEditLinkAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Invalid OData instance annotation after collection property - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[], " +

                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataEditLinkAnnotationName + "\":null }")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_CannotReadCollectionEnd", JsonLightConstants.ODataEditLinkAnnotationName)
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Пример #31
0
        internal void WriteEntityContainerConstructor(IEdmEntityContainer container)
        {
            var camelCaseContainerName = container.Name;
            if (Context.EnableNamingAlias)
            {
                camelCaseContainerName = Customization.CustomizeNaming(camelCaseContainerName);
            }

            WriteMethodStartForEntityContainerConstructor(camelCaseContainerName, GetFixedName(camelCaseContainerName));

            if (Context.UseKeyAsSegmentUrlConvention(container))
            {
                WriteKeyAsSegmentUrlConvention();
            }

            if (Context.NeedResolveNameFromType)
            {
                WriteInitializeResolveName();
            }

            if (Context.NeedResolveTypeFromName)
            {
                WriteInitializeResolveType();
            }

            WriteClassEndForEntityContainerConstructor();
        }
Пример #32
0
 /// <summary>
 /// Initializes a new instance of the StubEdmEntitySet class.
 /// </summary>
 /// <param name="name">the name of entity set</param>
 /// <param name="container">The container of the entity set</param>
 public StubEdmEntitySet(string name, IEdmEntityContainer container)
 {
     this.Name = name;
     this.Container = container;
 }
 static ODataActionPayloadDeserializerTest()
 {
     _model = GetModel();
     _container = _model.EntityContainer;
     _deserializer = new ODataActionPayloadDeserializer(new DefaultODataDeserializerProvider());
 }
Пример #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmEntitySet"/> class.
 /// </summary>
 /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this entity set.</param>
 /// <param name="name">Name of the entity set.</param>
 /// <param name="elementType">The entity type of the elements in this entity set.</param>
 public EdmEntitySet(IEdmEntityContainer container, string name, IEdmEntityType elementType)
     : this(container, name, elementType, true)
 {
 }
        public void CollectionWithODataTypeReaderTest()
        {
            IEdmModel           model     = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container = model.FindEntityContainer("DefaultContainer");
            EdmOperationImport  primitiveCollectionResultOperation = container.FindOperationImports("PrimitiveCollectionResultOperation").Single() as EdmOperationImport;
            EdmOperationImport  complexCollectionResultOperation   = container.FindOperationImports("ComplexCollectionResultOperation").Single() as EdmOperationImport;

            var primitiveCollection = PayloadBuilder.PrimitiveCollection("PrimitiveCollectionResultOperation");

            primitiveCollection.Add(PayloadBuilder.PrimitiveValue(1));
            primitiveCollection.Add(PayloadBuilder.PrimitiveValue(2));
            primitiveCollection.Add(PayloadBuilder.PrimitiveValue(3));

            var complexCollection = PayloadBuilder.ComplexCollection("ComplexCollectionResultOperation");
            var complexValue1     = PayloadBuilder.ComplexValue("TestModel.Address")
                                    .PrimitiveProperty("Street", "Am Euro Platz")
                                    .AddAnnotation(new SerializationTypeNameTestAnnotation()
            {
                TypeName = null
            });

            complexCollection.Add(complexValue1);

            // NOTE: tests to cover consistency between the expected function import and the function import
            //       in the payload exist in the ContextUriValidationJsonLightTests.
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Non-collection type specified in odata.type - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"TestModel.Address\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ]" +
                                                           "}")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightCollectionDeserializer_InvalidCollectionTypeName", "TestModel.Address"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Expected primitive item type and odata.type consistent - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(Edm.Int32)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ]" +
                                                           "}")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Expected complex item type and odata.type consistent - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.Address)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(TestModel.Address)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\": \"Am Euro Platz\"} ]" +
                                                           "}")
                                       .ExpectedFunctionImport(complexCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Context URI (primitive collection) and odata.type consistent - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(Edm.Int32)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ]" +
                                                           "}")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Context URI (complex collection) and odata.type consistent - should work.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.Address)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(TestModel.Address)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\": \"Am Euro Platz\"} ]" +
                                                           "}")
                                       .ExpectedFunctionImport(complexCollectionResultOperation),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Expected primitive item type and odata.type NOT consistent - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(Edm.Single)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ]" +
                                                           "}")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "Edm.Single", "Edm.Int32")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Expected primitive item type and odata.type NOT consistent (2) - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = primitiveCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.Address)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(Edm.Int32)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1, 2, 3 ]" +
                                                           "}")
                                       .ExpectedFunctionImport(complexCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "Edm.Int32", "Complex", "Primitive")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Expected complex item type and odata.type NOT consistent - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.Address)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(TestModel.OfficeType)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\": \"Am Euro Platz\"} ]" +
                                                           "}")
                                       .ExpectedFunctionImport(complexCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.OfficeType", "Complex", "Entity")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Expected primitive item type and odata.type NOT consistent (2) - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(TestModel.Address)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\": \"Am Euro Platz\"} ]" +
                                                           "}")
                                       .ExpectedFunctionImport(primitiveCollectionResultOperation),
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.Address", "Primitive", "Complex")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Complex item type in context URI and odata.type NOT consistent - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.Address)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(TestModel.OfficeType)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\": \"Am Euro Platz\"} ]" +
                                                           "}"),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.OfficeType", "Complex", "Entity")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Primitive item type in context URI and odata.type NOT consistent - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = complexCollection.DeepCopy()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(Edm.Int32)\", " +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataTypeAnnotationName) + "\":\"Collection(TestModel.Address)\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ { \"Street\": \"Am Euro Platz\"} ]" +
                                                           "}"),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.Address", "Primitive", "Complex")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Пример #36
0
        public void FeedReaderTest()
        {
            IEdmModel           model           = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container       = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet = container.FindEntitySet("Cities");
            IEdmType            cityType        = model.FindType("TestModel.CityType") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                #region Test cases
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed without next link or inline count.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a next link annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink")
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a next link annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink")
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a inline count annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet(null, 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a inline count annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet(null, 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link and inline count annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link and inline count annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link before and inline count after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link after and inline count before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link after and inline count before the feed property and custom annotations.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"@my.annotation\":\"annotation-value\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"@my.annotation2\":\"annotation-value2\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"@my.annotation3\":\"annotation-value3\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"@my.annotation4\":\"annotation-value4\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                #endregion Test cases
            };

            // TODO: all of the above for feeds in expanded navigation links

            // TODO: non-empty feed with entries of base type, of base + derived type, only derived type (with and without derived type specified as expected type)
            // TODO: non-empty feed at top-level and expanded navigation link

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
 private static IEdmActionImport CreateFakeActionImport(IEdmEntityContainer container, string name, bool isBindable)
 {
     Mock<IEdmActionImport> mock = new Mock<IEdmActionImport>();
     mock.Setup(o => o.Container).Returns(container);
     mock.Setup(o => o.Name).Returns(name);
     Mock<IEdmAction> mockAction = new Mock<IEdmAction>();
     mockAction.Setup(o => o.IsBound).Returns(isBindable);
     mock.Setup(o => o.Action).Returns(mockAction.Object);
     return mock.Object;
 }
Пример #38
0
        public static void SetFilterFunctionsCapabilitiesAnnotation(this EdmModel model, IEdmEntityContainer container, IEnumerable<string> functions)
        {
            if (model == null) throw new ArgumentNullException("model");
            if (container == null) throw new ArgumentNullException("container");

            model.SetCapabilitiesAnnotation(container, FilterFunctionsTerm, functions);
        }
Пример #39
0
		public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmTypeReference returnType) : this(container, name, returnType, null, true, false, false)
		{
		}
        /// <summary>
        /// When we see an entity container, we see if it has <see cref="CsdlConstants.SchemaNamespaceAnnotation"/>.
        /// If it does, then we attach it to that schema, otherwise we attached to the first existing schema.
        /// If there are no schemas, we create the one named "Default" and attach container to it.
        /// </summary>
        /// <param name="element">The entity container being processed.</param>
        protected override void ProcessEntityContainer(IEdmEntityContainer element)
        {
            var containerSchemaNamespace = element.Namespace;

            EdmSchema containerSchema;
            if (!this.modelSchemas.TryGetValue(containerSchemaNamespace, out containerSchema))
            {
                containerSchema = new EdmSchema(containerSchemaNamespace);
                this.modelSchemas.Add(containerSchema.Namespace, containerSchema);
            }

            containerSchema.AddEntityContainer(element);
            this.activeSchema = containerSchema;

            base.ProcessEntityContainer(element);
        }
 public EdmEntitySetWithResourceSet(IEdmEntityContainer container, ResourceSetWrapper resourceSet, IEdmEntityType elementType)
     : base(container, resourceSet.Name, elementType)
 {
     this.ResourceSet = resourceSet;
 }
Пример #42
0
 protected override void ProcessEntityContainer(IEdmEntityContainer element)
 {
     this.BeginElement(element, this.schemaWriter.WriteEntityContainerElementHeader);
     base.ProcessEntityContainer(element);
     this.EndElement(element);
 }