コード例 #1
0
        public void Initialize()
        {
            var addressEdmType = new EdmComplexType("Default", "Address");
            addressEdmType.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String);

            this.edmAddressComplexTypeRef = new EdmComplexTypeReference(addressEdmType, true);
        }
コード例 #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 void Init()
        {
            EdmModel model = new EdmModel();

            EdmComplexType complex1 = new EdmComplexType("ns", "complex1");
            complex1.AddProperty(new EdmStructuralProperty(complex1, "p1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            model.AddElement(complex1);            
            
            EdmComplexType complex2 = new EdmComplexType("ns", "complex2");
            complex2.AddProperty(new EdmStructuralProperty(complex2, "p1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            model.AddElement(complex2);

            EdmComplexTypeReference complex2Reference = new EdmComplexTypeReference(complex2, isNullable: false);
            EdmCollectionType primitiveCollectionType = new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
            EdmCollectionType complexCollectionType = new EdmCollectionType(complex2Reference);
            EdmCollectionTypeReference primitiveCollectionTypeReference = new EdmCollectionTypeReference(primitiveCollectionType);
            EdmCollectionTypeReference complexCollectionTypeReference = new EdmCollectionTypeReference(complexCollectionType);

            model.AddElement(new EdmTerm("custom", "int", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "string", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "double", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "bool", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: true)));
            model.AddElement(new EdmTerm("custom", "decimal", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "timespan", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Duration, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "guid", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Guid, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "complex", complex2Reference));
            model.AddElement(new EdmTerm("custom", "primitiveCollection", primitiveCollectionTypeReference));
            model.AddElement(new EdmTerm("custom", "complexCollection", complexCollectionTypeReference));

            this.stream = new MemoryStream();
            this.settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
            this.settings.SetServiceDocumentUri(ServiceDocumentUri);
            this.serializer = new ODataAtomPropertyAndValueSerializer(this.CreateAtomOutputContext(model, this.stream));
        }
        public ODataJsonLightInheritComplexCollectionWriterTests()
        {
            collectionStartWithoutSerializationInfo = new ODataCollectionStart();

            collectionStartWithSerializationInfo = new ODataCollectionStart();
            collectionStartWithSerializationInfo.SetSerializationInfo(new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(ns.Address)" });

            address = new ODataComplexValue { Properties = new[]
            {
                new ODataProperty { Name = "Street", Value = "1 Microsoft Way" }, 
                new ODataProperty { Name = "Zipcode", Value = 98052 }, 
                new ODataProperty { Name = "State", Value = new ODataEnumValue("WA", "ns.StateEnum") }, 
                new ODataProperty { Name = "City", Value = "Shanghai" }
            }, TypeName = "TestNamespace.DerivedAddress" };
            items = new[] { address };

            EdmComplexType addressType = new EdmComplexType("ns", "Address");
            addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(isNullable: true)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "Zipcode", EdmCoreModel.Instance.GetInt32(isNullable: true)));
            var stateEnumType = new EdmEnumType("ns", "StateEnum", isFlags: true);
            stateEnumType.AddMember("IL", new EdmIntegerConstant(1));
            stateEnumType.AddMember("WA", new EdmIntegerConstant(2));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "State", new EdmEnumTypeReference(stateEnumType, true)));
            
            EdmComplexType derivedAddressType = new EdmComplexType("ns", "DerivedAddress", addressType, false);
            derivedAddressType.AddProperty(new EdmStructuralProperty(derivedAddressType, "City", EdmCoreModel.Instance.GetString(isNullable: true)));

            addressTypeReference = new EdmComplexTypeReference(addressType, isNullable: false);
            derivedAddressTypeReference = new EdmComplexTypeReference(derivedAddressType, isNullable: false);
        }
コード例 #5
0
        public void GetEdmType_Returns_EdmTypeInitializedByCtor()
        {
            IEdmTypeReference elementType = new EdmComplexTypeReference(new EdmComplexType("NS", "Complex"), isNullable: false);
            IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType));

            var edmObject = new EdmComplexObjectCollection(collectionType);
            Assert.Same(collectionType, edmObject.GetEdmType());
        }
コード例 #6
0
 public void TypeNameShouldBeWrittenForUndeclaredComplexProperty()
 {
     var typeFromValue = new EdmComplexTypeReference(new EdmComplexType("Test", "ComplexType"), false);
     this.typeNameOracle.GetValueTypeNameForWriting(new ODataComplexValue {TypeName = "Test.ComplexType"},
         null,
         typeFromValue,
         /* isOpenProperty*/ true).Should().Be("Test.ComplexType");
 }
コード例 #7
0
 public void TypeNameShouldNotBeWrittenForDeclaredComplexProperty()
 {
     var typeFromMetadata = new EdmComplexTypeReference(new EdmComplexType("Test", "ComplexType"), true);
     var typeFromValue = new EdmComplexTypeReference(new EdmComplexType("Test", "ComplexType"), false);
     this.typeNameOracle.GetValueTypeNameForWriting(new ODataComplexValue {TypeName = "Test.ComplexType"},
         typeFromMetadata,
         typeFromValue,
         /* isOpenProperty*/ false).Should().BeNull();
 }
コード例 #8
0
        public void TryGetValue_ThrowsInvalidOperation_EdmComplexObjectNullRef()
        {
            IEdmComplexTypeReference edmType = new EdmComplexTypeReference(new EdmComplexType("NS", "ComplexType"), isNullable: true);
            NullEdmComplexObject nullComplexObject = new NullEdmComplexObject(edmType);
            object propertyValue;

            Assert.Throws<InvalidOperationException>(() => nullComplexObject.TryGetPropertyValue("property", out propertyValue),
                "Cannot get property 'property' of a null EDM object of type '[NS.ComplexType Nullable=True]'.");
        }
コード例 #9
0
        public void GetEdmType_Returns_CtorInitializedValue()
        {
            IEdmComplexTypeReference edmType = new EdmComplexTypeReference(new EdmComplexType("NS", "ComplexType"), isNullable: true);
            NullEdmComplexObject nullComplexObject = new NullEdmComplexObject(edmType);

            IEdmTypeReference result = nullComplexObject.GetEdmType();

            Assert.Same(edmType, result);
        }
コード例 #10
0
        public void EqualsOnComplexAndOtherComplexIsNotSupported()
        {
            var otherComplexType = new EdmComplexTypeReference(new EdmComplexType("NS", "OtherComplex"), true);
            IEdmTypeReference left = HardCodedTestModel.GetPersonAddressProp().Type;
            IEdmTypeReference right = otherComplexType;
            SingleValueNode leftNode = new SingleValuePropertyAccessNode(new ConstantNode(null)/*parent*/, new EdmStructuralProperty(new EdmEntityType("MyNamespace", "MyEntityType"), "myPropertyName", left));
            SingleValueNode rightNode = new SingleValuePropertyAccessNode(new ConstantNode(null)/*parent*/, new EdmStructuralProperty(new EdmEntityType("MyNamespace", "MyEntityType"), "myPropertyName", right));
            var result = TypePromotionUtils.PromoteOperandTypes(BinaryOperatorKind.Equal, leftNode, rightNode, out left, out right);

            result.Should().BeFalse();
            left.ShouldBeEquivalentTo(HardCodedTestModel.GetPersonAddressProp().Type);
            right.ShouldBeEquivalentTo(otherComplexType);
        }
