private void VerifyTimeOfDayValueReader(string payload, string edmTypeName, object expectedResult)
        {
            IEdmModel model = new EdmModel();
            IEdmPrimitiveTypeReference typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)model.FindType(edmTypeName), true);

            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(payload));
            object actualValue;
            using (ODataJsonLightInputContext inputContext = new ODataJsonLightInputContext(
                ODataFormat.Json,
                stream,
                JsonLightUtils.JsonLightStreamingMediaType,
                Encoding.UTF8,
                new ODataMessageReaderSettings(),
                /*readingResponse*/ true,
                /*synchronous*/ true,
                model,
                /*urlResolver*/ null))
            {
                ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(inputContext);
                deserializer.JsonReader.Read();
                actualValue = deserializer.ReadNonEntityValue(
                    /*payloadTypeName*/ null,
                    typeReference,
                    /*duplicatePropertyNamesChecker*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true,
                    /*isTopLevelPropertyValue*/ true,
                    /*insideComplexValue*/ false,
                    /*propertyName*/ null);
            }
            actualValue.Should().Be(expectedResult, "payload ->{0}<- for type '{1}'", payload, edmTypeName);
        }
Ejemplo n.º 2
0
        public void NonPrimitiveIsXXXMethods()
        {
            IEdmEntityType entityDef = new EdmEntityType("MyNamespace", "MyEntity");
            IEdmEntityTypeReference entityRef = new EdmEntityTypeReference(entityDef, false);

            Assert.IsTrue(entityRef.IsEntity(), "Entity is Entity");

            IEdmPrimitiveTypeReference bad = entityRef.AsPrimitive();
            Assert.IsTrue(bad.Definition.IsBad(), "bad TypeReference is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, bad.Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.IsTrue(bad.Definition.IsBad(), "Bad definition is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, bad.Definition.Errors().First().ErrorCode, "Definition is bad from conversion");

            IEdmPrimitiveType intDef = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32);
            IEdmPrimitiveTypeReference intRef = new EdmPrimitiveTypeReference(intDef, false);
            IEdmCollectionTypeReference intCollection = new EdmCollectionTypeReference(new EdmCollectionType(intRef));
            Assert.IsTrue(intCollection.IsCollection(), "Collection is collection");

            IEdmComplexType complexDef = new EdmComplexType("MyNamespace", "MyComplex");
            IEdmComplexTypeReference complexRef = new EdmComplexTypeReference(complexDef, false);
            Assert.IsTrue(complexRef.IsComplex(), "Complex is Complex");

            Assert.IsTrue(entityRef.IsStructured(), "Entity is Structured");
            Assert.IsTrue(complexRef.IsStructured(), "Complex is stuctured");
            Assert.IsFalse(intCollection.IsStructured(), "Collection is not structured");
        }
        public OperationImportSegmentUnitTests()
        {
            nullableIntType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true);
            nullableDecimalType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), true);
            nullableBinaryType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true);
            nullableStringType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);

            container = ModelBuildingHelpers.BuildValidEntityContainer();
            model = new EdmModel();
            model.AddElement(container);

            this.functionIntToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType);
            this.functionIntToInt.AddParameter("Parameter1", this.nullableIntType);
            this.functionImportIntToInt = new EdmFunctionImport(this.container, "Function", this.functionIntToInt);

            this.functionDecimalToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType);
            this.functionDecimalToInt.AddParameter("Parameter1", this.nullableDecimalType);
            this.functionImportDecimalToInt = new EdmFunctionImport(this.container, "Function", this.functionDecimalToInt);

            this.functionBinaryToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType);
            this.functionBinaryToInt.AddParameter("Parameter1", this.nullableBinaryType);
            this.functionImportBinaryToInt = new EdmFunctionImport(this.container, "Function", this.functionBinaryToInt);

            this.functionIntToString = new EdmFunction("Name.Space", "Function", this.nullableStringType);
            this.functionIntToString.AddParameter("Parameter1", this.nullableIntType);
            this.functionImportIntToString = new EdmFunctionImport(this.container, "Function", this.functionIntToString);

            model.AddElement(functionIntToInt);
            model.AddElement(functionDecimalToInt);
            model.AddElement(functionBinaryToInt);
            model.AddElement(functionIntToString);
        }
        public void TestComparingEdmTemporalTypeReference()
        {
            var duration = new EdmTemporalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Duration), true);
            var offset = new EdmTemporalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.DateTimeOffset), true);
            Assert.IsFalse(duration.IsEquivalentTo(offset));

            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Duration), true);
            Assert.IsFalse(duration.IsEquivalentTo(primitiveType));
        }
        public void TestComparingEdmBinaryTypeReference()
        {
            var binaryTypeWithDefaultValue = new EdmBinaryTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true);
            var binaryType = new EdmBinaryTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true, false, null);
            Assert.IsTrue(binaryType.IsEquivalentTo(binaryTypeWithDefaultValue));

            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true);
            Assert.IsFalse(binaryType.IsEquivalentTo(primitiveType));
        }
        public void TestComparingEdmDecimalTypeReference()
        {
            var decimalTypeWithPrecisionNull = new EdmDecimalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), false, null, null);
            var decimalTypeWithPrecisionNotNull = new EdmDecimalTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), false, 1, null);
            Assert.IsFalse(decimalTypeWithPrecisionNull.IsEquivalentTo(decimalTypeWithPrecisionNotNull));

            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), true);
            Assert.IsFalse(decimalTypeWithPrecisionNull.IsEquivalentTo(primitiveType));
        }
        public void TestComparingEdmStringTypeReference()
        {
            var stringType = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
            var stringTypeCopy = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
            Assert.IsTrue(stringType.IsEquivalentTo(stringTypeCopy));

            var stringTypeWithNullableFalse = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false);
            var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
            Assert.IsFalse(stringType.IsEquivalentTo(primitiveType));
            Assert.IsFalse(stringType.IsEquivalentTo(stringTypeWithNullableFalse));
        }
        public void TestCreateODataCollectionWriter_InJsonLight_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataResponseMessage response = CreateResponse();
            ODataMessageWriterSettings settings = CreateJsonLightSettings();
            IEdmModel model = CreateModel();
            IEdmTypeReference itemTypeReference = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageWriter writer = new ODataMessageWriter(response, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => writer.CreateODataCollectionWriter(itemTypeReference));
            }
        }
        public void TestCreateODataCollectionReader_InJsonLight_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage request = CreateJsonLightRequest();
            ODataMessageReaderSettings settings = CreateSettings();
            IEdmModel model = CreateModel();
            IEdmOperationImport producingOperationImport = model.EntityContainer.OperationImports().First();
            IEdmTypeReference expectedItemTypeReference = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => reader.CreateODataCollectionReader(expectedItemTypeReference));
            }
        }
