internal void AddAction(Action action)
        {
            EdmAction          edmAction;
            EdmEntityContainer entityContainer  = (EdmEntityContainer)EntityContainer;
            IEdmTypeReference  edmTypeReference = GetNotEntityTypeReference(action.ReturnType);

            if (edmTypeReference == null)
            {
                edmTypeReference = GetCollectionNotEntityTypeReference(action.ReturnType);
            }

            if (edmTypeReference != null)
            {
                edmAction = new EdmAction(DefaultNamespace, action.Name, edmTypeReference);
                entityContainer.AddActionImport(edmAction);
            }
            else if (action.ReturnType == typeof(void))
            {
                edmAction = new EdmAction(DefaultNamespace, action.Name, null);
                entityContainer.AddActionImport(edmAction);
            }
            else
            {
                IEdmTypeReference returnEdmTypeReference = GetEdmTypeReference(action.ReturnType, out IEdmEntityType returnEntityType, out bool isCollection);
                if (returnEntityType == null)
                {
                    throw new ArgumentNullException("Тип возвращаемого результата action не найден в модели OData.");
                }

                edmAction = new EdmAction(DefaultNamespace, action.Name, returnEdmTypeReference);
                edmAction.AddParameter("bindingParameter", returnEdmTypeReference);
                entityContainer.AddActionImport(action.Name, edmAction, new EdmEntitySetReferenceExpression(GetEdmEntitySet(returnEntityType)));
            }

            AddElement(edmAction);
            foreach (var parameter in action.ParametersTypes.Keys)
            {
                Type paramType = action.ParametersTypes[parameter];
                edmTypeReference = GetEdmTypeReference(paramType, out IEdmEntityType entityType, out bool isCollection);
                if (edmTypeReference == null)
                {
                    edmTypeReference = GetNotEntityTypeReference(paramType);
                    if (edmTypeReference == null)
                    {
                        edmTypeReference = GetCollectionNotEntityTypeReference(paramType);
                    }
                }

                if (edmTypeReference != null)
                {
                    edmAction.AddParameter(parameter, edmTypeReference);
                }
            }
        }