コード例 #11
0
        public void TestInitialize()
        {
            this.MetadataDocumentUri = new Uri("http://www.myhost.com/myservice.svc/$metadata");

            this.model = new EdmModel();

            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer");
            this.model.AddElement(defaultContainer);

            this.cityType = new EdmEntityType("TestModel", "City");
            EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            cityType.AddKeys(cityIdProperty);
            cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false));
            cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false));
            this.model.AddElement(cityType);

            EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType");
            this.model.AddElement(complexType);

            this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationImportWithNoOverload = defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload);
            this.model.AddElement(operationWithNoOverload);

            this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param);

            this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(operationWithOverloadAnd1Param);
            this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param);
            
            this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            var cityTypeReference = new EdmEntityTypeReference(this.cityType, isNullable: false);
            this.operationWithOverloadAnd2Params.AddParameter("p1", cityTypeReference);
            this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true));
            this.model.AddElement(operationWithOverloadAnd2Params);
            this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params);

            this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(cityTypeReference)));
            this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false))));
            this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true));
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
            this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference);
            this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference)));
            this.model.AddElement(operationWithOverloadAnd5Params);
            this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params);
        }
コード例 #12
0
        public ODataAtomAnnotationReaderTests()
        {
            this.model = new EdmModel();
            this.model.AddElement(new EdmComplexType("foo", "complex"));
            EdmComplexType complexType = new EdmComplexType("ns", "complex");
            this.model.AddElement(complexType);
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
            EdmCollectionType primitiveCollectionType = new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Guid, isNullable: false));
            EdmCollectionType complexCollectionType = new EdmCollectionType(complexTypeReference);
            EdmCollectionTypeReference primitiveCollectionTypeReference = new EdmCollectionTypeReference(primitiveCollectionType);
            EdmCollectionTypeReference complexCollectionTypeReference = new EdmCollectionTypeReference(complexCollectionType);

            this.model.AddElement(new EdmTerm("custom", "primitive", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, isNullable: false)));
            this.model.AddElement(new EdmTerm("custom", "complex", complexTypeReference));
            this.model.AddElement(new EdmTerm("custom", "primitiveCollection", primitiveCollectionTypeReference));
            this.model.AddElement(new EdmTerm("custom", "complexCollection", complexCollectionTypeReference));

            this.shouldIncludeAnnotation = (annotationName) => true;
        }
コード例 #13
0
        public EdmLibraryExtensionsTests()
        {
            this.model = TestModel.BuildDefaultTestModel();
            this.defaultContainer = (EdmEntityContainer)this.model.FindEntityContainer("Default");
            this.productsSet = this.defaultContainer.FindEntitySet("Products");
            this.productType = (IEdmEntityType)this.model.FindDeclaredType("TestModel.Product");
            this.productTypeReference = new EdmEntityTypeReference(this.productType, false);

            EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType");

            this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithNoOverload.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(operationWithNoOverload);
            this.operationImportWithNoOverload = this.defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload);

            this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.model.AddElement(operationWithOverloadAnd0Param);
            this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param);

            this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            this.model.AddElement(operationWithOverloadAnd1Param);
            this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param);

            this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            var productTypeReference = new EdmEntityTypeReference(productType, isNullable: false);
            this.operationWithOverloadAnd2Params.AddParameter("p1", productTypeReference);
            this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true));
            this.model.AddElement(operationWithOverloadAnd2Params);
            this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params);

            this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true));
            this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(productTypeReference)));
            this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false))));
            this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true));
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
            this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference);
            this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference)));
            this.model.AddElement(operationWithOverloadAnd5Params);
            this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params);
        }
