public IActionResult Get() { EdmChangedObjectCollection changedCollection = new EdmChangedObjectCollection(DeltaCustomerType); //Changed or Modified objects are represented as EdmDeltaResourceObjects for (int i = 0; i < 10; i++) { dynamic typelessCustomer = new EdmDeltaResourceObject(DeltaCustomerType); typelessCustomer.Id = i; typelessCustomer.Name = string.Format("Name {0}", i); typelessCustomer.FavoriteNumbers = Enumerable.Range(0, i).ToArray(); changedCollection.Add(typelessCustomer); } //Deleted objects are represented as EdmDeltaDeletedObjects for (int i = 10; i < 15; i++) { dynamic typelessCustomer = new EdmDeltaDeletedResourceObject(DeltaCustomerType); typelessCustomer.Id = new Uri(i.ToString(), UriKind.RelativeOrAbsolute); typelessCustomer.Reason = DeltaDeletedEntryReason.Deleted; changedCollection.Add(typelessCustomer); } return(Ok(changedCollection)); }
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 }; }
public void GetEdmType_Returns_EdmTypeInitializedByCtor() { IEdmEntityType _entityType = new EdmEntityType("NS", "Entity"); var edmObject = new EdmChangedObjectCollection(_entityType); IEdmCollectionTypeReference collectionTypeReference = (IEdmCollectionTypeReference)edmObject.GetEdmType(); Assert.Same(_entityType, collectionTypeReference.ElementType().Definition); }
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)); }
/// <inheritdoc /> public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext) { if (item == null) { return(null); } if (edmType == null) { throw Error.ArgumentNull(nameof(edmType)); } if (readContext == null) { throw Error.ArgumentNull(nameof(readContext)); } if (!edmType.IsCollection() || !edmType.AsCollection().ElementType().IsStructured()) { throw Error.Argument(nameof(edmType), SRResources.TypeMustBeResourceSet, edmType.ToTraceString()); } ODataDeltaResourceSetWrapper resourceSet = item as ODataDeltaResourceSetWrapper; if (resourceSet == null) { throw Error.Argument(nameof(item), SRResources.ArgumentMustBeOfType, typeof(ODataDeltaResourceSetWrapper).Name); } // Recursion guard to avoid stack overflows RuntimeHelpers.EnsureSufficientExecutionStack(); IEdmStructuredTypeReference elementType = edmType.AsCollection().ElementType().AsStructured(); IEnumerable result = ReadDeltaResourceSet(resourceSet, elementType, readContext); if (result != null) { if (readContext.IsNoClrType) { EdmChangedObjectCollection changedObjCollection = new EdmChangedObjectCollection(elementType.Definition as IEdmEntityType); foreach (IEdmChangedObject changedObject in result) { changedObjCollection.Add(changedObject); } return(changedObjCollection); } else { Type elementClrType = readContext.Model.GetClrType(elementType); Type changedObjCollType = typeof(DeltaSet <>).MakeGenericType(elementClrType); IDeltaSet deltaSet = Activator.CreateInstance(changedObjCollType) as IDeltaSet; foreach (var delta in result) { IDeltaSetItem deltaItem = delta as IDeltaSetItem; if (deltaItem != null) { deltaSet.Add(deltaItem); } } return(deltaSet); } } else { return(result); } }
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); }