예제 #2
0
        public static IEdmModel GetModelFunctionsOnNonEntityTypes()
        {
            EdmComplexType colorInfoType = new EdmComplexType("Test", "ColorInfo");

            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Red", EdmCoreModel.Instance.GetInt32(false)));
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Green", EdmCoreModel.Instance.GetInt32(false)));
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Blue", EdmCoreModel.Instance.GetInt32(false)));

            EdmEntityType          vegetableType = new EdmEntityType("Test", "Vegetable");
            IEdmStructuralProperty id            = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));

            vegetableType.AddKeys(id);
            vegetableType.AddStructuralProperty("Color", new EdmComplexTypeReference(colorInfoType, false));

            EdmEntityContainer container = new EdmEntityContainer("Test", "Container");
            var set = container.AddEntitySet("Vegetables", vegetableType);

            var function1 = new EdmFunction("Test", "IsPrime", EdmCoreModel.Instance.GetBoolean(false), true, null, true);

            function1.AddParameter("integer", EdmCoreModel.Instance.GetInt32(false));
            container.AddFunctionImport("IsPrime", function1);

            var action = new EdmAction("Test", "Subtract", EdmCoreModel.Instance.GetInt32(false), true /*isBound*/, null /*entitySetPath*/);

            action.AddParameter("integer", EdmCoreModel.Instance.GetInt32(false));
            container.AddActionImport(action);

            var function2 = new EdmFunction("Test", "IsDark", EdmCoreModel.Instance.GetBoolean(false), true, null, true);

            function2.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
            container.AddFunctionImport("IsDark", function2);

            var function3 = new EdmFunction("Test", "IsDarkerThan", EdmCoreModel.Instance.GetBoolean(false), true, null, true);

            function3.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
            function3.AddParameter("other", new EdmComplexTypeReference(colorInfoType, true));
            container.AddFunctionImport("IsDarkerThan", function3);

            var function4 = new EdmFunction("Test", "GetMostPopularVegetableWithThisColor", new EdmEntityTypeReference(vegetableType, true), true, new EdmPathExpression("color"), true);

            function4.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));

            EdmModel model = new EdmModel();

            model.AddElement(container);
            model.AddElement(vegetableType);
            model.AddElement(action);
            model.AddElement(function1);
            model.AddElement(function2);
            model.AddElement(function3);
            model.AddElement(function4);
            return(model);
        }
        private EdmAction BuildAction(OeOperationConfiguration operationConfiguration, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
        {
            var edmAction = new EdmAction(operationConfiguration.NamespaceName, operationConfiguration.Name, null);

            foreach (OeOperationParameterConfiguration parameterConfiguration in operationConfiguration.Parameters)
            {
                IEdmTypeReference edmTypeReference = GetEdmTypeReference(parameterConfiguration.ClrType, entityTypeInfos);
                edmAction.AddParameter(parameterConfiguration.Name, edmTypeReference);
            }

            return(edmAction);
        }
예제 #4
0
        /// <summary>
        /// Adds the action.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <param name="resultType">Type of the result.</param>
        /// <param name="isBound">if set to <c>true</c> [is bound].</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public EdmAction AddAction(string name, IEdmTypeReference boundType, IEdmTypeReference resultType, bool isBound, IEdmPathExpression entitySetPathExpression, params Tuple <string, IEdmTypeReference>[] parameters)
        {
            var action = new EdmAction(namespaceName, name, resultType, isBound, entitySetPathExpression);

            if (isBound)
            {
                action.AddParameter(new EdmOperationParameter(action, "bindingparameter", boundType));
            }

            this.AddOperation(action);
            return(action);
        }
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingOperationParameterTypeModel()
        {
            var model = new EdmModel();

            var operation = new EdmAction("NS", "Function", EdmCoreModel.Instance.GetInt32(true));
            var parameter = new CustomOperationParameter(operation, "Parameter", null);

            operation.AddParameter(parameter);
            model.AddElement(operation);

            return(model);
        }
예제 #6
0
        private static OeSkipTokenNameValue[] ParseJson(IEdmModel edmModel, String skipToken, IEdmStructuralProperty[] keys, out int?restCount)
        {
            restCount = null;
            var skipTokenNameValues = new OeSkipTokenNameValue[keys.Length];

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(skipToken)))
            {
                IODataRequestMessage requestMessage = new Infrastructure.OeInMemoryMessage(stream, null);
                using (ODataMessageReader messageReader = new ODataMessageReader(requestMessage, ReaderSettings, edmModel))
                {
                    var operation = new EdmAction("", "", null);
                    foreach (IEdmStructuralProperty key in keys)
                    {
                        operation.AddParameter(GetPropertyName(key), key.Type);
                    }
                    operation.AddParameter(RestCountName, OeEdmClrHelper.GetEdmTypeReference(edmModel, typeof(int?)));

                    ODataParameterReader reader = messageReader.CreateODataParameterReader(operation);
                    int i = 0;
                    while (reader.Read())
                    {
                        Object value = reader.Value;
                        if (value is ODataEnumValue enumValue)
                        {
                            value = OeEdmClrHelper.GetValue(edmModel, enumValue);
                        }

                        if (reader.Name == RestCountName)
                        {
                            restCount = (int)value;
                        }
                        else
                        {
                            skipTokenNameValues[i++] = new OeSkipTokenNameValue(reader.Name, value);
                        }
                    }
                }
            }
            return(skipTokenNameValues);
        }