コード例 #14
0
ファイル: ModelBuilder.cs プロジェクト: larsenjo/odata.net
        public static IEdmModel TaupoDefaultModelEdm()
        {
            var model = new EdmModel();

            #region TaupoDefault Model code
            var phoneType = new EdmComplexType("NS1", "Phone");
            phoneType.AddStructuralProperty("PhoneNumber", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 16, isUnicode: false, isNullable: false));
            phoneType.AddStructuralProperty("Extension", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 16, isUnicode: false, isNullable: true));
            model.AddElement(phoneType);
            var phoneTypeReference = new EdmComplexTypeReference(phoneType, false);

            var contactDetailsType = new EdmComplexType("NS1", "ContactDetails");
            contactDetailsType.AddStructuralProperty("Email", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 32, isUnicode: false, isNullable: false));
            contactDetailsType.AddStructuralProperty("HomePhone", phoneTypeReference);
            contactDetailsType.AddStructuralProperty("WorkPhone", phoneTypeReference);
            contactDetailsType.AddStructuralProperty("MobilePhone", phoneTypeReference);
            model.AddElement(contactDetailsType);
            var contactDetailsTypeReference = new EdmComplexTypeReference(contactDetailsType, false);

            var concurrencyInfoType = new EdmComplexType("NS1", "ConcurrencyInfo");
            concurrencyInfoType.AddStructuralProperty("Token", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 20, isUnicode: false, isNullable: false), string.Empty, EdmConcurrencyMode.Fixed);
            concurrencyInfoType.AddStructuralProperty("QueriedDateTimeOffset", EdmCoreModel.Instance.GetDateTimeOffset(true));
            model.AddElement(concurrencyInfoType);
            var concurrencyInfoTypeReference = new EdmComplexTypeReference(concurrencyInfoType, false);

            var auditInfoType = new EdmComplexType("NS1", "AuditInfo");
            auditInfoType.AddStructuralProperty("ModifiedDate", EdmPrimitiveTypeKind.DateTimeOffset);
            auditInfoType.AddStructuralProperty("ModifiedBy", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 50, isUnicode: false, isNullable: false));
            auditInfoType.AddStructuralProperty("Concurrency", new EdmComplexTypeReference(concurrencyInfoType, false));
            model.AddElement(auditInfoType);
            var auditInfoTypeReference = new EdmComplexTypeReference(auditInfoType, false);

            var dimensionsType = new EdmComplexType("NS1", "Dimensions");
            dimensionsType.AddStructuralProperty("Width", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            dimensionsType.AddStructuralProperty("Height", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            dimensionsType.AddStructuralProperty("Depth", EdmCoreModel.Instance.GetDecimal(10, 3, false));
            model.AddElement(dimensionsType);
            var dimensionsTypeReference = new EdmComplexTypeReference(dimensionsType, false);

            var suspiciousActivityType = new EdmEntityType("NS1", "SuspiciousActivity");
            suspiciousActivityType.AddKeys(suspiciousActivityType.AddStructuralProperty("SuspiciousActivityId", EdmPrimitiveTypeKind.Int32, false));
            suspiciousActivityType.AddStructuralProperty("Activity", EdmPrimitiveTypeKind.String);
            model.AddElement(suspiciousActivityType);

            var messageType = new EdmEntityType("NS1", "Message");
            var fromUsername = messageType.AddStructuralProperty("FromUsername", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            messageType.AddKeys(messageType.AddStructuralProperty("MessageId", EdmPrimitiveTypeKind.Int32, false), fromUsername);
            var toUsername = messageType.AddStructuralProperty("ToUsername", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            messageType.AddStructuralProperty("Sent", EdmPrimitiveTypeKind.DateTimeOffset);
            messageType.AddStructuralProperty("Subject", EdmPrimitiveTypeKind.String);
            messageType.AddStructuralProperty("Body", EdmCoreModel.Instance.GetString(true));
            messageType.AddStructuralProperty("IsRead", EdmCoreModel.Instance.GetBoolean(false));
            model.AddElement(messageType);

            var loginType = new EdmEntityType("NS1", "Login");
            loginType.AddKeys(loginType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false)));
            var loginCustomerIdProperty = loginType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(loginType);

            var loginSentMessages = new EdmNavigationPropertyInfo { Name = "SentMessages", Target = messageType, TargetMultiplicity = EdmMultiplicity.Many };
            var messageSender = new EdmNavigationPropertyInfo { Name = "Sender", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { fromUsername }, PrincipalProperties = loginType.Key() };
            loginType.AddBidirectionalNavigation(loginSentMessages, messageSender);
            var loginReceivedMessages = new EdmNavigationPropertyInfo { Name = "ReceivedMessages", Target = messageType, TargetMultiplicity = EdmMultiplicity.Many };
            var messageRecipient = new EdmNavigationPropertyInfo { Name = "Recipient", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { fromUsername }, PrincipalProperties = loginType.Key() };
            loginType.AddBidirectionalNavigation(loginReceivedMessages, messageRecipient);
            var loginSuspiciousActivity = new EdmNavigationPropertyInfo { Name = "SuspiciousActivity", Target = suspiciousActivityType, TargetMultiplicity = EdmMultiplicity.Many };
            loginType.AddUnidirectionalNavigation(loginSuspiciousActivity);

            var lastLoginType = new EdmEntityType("NS1", "LastLogin");
            var userNameProperty = lastLoginType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            lastLoginType.AddKeys(userNameProperty);
            lastLoginType.AddStructuralProperty("LoggedIn", EdmPrimitiveTypeKind.DateTimeOffset);
            lastLoginType.AddStructuralProperty("LoggedOut", EdmCoreModel.Instance.GetDateTimeOffset(true));
            model.AddElement(lastLoginType);

            var loginLastLogin = new EdmNavigationPropertyInfo { Name = "LastLogin", Target = lastLoginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var lastLoginLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { userNameProperty }, PrincipalProperties = loginType.Key() };
            lastLoginType.AddBidirectionalNavigation(lastLoginLogin, loginLastLogin);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false));
            var orderCustomerId = orderType.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true));
            orderType.AddStructuralProperty("Concurrency", concurrencyInfoTypeReference);
            model.AddElement(orderType);

            var loginOrders = new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many };
            var orderLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            orderType.AddBidirectionalNavigation(orderLogin, loginOrders);

            var customerInfoType = new EdmEntityType("NS1", "CustomerInfo");
            customerInfoType.AddKeys(customerInfoType.AddStructuralProperty("CustomerInfoId", EdmPrimitiveTypeKind.Int32, false));
            customerInfoType.AddStructuralProperty("Information", EdmPrimitiveTypeKind.String);
            model.AddElement(customerInfoType);

            var customerType = new EdmEntityType("NS1", "Customer");
            var customerIdProperty = customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            customerType.AddKeys(customerIdProperty);
            customerType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isUnicode: false, isNullable: false));
            customerType.AddStructuralProperty("ContactInfo", contactDetailsTypeReference);
            model.AddElement(customerType);

            var customerOrders = new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
            var orderCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { orderCustomerId }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(customerOrders, orderCustomer);
            var customerLogins = new EdmNavigationPropertyInfo { Name = "Logins", Target = loginType, TargetMultiplicity = EdmMultiplicity.Many, };
            var loginCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { loginCustomerIdProperty }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(customerLogins, loginCustomer);
            var customerHusband = new EdmNavigationPropertyInfo { Name = "Husband", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var customerWife = new EdmNavigationPropertyInfo { Name = "Wife", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            customerType.AddBidirectionalNavigation(customerHusband, customerWife);
            var customerInfo = new EdmNavigationPropertyInfo { Name = "CustomerInfo", Target = customerInfoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            customerType.AddUnidirectionalNavigation(customerInfo);

            var productType = new EdmEntityType("NS1", "Product");
            productType.AddKeys(productType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false));
            productType.AddStructuralProperty("Description", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: true, maxLength: 1000, isUnicode: false));
            productType.AddStructuralProperty("Dimensions", dimensionsTypeReference);
            productType.AddStructuralProperty("BaseConcurrency", EdmCoreModel.Instance.GetString(false), string.Empty, EdmConcurrencyMode.Fixed);
            productType.AddStructuralProperty("ComplexConcurrency", concurrencyInfoTypeReference);
            productType.AddStructuralProperty("NestedComplexConcurrency", auditInfoTypeReference);
            model.AddElement(productType);

            var barCodeType = new EdmEntityType("NS1", "Barcode");
            barCodeType.AddKeys(barCodeType.AddStructuralProperty("Code", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50)));
            var barCodeProductIdProperty = barCodeType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            barCodeType.AddStructuralProperty("Text", EdmPrimitiveTypeKind.String);
            model.AddElement(barCodeType);

            var productBarCodes = new EdmNavigationPropertyInfo { Name = "Barcodes", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.Many };
            var barCodeProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { barCodeProductIdProperty }, PrincipalProperties = productType.Key() };
            barCodeType.AddBidirectionalNavigation(barCodeProduct, productBarCodes);

            var incorrectScanType = new EdmEntityType("NS1", "IncorrectScan");
            incorrectScanType.AddKeys(incorrectScanType.AddStructuralProperty("IncorrectScanId", EdmPrimitiveTypeKind.Int32, false));
            var expectedCodeProperty = incorrectScanType.AddStructuralProperty("ExpectedCode", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50));
            var actualCodeProperty = incorrectScanType.AddStructuralProperty("ActualCode", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: true, maxLength: 50));
            incorrectScanType.AddStructuralProperty("ScanDate", EdmPrimitiveTypeKind.DateTimeOffset);
            incorrectScanType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(incorrectScanType);

            var barCodeIncorrectScan = new EdmNavigationPropertyInfo { Name = "BadScans", Target = incorrectScanType, TargetMultiplicity = EdmMultiplicity.Many };
            var incorrectScanExpectedBarCode = new EdmNavigationPropertyInfo { Name = "ExpectedBarcode", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { expectedCodeProperty }, PrincipalProperties = barCodeType.Key() };
            incorrectScanType.AddBidirectionalNavigation(incorrectScanExpectedBarCode, barCodeIncorrectScan);
            var actualBarcode = new EdmNavigationPropertyInfo { Name = "ActualBarcode", Target = barCodeType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { actualCodeProperty }, PrincipalProperties = barCodeType.Key() };
            incorrectScanType.AddUnidirectionalNavigation(actualBarcode);

            var barCodeDetailType = new EdmEntityType("NS1", "BarcodeDetail");
            var codeProperty = barCodeDetailType.AddStructuralProperty("Code", EdmCoreModel.Instance.GetBinary(isUnbounded: false, isNullable: false, maxLength: 50));
            barCodeDetailType.AddKeys(codeProperty);
            barCodeDetailType.AddStructuralProperty("RegisteredTo", EdmPrimitiveTypeKind.String);
            model.AddElement(barCodeDetailType);

            var barCodeDetail = new EdmNavigationPropertyInfo { Name = "Detail", Target = barCodeDetailType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = barCodeType.Key(), PrincipalProperties = barCodeDetailType.Key() };
            barCodeType.AddUnidirectionalNavigation(barCodeDetail);

            var resolutionType = new EdmEntityType("NS1", "Resolution");
            resolutionType.AddKeys(resolutionType.AddStructuralProperty("ResolutionId", EdmPrimitiveTypeKind.Int32, false));
            resolutionType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(resolutionType);

            var complaintType = new EdmEntityType("NS1", "Complaint");
            complaintType.AddKeys(complaintType.AddStructuralProperty("ComplaintId", EdmPrimitiveTypeKind.Int32, false));
            var complaintCustomerId = complaintType.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(true));
            complaintType.AddStructuralProperty("Logged", EdmPrimitiveTypeKind.DateTimeOffset);
            complaintType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(complaintType);

            var complaintCustomer = new EdmNavigationPropertyInfo { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { complaintCustomerId }, PrincipalProperties = customerType.Key() };
            complaintType.AddUnidirectionalNavigation(complaintCustomer);
            var complaintResolution = new EdmNavigationPropertyInfo { Name = "Resolution", Target = resolutionType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var resolutionComplaint = new EdmNavigationPropertyInfo { Name = "Complaint", Target = complaintType, TargetMultiplicity = EdmMultiplicity.One };
            complaintType.AddBidirectionalNavigation(complaintResolution, resolutionComplaint);

            var smartCardType = new EdmEntityType("NS1", "SmartCard");
            var smartCardUsername = smartCardType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            smartCardType.AddKeys(smartCardUsername);
            smartCardType.AddStructuralProperty("CardSerial", EdmPrimitiveTypeKind.String);
            smartCardType.AddStructuralProperty("Issued", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(smartCardType);

            var smartCardLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { smartCardUsername }, PrincipalProperties = loginType.Key() };
            smartCardType.AddUnidirectionalNavigation(smartCardLogin);
            var smartCardLastLogin = new EdmNavigationPropertyInfo { Name = "LastLogin", Target = lastLoginType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            smartCardType.AddUnidirectionalNavigation(smartCardLastLogin);

            var rsaTokenType = new EdmEntityType("NS1", "RSAToken");
            rsaTokenType.AddKeys(rsaTokenType.AddStructuralProperty("Serial", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 20, isUnicode: false)));
            rsaTokenType.AddStructuralProperty("Issued", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(rsaTokenType);

            var rsaTokenLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One };
            rsaTokenType.AddUnidirectionalNavigation(rsaTokenLogin);

            var passwordResetType = new EdmEntityType("NS1", "PasswordReset");
            passwordResetType.AddKeys(passwordResetType.AddStructuralProperty("ResetNo", EdmPrimitiveTypeKind.Int32, false));
            var passwordResetUsername = passwordResetType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            passwordResetType.AddStructuralProperty("TempPassword", EdmPrimitiveTypeKind.String);
            passwordResetType.AddStructuralProperty("EmailedTo", EdmPrimitiveTypeKind.String);
            model.AddElement(passwordResetType);

            var passwordResetLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { passwordResetUsername }, PrincipalProperties = loginType.Key() };
            passwordResetType.AddUnidirectionalNavigation(passwordResetLogin);

            var pageViewType = new EdmEntityType("NS1", "PageView");
            pageViewType.AddKeys(pageViewType.AddStructuralProperty("PageViewId", EdmPrimitiveTypeKind.Int32, false));
            var pageViewUsername = pageViewType.AddStructuralProperty("Username", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 50, isUnicode: false));
            pageViewType.AddStructuralProperty("Viewed", EdmPrimitiveTypeKind.DateTimeOffset);
            pageViewType.AddStructuralProperty("PageUrl", EdmCoreModel.Instance.GetString(isUnbounded: false, isNullable: false, maxLength: 500, isUnicode: false));
            model.AddElement(pageViewType);

            var pageViewLogin = new EdmNavigationPropertyInfo { Name = "Login", Target = loginType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { pageViewUsername }, PrincipalProperties = loginType.Key() };
            pageViewType.AddUnidirectionalNavigation(pageViewLogin);

            var productPageViewType = new EdmEntityType("NS1", "ProductPageView", pageViewType);
            var productPageViewProductId = productPageViewType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(productPageViewType);

            var productPageViewProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productPageViewProductId }, PrincipalProperties = productType.Key() };
            productPageViewType.AddUnidirectionalNavigation(productPageViewProduct);

            var supplierType = new EdmEntityType("NS1", "Supplier");
            supplierType.AddKeys(supplierType.AddStructuralProperty("SupplierId", EdmPrimitiveTypeKind.Int32, false));
            supplierType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(supplierType);

            var supplierProducts = new EdmNavigationPropertyInfo { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many };
            var productSuppliers = new EdmNavigationPropertyInfo { Name = "Suppliers", Target = supplierType, TargetMultiplicity = EdmMultiplicity.Many };
            supplierType.AddBidirectionalNavigation(supplierProducts, productSuppliers);

            var supplierLogoType = new EdmEntityType("NS1", "SupplierLogo");
            var supplierLogoSupplierId = supplierLogoType.AddStructuralProperty("SupplierId", EdmPrimitiveTypeKind.Int32, false);
            supplierLogoType.AddKeys(supplierLogoSupplierId);
            supplierLogoType.AddStructuralProperty("Logo", EdmCoreModel.Instance.GetBinary(isNullable: false, isUnbounded: false, maxLength: 500));
            model.AddElement(supplierLogoType);

            var supplierSupplierLogo = new EdmNavigationPropertyInfo { Name = "Logo", Target = supplierLogoType, TargetMultiplicity = EdmMultiplicity.One, PrincipalProperties = new[] { supplierLogoSupplierId }, DependentProperties = supplierType.Key() };
            supplierType.AddUnidirectionalNavigation(supplierSupplierLogo);

            var supplierInfoType = new EdmEntityType("NS1", "SupplierInfo");
            supplierInfoType.AddKeys(supplierInfoType.AddStructuralProperty("SupplierInfoId", EdmPrimitiveTypeKind.Int32, false));
            supplierInfoType.AddStructuralProperty("Information", EdmPrimitiveTypeKind.String);
            model.AddElement(supplierInfoType);

            var supplierInfoSupplier = new EdmNavigationPropertyInfo { Name = "Supplier", Target = supplierType, TargetMultiplicity = EdmMultiplicity.One, OnDelete = EdmOnDeleteAction.Cascade };
            supplierInfoType.AddUnidirectionalNavigation(supplierInfoSupplier);

            var orderNoteType = new EdmEntityType("NS1", "OrderNote");
            orderNoteType.AddKeys(orderNoteType.AddStructuralProperty("NoteId", EdmPrimitiveTypeKind.Int32, false));
            orderNoteType.AddStructuralProperty("Note", EdmPrimitiveTypeKind.String);
            model.AddElement(orderNoteType);

            var orderNoteOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One };
            var orderOrderNotes = new EdmNavigationPropertyInfo { Name = "Notes", Target = orderNoteType, TargetMultiplicity = EdmMultiplicity.Many, OnDelete = EdmOnDeleteAction.Cascade };
            orderNoteType.AddBidirectionalNavigation(orderNoteOrder, orderOrderNotes);

            var orderQualityCheckType = new EdmEntityType("NS1", "OrderQualityCheck");
            var orderQualityCheckOrderId = orderQualityCheckType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false);
            orderQualityCheckType.AddKeys(orderQualityCheckOrderId);
            orderQualityCheckType.AddStructuralProperty("CheckedBy", EdmPrimitiveTypeKind.String);
            orderQualityCheckType.AddStructuralProperty("CheckedDateTime", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(orderQualityCheckType);

            var orderQualityCheckOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderQualityCheckOrderId }, PrincipalProperties = orderType.Key() };
            orderQualityCheckType.AddUnidirectionalNavigation(orderQualityCheckOrder);

            var orderLineType = new EdmEntityType("NS1", "OrderLine");
            var orderLineOrderId = orderLineType.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32, false);
            var orderLineProductId = orderLineType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            orderLineType.AddKeys(orderLineOrderId, orderLineProductId);
            orderLineType.AddStructuralProperty("Quantity", EdmPrimitiveTypeKind.Int32);
            orderLineType.AddStructuralProperty("ConcurrencyToken", EdmCoreModel.Instance.GetString(false), string.Empty, EdmConcurrencyMode.Fixed);
            model.AddElement(orderLineType);

            var orderLineOrder = new EdmNavigationPropertyInfo { Name = "Order", Target = orderType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderLineOrderId }, PrincipalProperties = orderType.Key() };
            var orderOrderLine = new EdmNavigationPropertyInfo { Name = "OrderLines", Target = orderLineType, TargetMultiplicity = EdmMultiplicity.Many };
            orderLineType.AddBidirectionalNavigation(orderLineOrder, orderOrderLine);

            var orderLineProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { orderLineProductId }, PrincipalProperties = productType.Key() };
            orderLineType.AddUnidirectionalNavigation(orderLineProduct);

            var backOrderLineType = new EdmEntityType("NS1", "BackOrderLine", orderLineType);
            backOrderLineType.AddStructuralProperty("ETA", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(backOrderLineType);

            var backOrderLineSupplier = new EdmNavigationPropertyInfo { Name = "Supplier", Target = supplierType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            var supplierBackOrderLines = new EdmNavigationPropertyInfo { Name = "BackOrderLines", Target = backOrderLineType, TargetMultiplicity = EdmMultiplicity.Many };
            backOrderLineType.AddBidirectionalNavigation(backOrderLineSupplier, supplierBackOrderLines);

            var backOrderLine2Type = new EdmEntityType("NS1", "BackOrderLine2", backOrderLineType);
            model.AddElement(backOrderLine2Type);

            var discontinuedProductType = new EdmEntityType("NS1", "DiscontinuedProduct", productType);
            discontinuedProductType.AddStructuralProperty("Discontinued", EdmPrimitiveTypeKind.DateTimeOffset);
            var replacementProductId = discontinuedProductType.AddStructuralProperty("ReplacementProductId", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(discontinuedProductType);

            var discontinuedProductReplacement = new EdmNavigationPropertyInfo { Name = "ReplacedBy", Target = productType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { replacementProductId }, PrincipalProperties = productType.Key() };
            var productReplaces = new EdmNavigationPropertyInfo { Name = "Replaces", Target = discontinuedProductType, TargetMultiplicity = EdmMultiplicity.Many, };
            discontinuedProductType.AddBidirectionalNavigation(discontinuedProductReplacement, productReplaces);

            var productDetailType = new EdmEntityType("NS1", "ProductDetail");
            var productDetailProductId = productDetailType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            productDetailType.AddKeys(productDetailProductId);
            productDetailType.AddStructuralProperty("Details", EdmPrimitiveTypeKind.String);
            model.AddElement(productDetailType);

            var productDetailProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productDetailProductId }, PrincipalProperties = productType.Key() };
            var productProductDetail = new EdmNavigationPropertyInfo { Name = "Detail", Target = productDetailType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne };
            productDetailType.AddBidirectionalNavigation(productDetailProduct, productProductDetail);

            var productReviewType = new EdmEntityType("NS1", "ProductReview");
            var productReviewProductId = productReviewType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            productReviewType.AddKeys(productReviewProductId, productReviewType.AddStructuralProperty("ReviewId", EdmPrimitiveTypeKind.Int32, false));
            productReviewType.AddStructuralProperty("Review", EdmPrimitiveTypeKind.String);
            model.AddElement(productReviewType);

            var productReviewProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productReviewProductId }, PrincipalProperties = productType.Key() };
            var productProductReviews = new EdmNavigationPropertyInfo { Name = "Reviews", Target = productReviewType, TargetMultiplicity = EdmMultiplicity.Many };
            productReviewType.AddBidirectionalNavigation(productReviewProduct, productProductReviews);

            var productPhotoType = new EdmEntityType("NS1", "ProductPhoto");
            var productPhotoProductId = productPhotoType.AddStructuralProperty("ProductId", EdmPrimitiveTypeKind.Int32, false);
            productPhotoType.AddKeys(productPhotoProductId, productPhotoType.AddStructuralProperty("PhotoId", EdmPrimitiveTypeKind.Int32, false));
            productPhotoType.AddStructuralProperty("Photo", EdmPrimitiveTypeKind.Binary);
            model.AddElement(productPhotoType);

            var productProductPhotos = new EdmNavigationPropertyInfo { Name = "Photos", Target = productPhotoType, TargetMultiplicity = EdmMultiplicity.Many };
            var productPhotoProduct = new EdmNavigationPropertyInfo { Name = "Product", Target = productType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { productPhotoProductId }, PrincipalProperties = productType.Key() };
            productType.AddBidirectionalNavigation(productProductPhotos, productPhotoProduct);

            var productWebFeatureType = new EdmEntityType("NS1", "ProductWebFeature");
            productWebFeatureType.AddKeys(productWebFeatureType.AddStructuralProperty("FeatureId", EdmPrimitiveTypeKind.Int32, false));
            var productWebFeatureProductId = productWebFeatureType.AddStructuralProperty("ProductId", EdmCoreModel.Instance.GetInt32(true));
            var productWebFeaturePhotoId = productWebFeatureType.AddStructuralProperty("PhotoId", EdmCoreModel.Instance.GetInt32(true));
            var productWebFeatureReviewId = productWebFeatureType.AddStructuralProperty("ReviewId", EdmCoreModel.Instance.GetInt32(true));
            productWebFeatureType.AddStructuralProperty("Heading", EdmPrimitiveTypeKind.String);
            model.AddElement(productWebFeatureType);

            var productReviewWebFeatures = new EdmNavigationPropertyInfo { Name = "Features", Target = productWebFeatureType, TargetMultiplicity = EdmMultiplicity.Many };
            var productWebFeatureReview = new EdmNavigationPropertyInfo { Name = "Review", Target = productReviewType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { productWebFeatureReviewId, productWebFeatureProductId }, PrincipalProperties = productReviewType.Key() };
            productWebFeatureType.AddBidirectionalNavigation(productWebFeatureReview, productReviewWebFeatures);

            var productPhotoWebFeatures = new EdmNavigationPropertyInfo { Name = "Features", Target = productWebFeatureType, TargetMultiplicity = EdmMultiplicity.Many };
            var productWebFeaturePhoto = new EdmNavigationPropertyInfo { Name = "Photo", Target = productPhotoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, DependentProperties = new[] { productWebFeaturePhotoId, productWebFeatureProductId }, PrincipalProperties = productPhotoType.Key() };
            productWebFeatureType.AddBidirectionalNavigation(productWebFeaturePhoto, productPhotoWebFeatures);

            var computerType = new EdmEntityType("NS1", "Computer");
            computerType.AddKeys(computerType.AddStructuralProperty("ComputerId", EdmPrimitiveTypeKind.Int32, false));
            computerType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(computerType);

            var computerDetailType = new EdmEntityType("NS1", "ComputerDetail");
            computerDetailType.AddKeys(computerDetailType.AddStructuralProperty("ComputerDetailId", EdmPrimitiveTypeKind.Int32, false));
            computerDetailType.AddStructuralProperty("Model", EdmPrimitiveTypeKind.String);
            computerDetailType.AddStructuralProperty("Serial", EdmPrimitiveTypeKind.String);
            computerDetailType.AddStructuralProperty("Specifications", EdmPrimitiveTypeKind.String);
            computerDetailType.AddStructuralProperty("PurchaseDate", EdmPrimitiveTypeKind.DateTimeOffset);
            computerDetailType.AddStructuralProperty("Dimensions", dimensionsTypeReference);
            model.AddElement(computerDetailType);

            var computerDetailComputer = new EdmNavigationPropertyInfo { Name = "Computer", Target = computerType, TargetMultiplicity = EdmMultiplicity.One };
            var computerComputerDetail = new EdmNavigationPropertyInfo { Name = "ComputerDetail", Target = computerDetailType, TargetMultiplicity = EdmMultiplicity.One };
            computerType.AddBidirectionalNavigation(computerComputerDetail, computerDetailComputer);

            var driverType = new EdmEntityType("NS1", "Driver");
            driverType.AddKeys(driverType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isNullable: false, isUnicode: false)));
            driverType.AddStructuralProperty("BirthDate", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(driverType);

            var licenseType = new EdmEntityType("NS1", "License");
            var licenseDriverName = licenseType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isUnbounded: false, maxLength: 100, isNullable: false, isUnicode: false));
            licenseType.AddKeys(licenseDriverName);
            licenseType.AddStructuralProperty("LicenseNumber", EdmPrimitiveTypeKind.String);
            licenseType.AddStructuralProperty("LicenseClass", EdmPrimitiveTypeKind.String);
            licenseType.AddStructuralProperty("Restrictions", EdmPrimitiveTypeKind.String);
            licenseType.AddStructuralProperty("ExpirationDate", EdmPrimitiveTypeKind.DateTimeOffset);
            model.AddElement(licenseType);

            var driverLicense = new EdmNavigationPropertyInfo { Name = "License", Target = licenseType, TargetMultiplicity = EdmMultiplicity.One, };
            var licenseDriver = new EdmNavigationPropertyInfo { Name = "Driver", Target = driverType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { licenseDriverName }, PrincipalProperties = driverType.Key() };
            licenseType.AddBidirectionalNavigation(licenseDriver, driverLicense);

            #endregion

            model.AddDefaultContainerFixup("NS1");
            return model;
        }