Ejemplo n.º 10
0
        internal static object ConvertToPayloadValue(object value, ODataSerializerContext writeContext)
        {
            Ensure.NotNull(writeContext, "writeContext");

            IEdmTypeReference edmTypeReference = null;
            if (writeContext.Path != null)
            {
                // Try to get the EDM type of the value from the path.
                var edmType = writeContext.Path.EdmType as IEdmPrimitiveType;
                if (edmType != null)
                {
                    // Just created to call the payload value converter.
                    edmTypeReference = new EdmPrimitiveTypeReference(edmType, true /*isNullable*/);
                }
            }

            var payloadValueConverter = writeContext.Model.GetPayloadValueConverter();
            return payloadValueConverter.ConvertToPayloadValue(value, edmTypeReference);
        }
        private void VerifyPrimitiveValueRoundtrips(object clrValue, string edmTypeName, ODataVersion version, string description)
        {
            IEdmModel model = new EdmModel();
            IEdmPrimitiveTypeReference typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)model.FindType(edmTypeName), true);

            MemoryStream stream = new MemoryStream();
            using (ODataAtomOutputContext outputContext = new ODataAtomOutputContext(
                ODataFormat.Atom,
                new NonDisposingStream(stream),
                Encoding.UTF8,
                new ODataMessageWriterSettings() { Version = version },
                /*writingResponse*/ true,
                /*synchronous*/ true,
                model,
                /*urlResolver*/ null))
            {
                ODataAtomPropertyAndValueSerializer serializer = new ODataAtomPropertyAndValueSerializer(outputContext);
                serializer.XmlWriter.WriteStartElement("ValueElement");
                serializer.WritePrimitiveValue(
                    clrValue,
                    /*collectionValidator*/ null,
                    typeReference,
                    /*serializationTypeNameAnnotation*/ null);
                serializer.XmlWriter.WriteEndElement();
            }

            stream.Position = 0;

            object actualValue;
            using (ODataAtomInputContext inputContext = new ODataAtomInputContext(
                ODataFormat.Atom,
                stream,
                Encoding.UTF8,
                new ODataMessageReaderSettings(),
                /*readingResponse*/ true,
                /*synchronous*/ true,
                model,
                /*urlResolver*/ null))
            {
                ODataAtomPropertyAndValueDeserializer deserializer = new ODataAtomPropertyAndValueDeserializer(inputContext);
                deserializer.XmlReader.MoveToContent();
                actualValue = deserializer.ReadNonEntityValue(
                    typeReference,
                    /*duplicatePropertyNamesChecker*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true);
            }

            if (clrValue is byte[])
            {
                ((byte[])actualValue).Should().Equal((byte[])clrValue, description);
            }
            else
            {
                actualValue.Should().Be(clrValue, description);
            }
        }
Ejemplo n.º 12
0
        public void PrimitiveIsXXXMethods()
        {
            IEdmPrimitiveTypeReference binaryRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), false);
            IEdmPrimitiveTypeReference booleanRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Boolean), false);
            IEdmPrimitiveTypeReference byteRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Byte), false);
            IEdmPrimitiveTypeReference dateTimeOffsetRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.DateTimeOffset), false);
            IEdmPrimitiveTypeReference decimalRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), false);
            IEdmPrimitiveTypeReference doubleRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Double), false);
            IEdmPrimitiveTypeReference guidRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Guid), false);
            IEdmPrimitiveTypeReference int16Ref = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int16), false);
            IEdmPrimitiveTypeReference int32Ref = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);
            IEdmPrimitiveTypeReference int64Ref = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int64), false);
            IEdmPrimitiveTypeReference sByteRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.SByte), false);
            IEdmPrimitiveTypeReference singleRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Single), false);
            IEdmPrimitiveTypeReference stringRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false);
            IEdmPrimitiveTypeReference streamRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Stream), false);
            IEdmPrimitiveTypeReference timeRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Duration), false);
            IEdmPrimitiveTypeReference dateRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Date), false);
            IEdmPrimitiveTypeReference timeOfDayRef = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.TimeOfDay), false);

            Assert.IsTrue(binaryRef.IsPrimitive(), "Binary is Primitive");
            Assert.IsTrue(binaryRef.IsBinary(), "Binary is Binary");
            Assert.IsTrue(booleanRef.IsBoolean(), "Boolean is Boolean");
            Assert.IsTrue(byteRef.IsByte(), "Byte is Byte");
            Assert.IsTrue(dateTimeOffsetRef.IsDateTimeOffset(), "DateTimeOffset is DateTimeOffset");
            Assert.IsTrue(decimalRef.IsDecimal(), "Decimal is Decimal");
            Assert.IsTrue(doubleRef.IsDouble(), "Double is Double");
            Assert.IsTrue(guidRef.IsGuid(), "Guid is Guid");
            Assert.IsTrue(int16Ref.IsInt16(), "Int16 is Int16");
            Assert.IsTrue(int32Ref.IsInt32(), "Int32 is Int32");
            Assert.IsTrue(int64Ref.IsInt64(), "Int64 is Int64");
            Assert.IsTrue(sByteRef.IsSByte(), "SByte is SByte");
            Assert.IsTrue(singleRef.IsSingle(), "Single is Single");
            Assert.IsTrue(stringRef.IsString(), "String is String");
            Assert.IsTrue(streamRef.IsStream(), "Stream is Stream");
            Assert.IsTrue(timeRef.IsDuration(), "Duration is Duration");
            Assert.IsTrue(dateRef.IsDate(), "Date is Date");
            Assert.IsTrue(timeOfDayRef.IsTimeOfDay(), "TimeOfDay is TimeOfDay");

            Assert.IsTrue(binaryRef.AsPrimitive().IsPrimitive(), "Binary as primitive is Primitive");
            Assert.IsTrue(binaryRef.AsPrimitive().IsBinary(), "Binary as primitive is Binary");
            Assert.IsTrue(booleanRef.AsPrimitive().IsBoolean(), "Boolean as primitive is Boolean");
            Assert.IsTrue(byteRef.AsPrimitive().IsByte(), "Byte as primitive is Byte");
            Assert.IsTrue(dateTimeOffsetRef.AsPrimitive().IsDateTimeOffset(), "DateTimeOffset as primitive is DateTimeOffset");
            Assert.IsTrue(decimalRef.AsPrimitive().IsDecimal(), "Decimal as primitive is Decimal");
            Assert.IsTrue(doubleRef.AsPrimitive().IsDouble(), "Double as primitive is Double");
            Assert.IsTrue(guidRef.AsPrimitive().IsGuid(), "Guid as primitive is Guid");
            Assert.IsTrue(int16Ref.AsPrimitive().IsInt16(), "Int16 as primitive is Int16");
            Assert.IsTrue(int32Ref.AsPrimitive().IsInt32(), "Int32 as primitive is Int32");
            Assert.IsTrue(int64Ref.AsPrimitive().IsInt64(), "Int64 as primitive is Int64");
            Assert.IsTrue(sByteRef.AsPrimitive().IsSByte(), "SByte as primitive is SByte");
            Assert.IsTrue(singleRef.AsPrimitive().IsSingle(), "Single as primitive is Single");
            Assert.IsTrue(stringRef.AsPrimitive().IsString(), "String as primitive is String");
            Assert.IsTrue(streamRef.AsPrimitive().IsStream(), "Stream as primitive is Stream");
            Assert.IsTrue(timeRef.AsPrimitive().IsDuration(), "Duration as primitive is Duration");
            Assert.IsTrue(dateRef.AsPrimitive().IsDate(), "Date as primitive is Date");
            Assert.IsTrue(timeOfDayRef.AsPrimitive().IsTimeOfDay(), "TimeOfDay as primitive is TimeOfDay");

            Assert.IsTrue(dateTimeOffsetRef.IsTemporal(), "DateTimeOffset is Temporal");
            Assert.IsTrue(timeRef.IsTemporal(), "Duration is Temporal");
            Assert.IsTrue(timeOfDayRef.IsTemporal(), "TimeOfDay is Temporal");
            Assert.IsFalse(int32Ref.IsTemporal(), "Int is not Temporal");

            Assert.IsTrue(doubleRef.IsFloating(), "Double is floating");
            Assert.IsTrue(singleRef.IsFloating(), "Single is floating");
            Assert.IsFalse(int32Ref.IsFloating(), "Int is not floating");

            Assert.IsTrue(sByteRef.IsSignedIntegral(), "SByte is signed integral");
            Assert.IsTrue(int16Ref.IsSignedIntegral(), "Int16 is signed integral");
            Assert.IsTrue(int32Ref.IsSignedIntegral(), "Int32 is signed integral");
            Assert.IsTrue(int64Ref.IsSignedIntegral(), "Int64 is signed integral");
            Assert.IsFalse(stringRef.IsSignedIntegral(), "String is not signed integral");

            IEdmEntityType entityDef = new EdmEntityType("MyNamespace", "MyEntity");
            IEdmEntityTypeReference entityRef = new EdmEntityTypeReference(entityDef, false);
            Assert.AreEqual(EdmPrimitiveTypeKind.None, entityRef.PrimitiveKind(), "Non-Primitive Type has primitivetypekind of none");
            Assert.AreEqual(EdmSchemaElementKind.TypeDefinition, int16Ref.PrimitiveDefinition().SchemaElementKind,"SchemaElementKind of primitive type is correct.");
        }
        public void TestReadProperty_InJsonLight_WithTypeReference_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage request = CreateJsonLightRequest("{\"value\":1}");
            ODataMessageReaderSettings settings = CreateSettings();
            IEdmModel model = CreateModel();
            IEdmTypeReference expectedPropertyTypeReference = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => reader.ReadProperty(expectedPropertyTypeReference));
            }
        }
Ejemplo n.º 14
0
 public void PrimitiveTypesOfSameKindCanConvertToEachOther()
 {
     var stringType = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
     var primitiveType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true);
     Assert.True(TypePromotionUtils.CanConvertTo(null, stringType, primitiveType));
     Assert.True(TypePromotionUtils.CanConvertTo(null, primitiveType, stringType));
 }
        private void VerifyPrimitiveValuesRoundtripWithTypeInformationAndWithExpectedValues(Array clrValues, string edmTypeName, Array expectedValues)
        {
            var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType(edmTypeName), true);

            clrValues.Length.Should().Be(expectedValues.Length);

            for (int iterator = 0; iterator < clrValues.Length; iterator++)
            {
                object clrValue = clrValues.GetValue(iterator);
                object expectedValue = expectedValues.GetValue(iterator);
                this.VerifyPrimitiveValueRoundtrips(clrValue, typeReference, ODataVersion.V4, string.Format("JSON Light roundtrip value {0} of type {1} of expected value {2}.", clrValue, edmTypeName, expectedValue), isIeee754Compatible: true, expectedValue: expectedValue);
            }
        }
 private void VerifyPrimitiveValuesRoundtripWithTypeInformationIeee754CompatibleFalse(IEnumerable clrValues, string edmTypeName)
 {
     var typeReference = new EdmPrimitiveTypeReference((IEdmPrimitiveType)this.model.FindType(edmTypeName), true);
     foreach (object clrValue in clrValues)
     {
         this.VerifyPrimitiveValueRoundtrips(clrValue, typeReference, ODataVersion.V4, string.Format("JSON Light roundtrip value {0} with no expected type.", clrValue), isIeee754Compatible: false);
     }
 }
Ejemplo n.º 17
0
        private void BuildEdmModel()
        {
            _entityType = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
            _derivedEntityType = new EdmEntityTypeReference(new EdmEntityType("NS", "DerivedEntity", _entityType.EntityDefinition()), isNullable: false);
            var entityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_entityType));
            var derivedEntityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_derivedEntityType));

            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
            model.AddElement(container);

            // non-bindable action
            container.AddActionImport(new EdmAction("NS", "NonBindableAction", returnType: null));

            // action bound to entity
            var actionBoundToEntity = new EdmAction(
                "NS",
                "ActionBoundToEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntity.AddParameter("bindingParameter", _entityType);
            model.AddElement(actionBoundToEntity);

            // action bound to derived entity
            var actionBoundToDerivedEntity = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntity.AddParameter("bindingParameter", _derivedEntityType);
            model.AddElement(actionBoundToDerivedEntity);

            // action bound to entity collection
            var actionBoundToEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntityCollection.AddParameter("bindingParameter", entityCollection);
            model.AddElement(actionBoundToEntityCollection);

            // action bound to derived entity collection
            var actionBoundToDerivedEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntityCollection.AddParameter("bindingParameter", derivedEntityCollection);
            model.AddElement(actionBoundToDerivedEntityCollection);

            // ambiguos actions
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));

            IEdmTypeReference returnType = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            // non-bindable function
            container.AddFunctionImport(new EdmFunction("NS", "NonBindableFunction", returnType));

            // function bound to entity
            var functionBoundToEntity = new EdmFunction(
                "NS",
                "FunctionBoundToEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntity.AddParameter("bindingParameter", _entityType);
            model.AddElement(functionBoundToEntity);

            // function bound to entity
            var functionBoundToDerivedEntity = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntity.AddParameter("bindingParameter", _derivedEntityType);
            model.AddElement(functionBoundToDerivedEntity);

            // function bound to entity collection
            var functionBoundToEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntityCollection.AddParameter("bindingParameter", entityCollection);
            model.AddElement(functionBoundToEntityCollection);

            // function bound to derived entity collection
            var functionBoundToDerivedEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntityCollection.AddParameter("bindingParameter", derivedEntityCollection);
            model.AddElement(functionBoundToDerivedEntityCollection);

            _model = model;
            _container = container;
        }
Ejemplo n.º 18
0
        public void NonPrimitiveAsXXXMethods()
        {
            IEdmPrimitiveType intDef = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32);
            IEdmPrimitiveTypeReference intRef = new EdmPrimitiveTypeReference(intDef, false);

            IEdmEntityType entityDef = new EdmEntityType("MyNamespace", "MyEntity");
            IEdmEntityTypeReference entityRef = new EdmEntityTypeReference(entityDef, false);
            IEdmComplexType complexDef = new EdmComplexType("MyNamespace", "MyComplex");
            IEdmComplexTypeReference complexRef = new EdmComplexTypeReference(complexDef, false);
            IEdmCollectionType collectionDef = new EdmCollectionType(intRef);
            IEdmCollectionTypeReference collectionRef = new EdmCollectionTypeReference(collectionDef);

            IEdmCollectionTypeReference badCollectionRef = entityRef.AsCollection();
            IEdmEntityTypeReference badEntityRef = collectionRef.AsEntity();
            IEdmComplexTypeReference badComplexRef = entityRef.AsComplex();
            IEdmEntityReferenceTypeReference badEntityRefRef= entityRef.AsEntityReference();

            Assert.IsTrue(badCollectionRef.IsBad(), "Bad Collection is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badCollectionRef.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("[Collection([UnknownType Nullable=True]) Nullable=True]", badCollectionRef.ToString(), "Correct tostring");

            Assert.IsTrue(badComplexRef.IsBad(), "Bad Complex is Bad");
            Assert.IsTrue(badComplexRef.Definition.IsBad(), "Bad Complex definition is Bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badComplexRef.Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("TypeSemanticsCouldNotConvertTypeReference:[MyNamespace.MyEntity Nullable=False]", badComplexRef.ToString(), "Correct tostring");

            Assert.IsTrue(badEntityRef.IsBad(), "Bad Entity is bad");
            Assert.IsTrue(badEntityRef.Definition.IsBad(), "Bad Entity Definition is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badEntityRef.Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("TypeSemanticsCouldNotConvertTypeReference:[Collection(Edm.Int32) Nullable=False]", badEntityRef.ToString(), "Correct tostring");

            Assert.IsTrue(badEntityRefRef.IsBad(), "Bad Entity Reference is Bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badEntityRefRef.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("[EntityReference(.) Nullable=False]", badEntityRefRef.ToString(), "Correct tostring");

            Assert.IsFalse(entityRef.AsEntity().IsBad(), "Entity converted to Entity is good");
            Assert.IsFalse(complexRef.AsComplex().IsBad(), "Complex converted to complex is good");
            Assert.IsFalse(collectionRef.AsCollection().IsBad(), "Collection converted to collection is good");

            Assert.IsTrue(entityRef.AsStructured().IsEntity(), "Entity as structured is entity");
            Assert.IsFalse(entityRef.AsStructured().IsBad(), "Entity as structured is good");
            Assert.IsTrue(complexRef.AsStructured().IsComplex(), "Complex as structured is complex");
            Assert.IsFalse(complexRef.AsStructured().IsBad(), "Complex as structured is good");
            Assert.IsFalse(collectionRef.AsStructured().IsCollection(), "Collection as structured is not collection");
            Assert.IsTrue(collectionRef.AsStructured().IsBad(), "Collection as structured is bad");
            Assert.IsTrue(collectionRef.AsStructured().Definition.IsBad(), "Collection as structured definition is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, collectionRef.AsStructured().Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
        }
Ejemplo n.º 19
0
        private static IEdmEntityContainer GetEntityContainer()
        {
            var entityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_entityType), isNullable: false);
            var derivedEntityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_derivedEntityType), isNullable: false);
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");

            // non-bindable action
            container.AddActionImport(new EdmAction("NS", "NonBindableAction", returnType: null));

            // action bound to entity
            var actionBoundToEntity = new EdmAction(
                "NS",
                "ActionBoundToEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntity.AddParameter("Param", _entityType);
            container.AddActionImport(actionBoundToEntity);

            // action bound to derived entity
            var actionBoundToDerivedEntity = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntity",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntity.AddParameter("Param", _derivedEntityType);
            container.AddActionImport(actionBoundToDerivedEntity);

            // action bound to entity collection
            var actionBoundToEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToEntityCollection.AddParameter("Param", entityCollection);
            container.AddActionImport(actionBoundToEntityCollection);

            // action bound to derived entity collection
            var actionBoundToDerivedEntityCollection = new EdmAction(
                "NS",
                "ActionBoundToDerivedEntityCollection",
                returnType: null,
                isBound: true,
                entitySetPathExpression: null);
            actionBoundToDerivedEntityCollection.AddParameter("Param", derivedEntityCollection);
            container.AddActionImport(actionBoundToDerivedEntityCollection);

            // ambiguos actions
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));
            container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));

            IEdmTypeReference returnType = new EdmPrimitiveTypeReference(
                EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);

            // non-bindable function
            container.AddFunctionImport(new EdmFunction("NS", "NonBindableFunction", returnType));

            // function bound to entity
            var functionBoundToEntity = new EdmFunction(
                "NS",
                "FunctionBoundToEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntity.AddParameter("Param", _entityType);
            container.AddFunctionImport(functionBoundToEntity);

            // function bound to entity
            var functionBoundToDerivedEntity = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntity",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntity.AddParameter("Param", _derivedEntityType);
            container.AddFunctionImport(functionBoundToDerivedEntity);

            // function bound to entity collection
            var functionBoundToEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToEntityCollection.AddParameter("Param", entityCollection);
            container.AddFunctionImport(functionBoundToEntityCollection);

            // function bound to derived entity collection
            var functionBoundToDerivedEntityCollection = new EdmFunction(
                "NS",
                "FunctionBoundToDerivedEntityCollection",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            functionBoundToDerivedEntityCollection.AddParameter("Param", derivedEntityCollection);
            container.AddFunctionImport(functionBoundToDerivedEntityCollection);

            return container;
        }