예제 #7
0
        private static IEdmModel GetUntypedEdmModel()
        {
            var model = new EdmModel();
            // complex type address
            EdmComplexType address = new EdmComplexType("NS", "Address", null, false, true);

            address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            model.AddElement(address);

            // enum type color
            EdmEnumType color = new EdmEnumType("NS", "Color");

            color.AddMember(new EdmEnumMember(color, "Red", new EdmIntegerConstant(0)));
            model.AddElement(color);

            // entity type customer
            EdmEntityType customer = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);

            customer.AddKeys(customer.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
            customer.AddStructuralProperty("Color", new EdmEnumTypeReference(color, isNullable: true));
            model.AddElement(customer);

            EdmAction action = new EdmAction(
                "NS",
                "AddColor",
                null,
                isBound: true,
                entitySetPathExpression: null);

            action.AddParameter("bindingParameter", new EdmEntityTypeReference(customer, false));
            action.AddParameter("Color", new EdmEnumTypeReference(color, true));
            model.AddElement(action);

            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");

            container.AddEntitySet("UntypedSimpleOpenCustomers", customer);

            model.AddElement(container);
            return(model);
        }
예제 #8
0
        public void EdmActionConstructorShouldHaveSpecifiedConstructorValues()
        {
            var entitySetPath = new EdmPathExpression("Param1/Nav");
            var edmAction     = new EdmAction(defaultNamespaceName, checkout, this.boolType, true, entitySetPath);

            edmAction.AddParameter(new EdmOperationParameter(edmAction, "Param1", new EdmEntityTypeReference(personType, false)));
            edmAction.Namespace.Should().Be(defaultNamespaceName);
            edmAction.Name.Should().Be(checkout);
            edmAction.ReturnType.Should().Be(this.boolType);
            edmAction.EntitySetPath.Should().Be(entitySetPath);
            edmAction.IsBound.Should().BeTrue();
            edmAction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Action);
        }