コード例 #15
0
ファイル: SQLDataSource.cs プロジェクト: maskx/OData
        IEdmTypeReference BuildTableValueType(string name, EdmModel model)
        {
            EdmEntityContainer container = model.EntityContainer as EdmEntityContainer;
            string spRtvTypeName = string.Format("{0}_RtvCollectionType", name);
            EdmComplexType t = null;
            t = new EdmComplexType("ns", spRtvTypeName);

            using (DbAccess db = new DbAccess(this.ConnectionString))
            {
                db.ExecuteReader(this.TableValuedResultSetCommand, (reader) =>
                {
                    var et = Utility.DBType2EdmType(reader["DATA_TYPE"].ToString());
                    if (et.HasValue)
                    {
                        string col = reader["COLUMN_NAME"].ToString();
                        t.AddStructuralProperty(col, et.Value, true);
                    }
                }, (par) => { par.AddWithValue("@Name", name); });
            }
            var etr = new EdmComplexTypeReference(t, true);
            var t1 = new EdmCollectionTypeReference(new EdmCollectionType(etr));
            model.AddElement((t1.Definition as EdmCollectionType).ElementType.Definition as IEdmSchemaElement);
            return t1;
        }
コード例 #16
0
ファイル: SQLDataSource.cs プロジェクト: maskx/OData
        IEdmTypeReference BuildSPReturnType(string spName, EdmModel model)
        {
            EdmEntityContainer container = model.EntityContainer as EdmEntityContainer;
            string spRtvTypeName = string.Format("{0}_RtvCollectionType", spName);
            EdmComplexType t = null;
            t = new EdmComplexType("ns", spRtvTypeName);

            using (DbAccess db = new DbAccess(this.ConnectionString))
            {
                db.ExecuteReader(StoredProcedureResultSetCommand, (reader) =>
                 {
                     if (reader.IsDBNull("DATA_TYPE"))
                         return;
                     var et = Utility.DBType2EdmType(reader["DATA_TYPE"].ToString());
                     if (et.HasValue)
                     {
                         string col = reader["COLUMN_NAME"].ToString();
                         if (string.IsNullOrEmpty(col))
                             throw new Exception(string.Format("{0} has wrong return type. see [exec GetEdmSPResultSet '{0}'] ", spName));
                         t.AddStructuralProperty(col, et.Value, true);
                     }
                 }, (par) => { par.AddWithValue("@Name", spName); });
            }
            var etr = new EdmComplexTypeReference(t, true);
            return new EdmCollectionTypeReference(new EdmCollectionType(etr));
        }
