public void EdmDeltaEntityObject_IsDeltaObject_ReturnsTrueForDeltaObject() { IEdmEntityType _type = new EdmEntityType("NS", "Entity"); EdmDeltaEntityObject _edmObject = new EdmDeltaEntityObject(_type); Assert.True(_edmObject.IsDeltaResource()); }
public IHttpActionResult Get() { EdmChangedObjectCollection changedCollection = new EdmChangedObjectCollection(DeltaCustomerType); //Changed or Modified objects are represented as EdmDeltaEntityObjects for (int i = 0; i < 10; i++) { dynamic untypedCustomer = new EdmDeltaEntityObject(DeltaCustomerType); untypedCustomer.Id = i; untypedCustomer.Name = string.Format("Name {0}", i); untypedCustomer.FavoriteNumbers = Enumerable.Range(0, i).ToArray(); changedCollection.Add(untypedCustomer); } //Deleted objects are represented as EdmDeltaDeletedObjects for (int i = 10; i < 15; i++) { dynamic untypedCustomer = new EdmDeltaDeletedEntityObject(DeltaCustomerType); untypedCustomer.Id = i.ToString(); untypedCustomer.Reason = DeltaDeletedEntryReason.Deleted; changedCollection.Add(untypedCustomer); } return(Ok(changedCollection)); }
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 }; }
private void WriteDeltaEntry(object graph, ODataDeltaWriter writer, ODataSerializerContext writeContext) { Contract.Assert(writeContext != null); IEdmEntityTypeReference entityType = GetEntityType(graph, writeContext); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(writeContext, entityType, graph); SelectExpandNode selectExpandNode = CreateSelectExpandNode(entityInstanceContext); EdmDeltaEntityObject deltaResource = graph as EdmDeltaEntityObject; if (deltaResource != null && deltaResource.NavigationSource != null) { entityInstanceContext.NavigationSource = deltaResource.NavigationSource; } if (selectExpandNode != null) { ODataEntry entry = CreateEntry(selectExpandNode, entityInstanceContext); if (entry != null) { writer.WriteStart(entry); //TODO: Need to add support to write Navigation Links using Delta Writer //https://github.com/OData/odata.net/issues/155 writer.WriteEnd(); } } }
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(); }
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)); }