예제 #9
0
        public static void AddToModel(IEdmModel model)
        {
            var addressType = new EdmComplexType(Namespace, "address");

            addressType.AddStructuralProperty("street", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("city", EdmPrimitiveTypeKind.String);

            var addressTypeRef   = new EdmComplexTypeReference(addressType, isNullable: false);
            var addressesTypeRef = EdmCoreModel.GetCollection(addressTypeRef);

            var nonNullableStringTypeRef = EdmCoreModel.Instance.GetString(isNullable: false);
            var tagsTypeRef = EdmCoreModel.GetCollection(nonNullableStringTypeRef);

            var docEntityType         = new EdmEntityType(Namespace, DocEntityTypeName);
            EdmStructuralProperty key = docEntityType.AddStructuralProperty("id", EdmPrimitiveTypeKind.String);

            docEntityType.AddKeys(key);
            docEntityType.AddStructuralProperty("addresses", addressesTypeRef);
            docEntityType.AddStructuralProperty("tags", tagsTypeRef);

            var docEntitySetType = EdmCoreModel.GetCollection(new EdmEntityTypeReference(docEntityType, isNullable: true));

            var uploadAction = new EdmAction(Namespace, "UploadAddresses", returnType: null, isBound: true, entitySetPathExpression: null);

            uploadAction.AddParameter("bindingParameter", docEntitySetType);
            uploadAction.AddParameter("value", addressesTypeRef);

            var actionTerm = new EdmTerm(Namespace, "action", EdmPrimitiveTypeKind.String);

            var mutableModel = (EdmModel)model;

            mutableModel.AddElements(new IEdmSchemaElement[] { addressType, docEntityType, uploadAction, actionTerm });

            var container = (EdmEntityContainer)mutableModel.EntityContainer;

            container.AddEntitySet("Docs", docEntityType);
        }
        public void EnsureBoundAndUnBoundActionsNamedTheSameShouldNotError()
        {
            var edmAction = new EdmAction("n.s", "DoStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/);

            edmAction.AddParameter("param1", EdmCoreModel.Instance.GetString(true));
            var edmAction2 = new EdmAction("n.s", "DoStuff", EdmCoreModel.Instance.GetString(true), false /*isBound*/, null /*entitySetPath*/);

            edmAction2.AddParameter("param2", EdmCoreModel.Instance.GetString(true));

            EdmModel model = new EdmModel();

            model.AddElement(edmAction);
            model.AddElement(edmAction2);
            ValidateNoError(model);
        }
예제 #11
0
        public void EdmActionImportConstructorShouldHaveSpecifiedConstructorValues()
        {
            var actionEntitySetPath = new EdmPathExpression("Param1/Nav");
            var edmAction           = new EdmAction("DefaultNamespace", "Checkout", this.boolType, true, actionEntitySetPath);

            edmAction.AddParameter(new EdmOperationParameter(edmAction, "Param1", new EdmEntityTypeReference(personType, true)));

            var actionImportEntitySetPath = new EdmPathExpression("Param1/Nav2");
            var edmActionImport           = new EdmActionImport(this.entityContainer, "checkoutImport", edmAction, actionImportEntitySetPath);

            edmActionImport.Name.Should().Be("checkoutImport");
            edmActionImport.Container.Should().Be(this.entityContainer);
            edmActionImport.EntitySet.Should().Be(actionImportEntitySetPath);
            edmActionImport.Action.Should().Be(edmAction);
        }
        public void EnsureBoundActionWithSameBindingParameterTypesShouldError()
        {
            var edmAction = new EdmAction("n.s", "DoStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/);

            edmAction.AddParameter("param1", EdmCoreModel.Instance.GetString(true));
            var edmAction2 = new EdmAction("n.s", "DoStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/);

            edmAction2.AddParameter("param2", EdmCoreModel.Instance.GetString(true));

            EdmModel model = new EdmModel();

            model.AddElement(edmAction);
            model.AddElement(edmAction2);
            ValidateError(model, EdmErrorCode.DuplicateActions, Strings.EdmModel_Validator_Semantic_ModelDuplicateBoundActions("n.s.DoStuff"));
        }
        public void AmbigiousOperationBindingShouldReferToFirstOperationAlwaysWhenNotNull()
        {
            var action1 = new EdmAction("DS", "name", EdmCoreModel.Instance.GetBoolean(false));

            action1.AddParameter("param", EdmCoreModel.Instance.GetBoolean(false));
            var function = new EdmFunction("DS2", "name2", EdmCoreModel.Instance.GetBoolean(false), true, new EdmPathExpression("path1"), true);
            AmbiguousOperationBinding ambigiousOperationBinding = new AmbiguousOperationBinding(action1, function);

            ambigiousOperationBinding.Namespace.Should().Be("DS");
            ambigiousOperationBinding.Name.Should().Be("name");
            ambigiousOperationBinding.ReturnType.Should().BeNull();
            ambigiousOperationBinding.Parameters.Should().HaveCount(1);
            ambigiousOperationBinding.SchemaElementKind.Should().Be(EdmSchemaElementKind.Action);
            ambigiousOperationBinding.IsBound.Should().BeFalse();
            ambigiousOperationBinding.EntitySetPath.Should().BeNull();
        }
예제 #14
0
        public void AmbigiousOperationBindingShouldReferToFirstOperationAlwaysWhenNotNull()
        {
            var action1 = new EdmAction("DS", "name", EdmCoreModel.Instance.GetBoolean(false));

            action1.AddParameter("param", EdmCoreModel.Instance.GetBoolean(false));
            var function = new EdmFunction("DS2", "name2", EdmCoreModel.Instance.GetBoolean(false), true, new EdmPathExpression("path1"), true);
            AmbiguousOperationBinding ambigiousOperationBinding = new AmbiguousOperationBinding(action1, function);

            Assert.Equal("DS", ambigiousOperationBinding.Namespace);
            Assert.Equal("name", ambigiousOperationBinding.Name);
            Assert.Null(ambigiousOperationBinding.ReturnType);
            Assert.Single(ambigiousOperationBinding.Parameters);
            Assert.Equal(EdmSchemaElementKind.Action, ambigiousOperationBinding.SchemaElementKind);
            Assert.False(ambigiousOperationBinding.IsBound);
            Assert.Null(ambigiousOperationBinding.EntitySetPath);
        }
예제 #15
0
        public void FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingTypeShouldFilterReturnTypeClosestToTypeA()
        {
            EdmEntityType aType  = new EdmEntityType("N", "A");
            EdmEntityType bType  = new EdmEntityType("N", "B", aType);
            EdmEntityType cType  = new EdmEntityType("N", "C", bType);
            EdmAction     action = new EdmAction("namespace", "action", null, true, null);

            action.AddParameter("bindingParameter", new EdmEntityTypeReference(aType, false));
            EdmAction action2 = new EdmAction("namespace", "action", null, true, null);

            action2.AddParameter("bindingParameter", new EdmEntityTypeReference(bType, false));
            var filteredResults = new IEdmOperation[] { action, action2 }.FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingType(cType).ToList();
            var result = Assert.Single(filteredResults);

            Assert.Same(action2, result);
        }
예제 #16
0
        public void FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingTypeShouldFilterReturnSameAType()
        {
            EdmEntityType aType  = new EdmEntityType("N", "A");
            EdmEntityType bType  = new EdmEntityType("N", "B", aType);
            EdmEntityType cType  = new EdmEntityType("N", "C", bType);
            EdmAction     action = new EdmAction("namespace", "action", null, true, null);

            action.AddParameter("bindingParameter", new EdmEntityTypeReference(cType, false));
            EdmAction action2 = new EdmAction("namespace", "action2", null, true, null);

            action2.AddParameter("bindingParameter", new EdmEntityTypeReference(aType, false));
            var filteredResults = new IEdmOperation[] { action, action2 }.FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingType(aType).ToList();

            filteredResults.Should().HaveCount(1);
            filteredResults[0].Should().BeSameAs(action2);
        }
예제 #17
0
        public void GetActionOperationLinkBuilder_ReturnsDefaultOperationLinkBuilder_IfNotSet()
        {
            // Arrange
            IEdmModel model  = new EdmModel();
            EdmAction action = new EdmAction("NS", "Action", returnType: null);

            action.AddParameter("entity", new EdmEntityTypeReference(new EdmEntityType("NS", "Customer"), false));

            // Act
            OperationLinkBuilder builder = model.GetOperationLinkBuilder(action);

            // Assert
            Assert.NotNull(builder);
            Assert.NotNull(builder.LinkFactory);
            Assert.IsType <Func <ResourceContext, Uri> >(builder.LinkFactory);
            Assert.Null(builder.FeedLinkFactory);
        }
예제 #18
0
        private EdmAction BuildAction(OeOperationConfiguration operationConfiguration)
        {
            var edmAction = new EdmAction(operationConfiguration.NamespaceName ?? "", operationConfiguration.Name, null);

            foreach (OeFunctionParameterConfiguration parameterConfiguration in operationConfiguration.Parameters)
            {
                IEdmTypeReference edmTypeReference = GetEdmTypeReference(parameterConfiguration.ClrType);
                if (edmTypeReference == null)
                {
                    return(null);
                }

                edmAction.AddParameter(parameterConfiguration.Name, edmTypeReference);
            }

            return(edmAction);
        }
        public async Task WriteParameterAsync()
        {
            var result = await SetupJsonLightOutputContextAndRunTestAsync(
                async (jsonLightOutputContext) =>
            {
                var rateCustomerAction = new EdmAction("NS", "RateCustomer", EdmCoreModel.Instance.GetInt32(false));
                rateCustomerAction.AddParameter("customerId", EdmCoreModel.Instance.GetInt32(false));

                var parameterWriter = await jsonLightOutputContext.CreateODataParameterWriterAsync(rateCustomerAction);

                await parameterWriter.WriteStartAsync();
                await parameterWriter.WriteValueAsync("customerId", 1);
                await parameterWriter.WriteEndAsync();
            },
                /*writingResponse*/ false);

            Assert.Equal("{\"customerId\":1}", result);
        }
예제 #20
0
        public async Task ReadPrimitiveParameterAsync()
        {
            var setRatingAction = new EdmAction("NS", "SetRating", null);

            setRatingAction.AddParameter("rating", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(setRatingAction);

            var payload = "{\"rating\":4}";

            await SetupJsonLightParameterDeserializerAndRunTestAsync(
                payload,
                async (jsonLightParameterDeserializer) =>
            {
                var parameterRead = await jsonLightParameterDeserializer.ReadNextParameterAsync(this.propertyAndAnnotationCollector);

                Assert.True(parameterRead);
            },
                setRatingAction);
        }
예제 #21
0
        private static IEdmModel GetModel()
        {
            ODataModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            builder.ContainerName = "Container";
            builder.Namespace     = "org.odata";
            // Action with no overloads
            builder.EntitySet <Vehicle>("Vehicles").EntityType.Action("Drive");
            builder.Singleton <Vehicle>("MyVehicle");
            // Valid overloads of "Wash" bound to different entities
            builder.EntityType <Motorcycle>().Action("Wash");
            builder.EntityType <Car>().Action("Wash");
            builder.EntityType <Car>().Action("NSAction").Namespace = "customize";

            EdmModel model = (EdmModel)builder.GetEdmModel();

            // Invalid overloads of action "Park". These two actions must have different names or binding types
            // but differ only in that the second has a 'mood' parameter.
            IEdmEntityType entityType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Car");
            var            park       = new EdmAction(
                "org.odata",
                "Park",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);

            park.AddParameter("bindingParameter", new EdmEntityTypeReference(entityType, isNullable: false));
            model.AddElement(park);

            IEdmTypeReference stringType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: true);

            park = new EdmAction(
                "org.odata",
                "Park",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            park.AddParameter("bindingParameter", new EdmEntityTypeReference(entityType, isNullable: false));
            park.AddParameter("mood", stringType);
            model.AddElement(park);

            return(model);
        }
예제 #22
0
        public async Task ReadParameterAsync_ThrowsExceptionForUnsupportedPrimitiveParameterType()
        {
            var setPhotoAction = new EdmAction("NS", "SetPhoto", null);

            setPhotoAction.AddParameter("photo", EdmCoreModel.Instance.GetStream(false));
            this.model.AddElement(setPhotoAction);

            var payload = "{\"photo\":\"AQIDBAUGBwgJAA==\"}";

            var exception = await Assert.ThrowsAsync <ODataException>(
                () => SetupJsonLightParameterDeserializerAndRunTestAsync(
                    payload,
                    (jsonLightParameterDeserializer) => jsonLightParameterDeserializer.ReadNextParameterAsync(this.propertyAndAnnotationCollector),
                    setPhotoAction));

            Assert.Equal(
                ErrorStrings.ODataJsonLightParameterDeserializer_UnsupportedPrimitiveParameterType("photo", EdmPrimitiveTypeKind.Stream),
                exception.Message);
        }
        static ODataJsonLightEntryAndFeedDeserializerTests()
        {
            EdmModel       tmpModel    = new EdmModel();
            EdmComplexType complexType = new EdmComplexType("TestNamespace", "TestComplexType");

            complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(false)));
            tmpModel.AddElement(complexType);

            EntityType = new EdmEntityType("TestNamespace", "TestEntityType");
            tmpModel.AddElement(EntityType);
            var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false));

            EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty });
            EntityType.AddProperty(keyProperty);

            var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub");

            tmpModel.AddElement(defaultContainer);
            EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType);
            defaultContainer.AddElement(EntitySet);

            Action = new EdmAction("TestNamespace", "DoSomething", null, true, null);
            Action.AddParameter("p1", new EdmEntityTypeReference(EntityType, false));
            tmpModel.AddElement(Action);

            ActionImport = defaultContainer.AddActionImport("DoSomething", Action);

            var serviceOperationFunction = new EdmFunction("TestNamespace", "ServiceOperation", EdmCoreModel.Instance.GetInt32(true));

            defaultContainer.AddFunctionImport("ServiceOperation", serviceOperationFunction);
            tmpModel.AddElement(serviceOperationFunction);

            tmpModel.AddElement(new EdmTerm("custom", "DateTimeOffsetAnnotation", EdmPrimitiveTypeKind.DateTimeOffset));
            tmpModel.AddElement(new EdmTerm("custom", "DateAnnotation", EdmPrimitiveTypeKind.Date));
            tmpModel.AddElement(new EdmTerm("custom", "TimeOfDayAnnotation", EdmPrimitiveTypeKind.TimeOfDay));

            EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel);
            MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings {
                ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*")
            };
            MessageReaderSettingsIgnoreInstanceAnnotations = new ODataMessageReaderSettings();
        }