コード例 #17
0
        private static object ConvertComplexValue(ODataComplexValue complexValue, ref IEdmTypeReference propertyType,
            ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmComplexTypeReference edmComplexType;
            if (propertyType == null)
            {
                // open complex property
                Contract.Assert(!String.IsNullOrEmpty(complexValue.TypeName),
                    "ODataLib should have verified that open complex value has a type name since we provided metadata.");
                IEdmModel model = readContext.Model;
                IEdmType edmType = model.FindType(complexValue.TypeName);
                Contract.Assert(edmType.TypeKind == EdmTypeKind.Complex, "ODataLib should have verified that complex value has a complex resource type.");
                edmComplexType = new EdmComplexTypeReference(edmType as IEdmComplexType, isNullable: true);
                propertyType = edmComplexType;
            }
            else
            {
                edmComplexType = propertyType.AsComplex();
            }

            ODataEdmTypeDeserializer deserializer = deserializerProvider.GetEdmTypeDeserializer(edmComplexType);
            return deserializer.ReadInline(complexValue, propertyType, readContext);
        }
コード例 #18
0
        public void WritingMultipleInstanceAnnotationInComplexValueShouldSkipBaseOnSettings()
        {
            var complexType = new EdmComplexType("TestNamespace", "Address");
            model.AddElement(complexType);
            var result = this.SetupSerializerAndRunTest(serializer =>
            {
                var complexValue = new ODataComplexValue
                {
                    TypeName = "TestNamespace.Address",
                    InstanceAnnotations = new Collection<ODataInstanceAnnotation>
                    {
                        new ODataInstanceAnnotation("Annotation.1", new ODataPrimitiveValue(true)),
                        new ODataInstanceAnnotation("Annotation.2", new ODataPrimitiveValue(123)),
                        new ODataInstanceAnnotation("Annotation.3", new ODataPrimitiveValue("annotation"))
                    }
                };

                var complexTypeRef = new EdmComplexTypeReference(complexType, false);
                serializer.WriteComplexValue(complexValue, complexTypeRef, false, false, new DuplicatePropertyNamesChecker(false, true));
            });

            result.Should().NotContain("\"@Annotation.1\":true,\"@Annotation.2\":123,\"@Annotation.3\":\"annotation\"");
        }
