public bool MyAction(ODataUntypedActionParameters parameters) { Assert.True(parameters.ContainsKey("Customer")); dynamic customer = parameters["Customer"] as EdmEntityObject; Assert.NotNull(customer); Assert.Equal(101, customer.ID); Assert.Equal("Avatar", customer.Name); Assert.True(parameters.ContainsKey("Customers")); IEnumerable <IEdmObject> customers = parameters["Customers"] as EdmEntityObjectCollection; Assert.Equal(2, customers.Count()); EdmEntityObject entity = customers.First() as EdmEntityObject; IEdmTypeReference typeReference = entity.GetEdmType(); Assert.Equal("System.Web.OData.Formatter.Customer", typeReference.FullName()); customer = customers.First(); Assert.NotNull(customer); Assert.Equal(901, customer.ID); Assert.Equal("John", customer.Name); entity = customers.Last() as EdmEntityObject; typeReference = entity.GetEdmType(); Assert.Equal("System.Web.OData.Formatter.SubCustomer", typeReference.FullName()); customer = customers.Last(); Assert.NotNull(customer); Assert.Equal(902, customer.ID); Assert.Equal("Mike", customer.Name); Assert.Equal(9.9, customer.Price); return(true); }
public bool EntityFunction(int key, [FromODataUri] EdmEntityObject customer) { Assert.NotNull(customer); dynamic result = customer; Assert.Equal("NS.Customer", customer.GetEdmType().FullName()); // entity call if (key == 9) { Assert.Equal(91, result.Id); Assert.Equal("John", result.Name); dynamic address = result.Location; EdmComplexObject addressObj = Assert.IsType <EdmComplexObject>(address); Assert.Equal("NS.Address", addressObj.GetEdmType().FullName()); Assert.Equal("NE 24th St.", address.Street); Assert.Equal("Redmond", address.City); } else { // entity reference call Assert.Equal(8, result.Id); Assert.Equal("Id", String.Join(",", customer.GetChangedPropertyNames())); Assert.Equal("Name,Location", String.Join(",", customer.GetUnchangedPropertyNames())); } return(true); }
public void CreateEntityResource_CreatesEdmEntityObject_IfTypeLessMode() { // Arrange var deserializer = new ODataEntityDeserializer(_deserializerProvider); ODataDeserializerContext readContext = new ODataDeserializerContext { Model = _readContext.Model, ResourceType = typeof(IEdmObject) }; // Act var result = deserializer.CreateEntityResource(_productEdmType, readContext); // Assert EdmEntityObject resource = Assert.IsType <EdmEntityObject>(result); Assert.Equal(_productEdmType, resource.GetEdmType(), new EdmTypeReferenceEqualityComparer()); }
public bool CollectionEntityFunction(int key, [FromODataUri] EdmEntityObjectCollection customers) { Assert.NotNull(customers); IList <IEdmEntityObject> results = customers.ToList(); Assert.Equal(2, results.Count); // entities call if (key == 9) { // #1 EdmEntityObject entity = results[0] as EdmEntityObject; Assert.NotNull(entity); Assert.Equal("NS.Customer", entity.GetEdmType().FullName()); dynamic customer = results[0]; Assert.Equal(91, customer.Id); Assert.Equal("John", customer.Name); dynamic address = customer.Location; EdmComplexObject addressObj = Assert.IsType <EdmComplexObject>(address); Assert.Equal("NS.Address", addressObj.GetEdmType().FullName()); Assert.Equal("NE 24th St.", address.Street); Assert.Equal("Redmond", address.City); // #2 entity = results[1] as EdmEntityObject; Assert.Equal("NS.SpecialCustomer", entity.GetEdmType().FullName()); customer = results[1]; Assert.Equal(92, customer.Id); Assert.Equal("Mike", customer.Name); address = customer.Location; addressObj = Assert.IsType <EdmComplexObject>(address); Assert.Equal("NS.SubAddress", addressObj.GetEdmType().FullName()); Assert.Equal("LianHua Rd.", address.Street); Assert.Equal("Shanghai", address.City); Assert.Equal(9.9, address.Code); Assert.Equal(new Guid("883F50C5-F554-4C49-98EA-F7CACB41658C"), customer.Title); } else { // entity references call int id = 81; foreach (IEdmEntityObject edmObj in results) { EdmEntityObject entity = edmObj as EdmEntityObject; Assert.NotNull(entity); Assert.Equal("NS.Customer", entity.GetEdmType().FullName()); dynamic customer = entity; Assert.Equal(id++, customer.Id); Assert.Equal("Id", String.Join(",", customer.GetChangedPropertyNames())); Assert.Equal("Name,Location", String.Join(",", customer.GetUnchangedPropertyNames())); } } return(true); }
public static void PrepareHttpResponseMessage(ref HttpResponseMessage msg, string mediaType, DataObjectEdmModel model, byte[] buffer) { List <IEdmEntityObject> edmObjList = new List <IEdmEntityObject>(); var edmObj = new EdmEntityObject(model.GetEdmEntityType(typeof(DataObject))); edmObj.TrySetPropertyValue("__PrimaryKey", buffer); edmObjList.Add(edmObj); IEdmCollectionTypeReference entityCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(edmObj.GetEdmType())); EdmEntityObjectCollection collection = new EdmEntityObjectCollection(entityCollectionType, edmObjList); msg.Content = new ObjectContent(typeof(EdmEntityObjectCollection), collection, new RawOutputFormatter(), mediaType); }