예제 #24
0
        public async Task ReadEnumParameterAsync()
        {
            var colorEnumType  = this.model.SchemaElements.Single(d => d.Name.Equals("Color")) as EdmEnumType;
            var setColorAction = new EdmAction("NS", "SetColor", null);

            setColorAction.AddParameter("color", new EdmEnumTypeReference(colorEnumType, false));
            this.model.AddElement(setColorAction);

            var payload = "{\"color\":\"Black\"}";

            await SetupJsonLightParameterDeserializerAndRunTestAsync(
                payload,
                async (jsonLightParameterDeserializer) =>
            {
                var parameterRead = await jsonLightParameterDeserializer.ReadNextParameterAsync(this.propertyAndAnnotationCollector);

                Assert.True(parameterRead);
            },
                setColorAction);
        }
예제 #25
0
        public void CreateOperationForEdmActionReturnsCorrectOperationId(bool enableOperationId)
        {
            // Arrange
            EdmModel      model    = new EdmModel();
            EdmEntityType customer = new EdmEntityType("NS", "Customer");

            customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            model.AddElement(customer);
            EdmAction action = new EdmAction("NS", "MyAction", EdmCoreModel.Instance.GetString(false), false, null);

            action.AddParameter("param", EdmCoreModel.Instance.GetString(false));
            model.AddElement(action);
            EdmEntityContainer container    = new EdmEntityContainer("NS", "Default");
            EdmEntitySet       customers    = new EdmEntitySet(container, "Customers", customer);
            EdmActionImport    actionImport = new EdmActionImport(container, "MyAction", action);

            model.AddElement(container);

            OpenApiConvertSettings settings = new OpenApiConvertSettings
            {
                EnableOperationId = enableOperationId
            };
            ODataContext context = new ODataContext(model, settings);

            ODataPath path = new ODataPath(new ODataOperationImportSegment(actionImport));

            // Act
            var operation = _operationHandler.CreateOperation(context, path);

            // Assert
            Assert.NotNull(operation);

            if (enableOperationId)
            {
                Assert.Equal("OperationImport.MyAction", operation.OperationId);
            }
            else
            {
                Assert.Null(operation.OperationId);
            }
        }