コード例 #19
0
        public void WritingInstanceAnnotationInComplexValueShouldWrite()
        {
            var complexType = new EdmComplexType("TestNamespace", "Address");
            model.AddElement(complexType);
            settings.ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*");
            var result = this.SetupSerializerAndRunTest(serializer =>
            {
                var complexValue = new ODataComplexValue { TypeName = "TestNamespace.Address", InstanceAnnotations = new Collection<ODataInstanceAnnotation> { new ODataInstanceAnnotation("Is.ReadOnly", new ODataPrimitiveValue(true)) } };

                var complexTypeRef = new EdmComplexTypeReference(complexType, false);
                serializer.WriteComplexValue(complexValue, complexTypeRef, false, false, new DuplicatePropertyNamesChecker(false, true));
            });

            result.Should().Contain("\"@Is.ReadOnly\":true");
        }
コード例 #20
0
        private static IEdmModel GetUnTypedEdmModel()
        {
            EdmModel model = new EdmModel();

            // Enum type "Color"
            EdmEnumType colorEnum = new EdmEnumType("NS", "Color");
            colorEnum.AddMember(new EdmEnumMember(colorEnum, "Red", new EdmIntegerConstant(0)));
            colorEnum.AddMember(new EdmEnumMember(colorEnum, "Blue", new EdmIntegerConstant(1)));
            colorEnum.AddMember(new EdmEnumMember(colorEnum, "Green", new EdmIntegerConstant(2)));
            model.AddElement(colorEnum);

            // complex type "Address"
            EdmComplexType address = new EdmComplexType("NS", "Address");
            address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            model.AddElement(address);

            // derived complex type "SubAddress"
            EdmComplexType subAddress = new EdmComplexType("NS", "SubAddress", address);
            subAddress.AddStructuralProperty("Code", EdmPrimitiveTypeKind.Double);
            model.AddElement(subAddress);

            // entity type "Customer"
            EdmEntityType customer = new EdmEntityType("NS", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            customer.AddStructuralProperty("Location", new EdmComplexTypeReference(address, isNullable: true));
            model.AddElement(customer);

            // derived entity type special customer
            EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer);
            specialCustomer.AddStructuralProperty("Title", EdmPrimitiveTypeKind.Guid);
            model.AddElement(specialCustomer);

            // entity sets
            EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
            model.AddElement(container);
            container.AddEntitySet("FCustomers", customer);

            EdmComplexTypeReference complexType = new EdmComplexTypeReference(address, isNullable: false);
            EdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(complexType));

            EdmEnumTypeReference enumType = new EdmEnumTypeReference(colorEnum, isNullable: false);
            EdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(enumType));

            EdmEntityTypeReference entityType = new EdmEntityTypeReference(customer, isNullable: false);
            EdmCollectionTypeReference entityCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(entityType));

            IEdmTypeReference intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true);
            EdmCollectionTypeReference primitiveCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(intType));

            // bound functions
            BoundFunction(model, "IntCollectionFunction", "intValues", primitiveCollectionType, entityType);

            BoundFunction(model, "ComplexFunction", "address", complexType, entityType);

            BoundFunction(model, "ComplexCollectionFunction", "addresses", complexCollectionType, entityType);

            BoundFunction(model, "EnumFunction", "color", enumType, entityType);

            BoundFunction(model, "EnumCollectionFunction", "colors", enumCollectionType, entityType);

            BoundFunction(model, "EntityFunction", "customer", entityType, entityType);

            BoundFunction(model, "CollectionEntityFunction", "customers", entityCollectionType, entityType);

            // unbound functions
            UnboundFunction(container, "UnboundIntCollectionFunction", "intValues", primitiveCollectionType);

            UnboundFunction(container, "UnboundComplexFunction", "address", complexType);

            UnboundFunction(container, "UnboundComplexCollectionFunction", "addresses", complexCollectionType);

            UnboundFunction(container, "UnboundEnumFunction", "color", enumType);

            UnboundFunction(container, "UnboundEnumCollectionFunction", "colors", enumCollectionType);

            UnboundFunction(container, "UnboundEntityFunction", "customer", entityType);

            UnboundFunction(container, "UnboundCollectionEntityFunction", "customers", entityCollectionType);

            model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));
            return model;
        }
