public void ClientShouldSendTypeAnnotationsForOpenServerPropertiesForAddRelatedObject()
 {
     this.TestClientOpenPropertyPayload((ctx, e) =>
     {
         var parent = new TestClientEntityType {
             ID = 1234
         };
         ctx.AttachTo("Parents", parent);
         ctx.AddRelatedObject(parent, "Navigation", e);
     });
 }
 public void ClientShouldSendTypeAnnotationsForOpenServerPropertiesForAddRelatedObject()
 {
     this.TestClientOpenPropertyPayload((ctx, e) =>
     {
         var parent = new TestClientEntityType { ID = 1234 };
         ctx.AttachTo("Parents", parent);
         ctx.AddRelatedObject(parent, "Navigation", e);
     });
 }
        public void Init()
        {
            this.serverModel = new EdmModel();
            this.serverEntityType = new EdmEntityType("Server.NS", "ServerEntityType");
            this.serverEntityTypeName = "Server.NS.ServerEntityType";
            this.serverModel.AddElement(this.serverEntityType);
            this.serverEntityType.AddKeys(this.serverEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            
            var addressType = new EdmComplexType("Server.NS", "Address");
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            this.serverEntityType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
            this.serverComplexTypeName = "Server.NS.Address";

            var homeAddressType = new EdmComplexType("Server.NS", "HomeAddress", addressType);
            homeAddressType.AddStructuralProperty("FamilyName", EdmPrimitiveTypeKind.String);
            this.serverComplexTypeName = "Server.NS.HomeAddress";

            var colorType = new EdmEnumType("Server.NS", "Color");
            colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmIntegerConstant(1)));
            colorType.AddMember(new EdmEnumMember(colorType, "Blue", new EdmIntegerConstant(2)));
            colorType.AddMember(new EdmEnumMember(colorType, "Green", new EdmIntegerConstant(3)));
            this.serverEntityType.AddStructuralProperty("Color", new EdmEnumTypeReference(colorType, false));

            this.serverEntityType.AddStructuralProperty("Nicknames", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(false))));
            this.serverEntityType.AddStructuralProperty("OtherAddresses", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressType, false))));

            this.clientModel = new ClientEdmModel(ODataProtocolVersion.V4);
            this.clientTypeAnnotation = this.clientModel.GetClientTypeAnnotation(typeof(TestClientEntityType));

            this.context = new DataServiceContext(new Uri("http://temp/"), ODataProtocolVersion.V4, this.clientModel);
            this.context.Format.UseJson(this.serverModel);

            this.testSubject = new ODataPropertyConverter(new RequestInfo(this.context));

            this.context.Format.UseJson(this.serverModel);
            this.context.ResolveName = t =>
                                       {
                                           if (t == typeof(TestClientEntityType))
                                           {
                                               return this.serverEntityTypeName;
                                           }

                                           if (t == typeof(Address))
                                           {
                                               return this.serverComplexTypeName;
                                           }

                                           return null;
                                       };
            this.entity = new TestClientEntityType
            {
                Id = 1, 
                Name = "foo", 
                Number = 1.23f, 
                Address = new Address(),
                OpenAddress = new Address(), 
                Nicknames = new string[0],
                OtherAddresses = new[] { new Address() },
                Color = 0
            };
            this.entityWithDerivedComplexProperty = new TestClientEntityType
            {
                Id = 1,
                Name = "foo",
                Number = 1.23f,
                Address = new HomeAddress(),
                OpenAddress = new Address(),
                Nicknames = new string[0],
                OtherAddresses = new[] { new Address() }
            };
            this.entityWithDerivedComplexInCollection = new TestClientEntityType
            {
                Id = 1,
                Name = "foo",
                Number = 1.23f,
                Address = new HomeAddress(),
                OpenAddress = new Address(),
                Nicknames = new string[0],
                OtherAddresses = new[] { new Address(), new HomeAddress() }
            };
        }
Ejemplo n.º 4
0
        public void Init()
        {
            this.serverModel          = new EdmModel();
            this.serverEntityType     = new EdmEntityType("Server.NS", "ServerEntityType");
            this.serverEntityTypeName = "Server.NS.ServerEntityType";
            this.serverModel.AddElement(this.serverEntityType);
            this.serverEntityType.AddKeys(this.serverEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));

            var addressType = new EdmComplexType("Server.NS", "Address");

            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            this.serverEntityType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
            this.serverComplexTypeName = "Server.NS.Address";

            var homeAddressType = new EdmComplexType("Server.NS", "HomeAddress", addressType);

            homeAddressType.AddStructuralProperty("FamilyName", EdmPrimitiveTypeKind.String);
            this.serverComplexTypeName = "Server.NS.HomeAddress";

            var colorType = new EdmEnumType("Server.NS", "Color");

            colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmEnumMemberValue(1)));
            colorType.AddMember(new EdmEnumMember(colorType, "Blue", new EdmEnumMemberValue(2)));
            colorType.AddMember(new EdmEnumMember(colorType, "Green", new EdmEnumMemberValue(3)));
            this.serverEntityType.AddStructuralProperty("Color", new EdmEnumTypeReference(colorType, false));

            this.serverEntityType.AddStructuralProperty("Nicknames", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(false))));
            this.serverEntityType.AddStructuralProperty("OtherAddresses", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressType, false))));

            this.clientModel          = new ClientEdmModel(ODataProtocolVersion.V4);
            this.clientTypeAnnotation = this.clientModel.GetClientTypeAnnotation(typeof(TestClientEntityType));

            this.context = new DataServiceContext(new Uri("http://temp/"), ODataProtocolVersion.V4, this.clientModel);
            this.context.Format.UseJson(this.serverModel);

            this.testSubject = new ODataPropertyConverter(new RequestInfo(this.context));

            this.context.Format.UseJson(this.serverModel);
            this.context.ResolveName = t =>
            {
                if (t == typeof(TestClientEntityType))
                {
                    return(this.serverEntityTypeName);
                }

                if (t == typeof(Address))
                {
                    return(this.serverComplexTypeName);
                }

                return(null);
            };
            this.entity = new TestClientEntityType
            {
                Id             = 1,
                Name           = "foo",
                Number         = 1.23f,
                Address        = new Address(),
                OpenAddress    = new Address(),
                Nicknames      = new string[0],
                OtherAddresses = new[] { new Address() },
                Color          = 0
            };
            this.entityWithDerivedComplexProperty = new TestClientEntityType
            {
                Id             = 1,
                Name           = "foo",
                Number         = 1.23f,
                Address        = new HomeAddress(),
                OpenAddress    = new Address(),
                Nicknames      = new string[0],
                OtherAddresses = new[] { new Address() }
            };
            this.entityWithDerivedComplexInCollection = new TestClientEntityType
            {
                Id             = 1,
                Name           = "foo",
                Number         = 1.23f,
                Address        = new HomeAddress(),
                OpenAddress    = new Address(),
                Nicknames      = new string[0],
                OtherAddresses = new[] { new Address(), new HomeAddress() }
            };
        }