예제 #26
0
        public void GetActionLinkBuilderForFeed_ReturnsDefaultActionLinkBuilder_IfNotSet()
        {
            // Arrange
            IEdmModel           model     = new EdmModel();
            IEdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmAction           action    = new EdmAction("NS", "Action", returnType: null);

            action.AddParameter("entityset",
                                new EdmCollectionTypeReference(
                                    new EdmCollectionType(new EdmEntityTypeReference(new EdmEntityType("NS", "Customer"), false))));

            // Act
            ActionLinkBuilder builder = model.GetActionLinkBuilder(action);

            // Assert
            Assert.NotNull(builder);
            Assert.Null(builder.LinkFactory);

            Assert.NotNull(builder.FeedLinkFactory);
            Assert.IsType <Func <FeedContext, Uri> >(builder.FeedLinkFactory);
        }
예제 #27
0
        public async Task ReadNullPrimitiveCollectionParameterAsync()
        {
            var setAttributesAction = new EdmAction("NS", "SetAttributes", null);

            setAttributesAction.AddParameter(
                "attributes",
                new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))));
            this.model.AddElement(setAttributesAction);

            var payload = "{\"attributes\":null}";

            await SetupJsonLightParameterDeserializerAndRunTestAsync(
                payload,
                async (jsonLightParameterDeserializer) =>
            {
                var parameterRead = await jsonLightParameterDeserializer.ReadNextParameterAsync(this.propertyAndAnnotationCollector);

                Assert.True(parameterRead);
            },
                setAttributesAction);
        }
        public async Task CreateResourceSetWriterAsync_ThrowsExceptionForNonStructuredType()
        {
            var colorEnumType = new EdmEnumType("NS", "Color");

            colorEnumType.AddMember(new EdmEnumMember(colorEnumType, "Black", new EdmEnumMemberValue(1)));
            colorEnumType.AddMember(new EdmEnumMember(colorEnumType, "Black", new EdmEnumMemberValue(2)));

            var edmAction = new EdmAction("NS", "SetColor", null);

            edmAction.AddParameter("color", new EdmEnumTypeReference(colorEnumType, false));

            var exception = await Assert.ThrowsAsync <ODataException>(
                () => SetupJsonLightParameterWriterAndRunTestAsync(
                    (jsonLightParameterWriter) => jsonLightParameterWriter.CreateResourceSetWriterAsync("color"),
                    edmOperation : edmAction,
                    writingResponse : false));

            Assert.Equal(
                Strings.ODataParameterWriterCore_CannotCreateResourceSetWriterOnNonStructuredCollectionTypeKind("color", "Enum"),
                exception.Message);
        }