コード例 #21
0
 public void ParsingInstanceAnnotationsInComplexValueShouldReadComplexValue()
 {
     var model = new EdmModel();
     var complexType = new EdmComplexType("TestNamespace", "Address");
     model.AddElement(complexType);
     var complexTypeRef = new EdmComplexTypeReference(complexType, false);
     this.messageReaderSettings = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
     ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@Annotation.1\":true,\"@Annotation.2\":123,\"Annotation.3\":\"annotation\"}", model));
     deserializer.JsonReader.Read();
     ODataComplexValue complexValue = (ODataComplexValue)deserializer.ReadNonEntityValue(
         /*payloadTypeName*/ null,
         complexTypeRef,
         /*duplicatePropertyNamesChecker*/ null,
         /*collectionValidator*/ null,
         /*validateNullValue*/ true,
         /*isTopLevelPropertyValue*/ false,
         /*insideComplexValue*/ false,
         /*propertyName*/ null);
     complexValue.InstanceAnnotations.Count.Should().Be(3);
     TestUtils.AssertODataValueAreEqual(new ODataPrimitiveValue(true), complexValue.InstanceAnnotations.Single(ia => ia.Name == "Annotation.1").Value);
     TestUtils.AssertODataValueAreEqual(new ODataPrimitiveValue(123), complexValue.InstanceAnnotations.Single(ia => ia.Name == "Annotation.2").Value);
     TestUtils.AssertODataValueAreEqual(new ODataPrimitiveValue("annotation"), complexValue.InstanceAnnotations.Single(ia => ia.Name == "Annotation.3").Value);
 }
コード例 #22
0
        public void CreateODataComplexValue_ReturnsNull_ForNullEdmComplexObject()
        {
            IEdmComplexTypeReference edmType = new EdmComplexTypeReference(_addressType, isNullable: true);
            ODataComplexTypeSerializer serializer = new ODataComplexTypeSerializer(new DefaultODataSerializerProvider());

            var result = serializer.CreateODataComplexValue(new NullEdmComplexObject(edmType), edmType, new ODataSerializerContext());

            Assert.Null(result);
        }
コード例 #23
0
        public void GetDefaultValue_NonNullableComplexCollection()
        {
            IEdmTypeReference elementType = new EdmComplexTypeReference(new EdmComplexType("NS", "Complex"), isNullable: true);
            IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType));

            var result = EdmStructuredObject.GetDefaultValue(complexCollectionType);

            var complexCollectionObject = Assert.IsType<EdmComplexObjectCollection>(result);
            Assert.Equal(complexCollectionType, complexCollectionObject.GetEdmType(), new EdmTypeReferenceEqualityComparer());
        }
コード例 #24
0
        private static IEdmModel GetModelWithFunctions()
        {
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            var container = model.Container;
            IEdmTypeReference boolType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference customerType = model.Customer.AsReference();
            IEdmTypeReference addressType = new EdmComplexTypeReference(model.Address, isNullable: false);
            IEdmTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(customerType));

            AddFunction(model, "unBoundWithoutParams");

            var unBoundWithOneParam = AddFunction(model, "unBoundWithOneParam");
            unBoundWithOneParam.AddParameter("Param", boolType);

            var unBoundWithMultipleParams = AddFunction(model, "unBoundWithMultipleParams");
            unBoundWithMultipleParams.AddParameter("Param1", boolType);
            unBoundWithMultipleParams.AddParameter("Param2", boolType);
            unBoundWithMultipleParams.AddParameter("Param3", boolType);

            AddFunction(model, "BoundToEntityNoParams", bindingParameterType: customerType);

            var boundToEntity = AddFunction(model, "BoundToEntity", bindingParameterType: customerType);
            boundToEntity.AddParameter("Param", boolType);

            AddFunction(model, "BoundToEntityReturnsEntityNoParams",
                returnType: customerType, entitySet: model.Customers, bindingParameterType: customerType);

            AddFunction(model, "BoundToEntityReturnsEntityCollectionNoParams",
                returnType: customersType, entitySet: model.Customers, bindingParameterType: customerType);

            AddFunction(model, "BoundToEntityCollection", bindingParameterType: customersType);

            AddFunction(model, "BoundToEntityCollectionReturnsComplex", bindingParameterType: customersType, returnType: addressType);

            return model.Model;
        }
