public ODataDeltaFeedSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
            _path = new ODataPath(new EntitySetPathSegment(_customerSet));
            _customers = new[] {
                new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    ID = 10,
                },
                new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    ID = 42,
                }
            };

            _deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType());
            EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType());
            newCustomer.TrySetPropertyValue("ID", 10);
            newCustomer.TrySetPropertyValue("FirstName", "Foo");
            _deltaFeedCustomers.Add(newCustomer);

             _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();

            _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path };
        }
Beispiel #2
0
        public ODataDeltaFeedSerializerTests()
        {
            _model       = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
            _path      = new ODataPath(new EntitySetPathSegment(_customerSet));
            _customers = new[] {
                new Customer()
                {
                    FirstName = "Foo",
                    LastName  = "Bar",
                    ID        = 10,
                },
                new Customer()
                {
                    FirstName = "Foo",
                    LastName  = "Bar",
                    ID        = 42,
                }
            };

            _deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType());
            EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType());

            newCustomer.TrySetPropertyValue("ID", 10);
            newCustomer.TrySetPropertyValue("FirstName", "Foo");
            _deltaFeedCustomers.Add(newCustomer);

            _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();

            _writeContext = new ODataSerializerContext()
            {
                NavigationSource = _customerSet, Model = _model, Path = _path
            };
        }
        public ODataDeltaFeedSerializerTests()
        {
            _model       = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
            _path      = new ODataPath(new EntitySetSegment(_customerSet));
            _customers = new[] {
                new Customer()
                {
                    FirstName   = "Foo",
                    LastName    = "Bar",
                    ID          = 10,
                    HomeAddress = new Address()
                    {
                        Street  = "Street",
                        ZipCode = null,
                    }
                },
                new Customer()
                {
                    FirstName = "Foo",
                    LastName  = "Bar",
                    ID        = 42,
                }
            };

            _deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType());
            EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType());

            newCustomer.TrySetPropertyValue("ID", 10);
            newCustomer.TrySetPropertyValue("FirstName", "Foo");
            EdmDeltaComplexObject newCustomerAddress = new EdmDeltaComplexObject(_model.FindType("Default.Address") as IEdmComplexType);

            newCustomerAddress.TrySetPropertyValue("Street", "Street");
            newCustomerAddress.TrySetPropertyValue("ZipCode", null);
            newCustomer.TrySetPropertyValue("HomeAddress", newCustomerAddress);
            _deltaFeedCustomers.Add(newCustomer);

            _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();

            _writeContext = new ODataSerializerContext()
            {
                NavigationSource = _customerSet, Model = _model, Path = _path
            };
            _serializerProvider = ODataSerializerProviderFactory.Create();
        }
Beispiel #4
0
        public IHttpActionResult Get()
        {
            IEdmEntityType             customerType            = Request.GetModel().FindDeclaredType("WebStack.QA.Test.OData.TestCustomer") as IEdmEntityType;
            IEdmEntityType             customerWithAddressType = Request.GetModel().FindDeclaredType("WebStack.QA.Test.OData.TestCustomerWithAddress") as IEdmEntityType;
            IEdmComplexType            addressType             = Request.GetModel().FindDeclaredType("WebStack.QA.Test.OData.TestAddress") as IEdmComplexType;
            IEdmEntityType             orderType      = Request.GetModel().FindDeclaredType("WebStack.QA.Test.OData.TestOrder") as IEdmEntityType;
            IEdmEntitySet              ordersSet      = Request.GetModel().FindDeclaredEntitySet("TestOrders") as IEdmEntitySet;
            EdmChangedObjectCollection changedObjects = new EdmChangedObjectCollection(customerType);

            EdmDeltaComplexObject a = new EdmDeltaComplexObject(addressType);

            a.TrySetPropertyValue("State", "State");
            a.TrySetPropertyValue("ZipCode", null);

            EdmDeltaEntityObject changedEntity = new EdmDeltaEntityObject(customerWithAddressType);

            changedEntity.TrySetPropertyValue("Id", 1);
            changedEntity.TrySetPropertyValue("Name", "Name");
            changedEntity.TrySetPropertyValue("Address", a);
            changedEntity.TrySetPropertyValue("PhoneNumbers", new List <String> {
                "123-4567", "765-4321"
            });
            changedEntity.TrySetPropertyValue("OpenProperty", 10);
            changedEntity.TrySetPropertyValue("NullOpenProperty", null);
            changedObjects.Add(changedEntity);

            EdmComplexObjectCollection places = new EdmComplexObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressType, true))));
            EdmDeltaComplexObject      b      = new EdmDeltaComplexObject(addressType);

            b.TrySetPropertyValue("City", "City2");
            b.TrySetPropertyValue("State", "State2");
            b.TrySetPropertyValue("ZipCode", 12345);
            b.TrySetPropertyValue("OpenProperty", 10);
            b.TrySetPropertyValue("NullOpenProperty", null);
            places.Add(a);
            places.Add(b);

            var newCustomer = new EdmDeltaEntityObject(customerType);

            newCustomer.TrySetPropertyValue("Id", 10);
            newCustomer.TrySetPropertyValue("Name", "NewCustomer");
            newCustomer.TrySetPropertyValue("FavoritePlaces", places);
            changedObjects.Add(newCustomer);

            var newOrder = new EdmDeltaEntityObject(orderType);

            newOrder.NavigationSource = ordersSet;
            newOrder.TrySetPropertyValue("Id", 27);
            newOrder.TrySetPropertyValue("Amount", 100);
            changedObjects.Add(newOrder);

            var deletedCustomer = new EdmDeltaDeletedEntityObject(customerType);

            deletedCustomer.Id     = "7";
            deletedCustomer.Reason = DeltaDeletedEntryReason.Changed;
            changedObjects.Add(deletedCustomer);

            var deletedOrder = new EdmDeltaDeletedEntityObject(orderType);

            deletedOrder.NavigationSource = ordersSet;
            deletedOrder.Id     = "12";
            deletedOrder.Reason = DeltaDeletedEntryReason.Deleted;
            changedObjects.Add(deletedOrder);

            var deletedLink = new EdmDeltaDeletedLink(customerType);

            deletedLink.Source       = new Uri("http://localhost/odata/DeltaCustomers(1)");
            deletedLink.Target       = new Uri("http://localhost/odata/DeltaOrders(12)");
            deletedLink.Relationship = "Orders";
            changedObjects.Add(deletedLink);

            var addedLink = new EdmDeltaLink(customerType);

            addedLink.Source       = new Uri("http://localhost/odata/DeltaCustomers(10)");
            addedLink.Target       = new Uri("http://localhost/odata/DeltaOrders(27)");
            addedLink.Relationship = "Orders";
            changedObjects.Add(addedLink);

            return(Ok(changedObjects));
        }