예제 #29
0
        public async Task ReadParameterWithCustomInstanceAnnotationAsync()
        {
            this.messageReaderSettings.ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*");

            var setDiscountAction = new EdmAction("NS", "SetDiscount", null);

            setDiscountAction.AddParameter("discount", EdmCoreModel.Instance.GetDouble(false));
            this.model.AddElement(setDiscountAction);

            var payload = "{\"@custom.annotation\":\"foobar\",\"discount\":1.70}";

            await SetupJsonLightParameterDeserializerAndRunTestAsync(
                payload,
                async (jsonLightParameterDeserializer) =>
            {
                var parameterRead = await jsonLightParameterDeserializer.ReadNextParameterAsync(this.propertyAndAnnotationCollector);

                Assert.True(parameterRead);
            },
                setDiscountAction);
        }
예제 #30
0
        public async Task ReadParameterAsync_ThrowsExceptionForUnexpectedPrimitiveCollectionParameterValue()
        {
            var setAttributesAction = new EdmAction("NS", "SetAttributes", null);

            setAttributesAction.AddParameter(
                "attributes",
                new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))));
            this.model.AddElement(setAttributesAction);

            var payload = "{\"attributes\":\"attrs\"}";

            var exception = await Assert.ThrowsAsync <ODataException>(
                () => SetupJsonLightParameterDeserializerAndRunTestAsync(
                    payload,
                    (jsonLightParameterDeserializer) => jsonLightParameterDeserializer.ReadNextParameterAsync(this.propertyAndAnnotationCollector),
                    setAttributesAction));

            Assert.Equal(
                ErrorStrings.ODataJsonLightParameterDeserializer_NullCollectionExpected("PrimitiveValue", "attrs"),
                exception.Message);
        }