コード例 #25
0
        /// <summary>
        /// Deserializes the given <paramref name="complexValue"/> under the given <paramref name="readContext"/>.
        /// </summary>
        /// <param name="complexValue">The complex value to deserialize.</param>
        /// <param name="complexType">The EDM type of the complex value to read.</param>
        /// <param name="readContext">The deserializer context.</param>
        /// <returns>The deserialized complex value.</returns>
        public virtual object ReadComplexValue(ODataComplexValue complexValue, IEdmComplexTypeReference complexType,
            ODataDeserializerContext readContext)
        {
            if (complexValue == null)
            {
                throw Error.ArgumentNull("complexValue");
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            if (readContext.Model == null)
            {
                throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
            }

            if (!String.IsNullOrEmpty(complexValue.TypeName) && complexType.FullName() != complexValue.TypeName)
            {
                // received a derived complex type in a base type deserializer.
                IEdmModel model = readContext.Model;
                if (model == null)
                {
                    throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext);
                }

                IEdmComplexType actualType = model.FindType(complexValue.TypeName) as IEdmComplexType;
                if (actualType == null)
                {
                    throw new ODataException(Error.Format(SRResources.ComplexTypeNotInModel, complexValue.TypeName));
                }

                if (actualType.IsAbstract)
                {
                    string message = Error.Format(SRResources.CannotInstantiateAbstractComplexType,
                        complexValue.TypeName);
                    throw new ODataException(message);
                }

                IEdmTypeReference actualComplexType = new EdmComplexTypeReference(actualType, isNullable: false);
                ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(actualComplexType);
                if (deserializer == null)
                {
                    throw new SerializationException(
                        Error.Format(SRResources.TypeCannotBeDeserialized, actualComplexType.FullName(),
                            typeof(ODataMediaTypeFormatter).Name));
                }

                object resource = deserializer.ReadInline(complexValue, actualComplexType, readContext);

                EdmStructuredObject structuredObject = resource as EdmStructuredObject;
                if (structuredObject != null)
                {
                    structuredObject.ExpectedEdmType = complexType.ComplexDefinition();
                }

                return resource;
            }
            else
            {
                object complexResource = CreateResource(complexType, readContext);

                foreach (ODataProperty complexProperty in complexValue.Properties)
                {
                    DeserializationHelpers.ApplyProperty(complexProperty, complexType, complexResource,
                        DeserializerProvider, readContext);
                }
                return complexResource;
            }
        }
コード例 #26
0
 public void ParsingExpectedComplexPropertyActualNotShouldThrow()
 {
     var model = new EdmModel();
     var complexType = new EdmComplexType("TestNamespace", "Address");
     model.AddElement(complexType);
     var complexTypeRef = new EdmComplexTypeReference(complexType, false);
     ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("\"CountryRegion\":\"China\"", model));
     deserializer.JsonReader.Read();
     Action action = () => deserializer.ReadNonEntityValue(
          /*payloadTypeName*/ null,
          complexTypeRef,
          /*duplicatePropertyNamesChecker*/ null,
          /*collectionValidator*/ null,
          /*validateNullValue*/ true,
          /*isTopLevelPropertyValue*/ false,
          /*insideComplexValue*/ false,
          /*propertyName*/ "Home");
     action.ShouldThrow<ODataException>().WithMessage(
         string.Format(CultureInfo.InvariantCulture,
         "The property with name '{0}' was found with a value node of type '{1}'; however, a complex value of type '{2}' was expected.",
         "Home", "PrimitiveValue", "TestNamespace.Address"));
 }
コード例 #27
0
        public void GetDefaultValue_NonNullableComplex()
        {
            IEdmTypeReference nonNullableComplexType = new EdmComplexTypeReference(new EdmComplexType("NS", "Complex"), isNullable: false);

            var result = EdmStructuredObject.GetDefaultValue(nonNullableComplexType);

            var complexObject = Assert.IsType<EdmComplexObject>(result);
            Assert.Equal(nonNullableComplexType, complexObject.GetEdmType(), new EdmTypeReferenceEqualityComparer());
        }
コード例 #28
0
 public void ParsingInstanceAnnotationsInComplexPropertyShouldSkipBaseOnSettings()
 {
     var model = new EdmModel();
     var complexType = new EdmComplexType("TestNamespace", "Address");
     complexType.AddStructuralProperty("CountryRegion", EdmPrimitiveTypeKind.String);
     model.AddElement(complexType);
     var complexTypeRef = new EdmComplexTypeReference(complexType, false);
     ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"[email protected]\":true,\"CountryRegion\":\"China\"}", model));
     deserializer.JsonReader.Read();
     ODataComplexValue complexValue = (ODataComplexValue)deserializer.ReadNonEntityValue(
         /*payloadTypeName*/ null,
         complexTypeRef,
         /*duplicatePropertyNamesChecker*/ null,
         /*collectionValidator*/ null,
         /*validateNullValue*/ true,
         /*isTopLevelPropertyValue*/ false,
         /*insideComplexValue*/ false,
         /*propertyName*/ null);
     complexValue.Properties.First().InstanceAnnotations.Count.Should().Be(0);
 }
コード例 #29
0
        public void CreateODataComplexValue_Understands_IEdmComplexTypeObject()
        {
            // Arrange
            EdmComplexType complexEdmType = new EdmComplexType("NS", "ComplexType");
            complexEdmType.AddStructuralProperty("Property", EdmPrimitiveTypeKind.Int32);
            IEdmComplexTypeReference edmTypeReference = new EdmComplexTypeReference(complexEdmType, isNullable: false);

            ODataSerializerContext context = new ODataSerializerContext();
            TypedEdmComplexObject edmObject = new TypedEdmComplexObject(new { Property = 42 }, edmTypeReference, context.Model);
            ODataComplexTypeSerializer serializer = new ODataComplexTypeSerializer(new DefaultODataSerializerProvider());

            // Act
            ODataComplexValue result = serializer.CreateODataComplexValue(edmObject, edmTypeReference, context);

            // Assert
            Assert.Equal("Property", result.Properties.Single().Name);
            Assert.Equal(42, result.Properties.Single().Value);
        }
コード例 #30
0
 public void ParsingInstanceAnnotationInComplexValueShouldThrowOnReservedODataAnnotationNamesNotApplicableToComplexValues()
 {
     var model = new EdmModel();
     var complexType = new EdmComplexType("TestNamespace", "Address");
     model.AddElement(complexType);
     var complexTypeRef = new EdmComplexTypeReference(complexType, false);
     this.messageReaderSettings = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
     ODataJsonLightPropertyAndValueDeserializer deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@odata.count\":\"123\"}", model));
     deserializer.JsonReader.Read();
     Action action = () => deserializer.ReadNonEntityValue(
         /*payloadTypeName*/ null,
         complexTypeRef,
         /*duplicatePropertyNamesChecker*/ null,
         /*collectionValidator*/ null,
         /*validateNullValue*/ true,
         /*isTopLevelPropertyValue*/ false,
         /*insideComplexValue*/ false,
         /*propertyName*/ null);
     action.ShouldThrow<ODataException>().WithMessage(ErrorStrings.ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties("odata.count"));
 }