public void JsonSerializationWith_SimpleContent_Count() { var responseContent = new ODataResponseContent( null, new[] { 1, 2, 3 }, count: 5); var jsonResult = JsonConvert.SerializeObject(responseContent); Assert.Equal("{\"@odata.count\":5,\"value\":[1,2,3]}", jsonResult); }
public void JsonSerializationWith_SimpleContent_Count() { var responseContent = new ODataResponseContent { Count = 5, Value = new[] { 1, 2, 3 }, }; string jsonResult = JsonSerializer.Serialize(responseContent, TestHelper.JsonSerializerOptions); Assert.Equal("{\"@odata.count\":5,\"value\":[1,2,3]}", jsonResult); }
public void JsonSerializationWith_Context_DynamicContent_Count() { dynamic item = new ExpandoObject(); item.Id = 14225; item.Name = "Fred"; var responseContent = new ODataResponseContent( new Uri("http://services.odata.org/OData/$metadata#Products"), new[] { item }, count: 12); var jsonResult = JsonConvert.SerializeObject(responseContent); Assert.Equal("{\"@odata.context\":\"http://services.odata.org/OData/$metadata#Products\",\"@odata.count\":12,\"value\":[{\"Id\":14225,\"Name\":\"Fred\"}]}", jsonResult); }
public void JsonSerializationWith_Context_ClassContent_Count() { var item = new Thing(); item.Name = "Coffee"; item.Total = 2.55M; var responseContent = new ODataResponseContent( new Uri("http://services.odata.org/OData/$metadata#Products"), new[] { item }, count: 12); var jsonResult = JsonConvert.SerializeObject(responseContent); Assert.Equal("{\"@odata.context\":\"http://services.odata.org/OData/$metadata#Products\",\"@odata.count\":12,\"value\":[{\"Name\":\"Coffee\",\"Total\":2.55}]}", jsonResult); }
public void JsonSerializationWith_ClassContent_Count() { var item = new Thing(); item.Name = "Coffee"; item.Total = 2.55M; var responseContent = new ODataResponseContent( null, new[] { item }, count: 12); var jsonResult = JsonConvert.SerializeObject(responseContent); Assert.Equal("{\"@odata.count\":12,\"value\":[{\"Name\":\"Coffee\",\"Total\":2.55}]}", jsonResult); }
public void JsonSerializationWith_DynamicContent_Count() { dynamic item = new ExpandoObject(); item.Id = 14225; item.Name = "Fred"; var responseContent = new ODataResponseContent( null, new[] { item }, count: 12); var jsonResult = JsonConvert.SerializeObject(responseContent); Assert.Equal("{\"@odata.count\":12,\"value\":[{\"Id\":14225,\"Name\":\"Fred\"}]}", jsonResult); }
public void JsonSerializationWith_DynamicContent_Count() { dynamic item = new ExpandoObject(); item.Id = 14225; item.Name = "Fred"; var responseContent = new ODataResponseContent { Count = 12, Value = new[] { item }, }; string jsonResult = JsonSerializer.Serialize(responseContent, TestHelper.JsonSerializerOptions); Assert.Equal("{\"@odata.count\":12,\"value\":[{\"Id\":14225,\"Name\":\"Fred\"}]}", jsonResult); }
public void JsonSerializationWith_ClassContent_Count() { var item = new Thing { Name = "Coffee", Total = 2.55M }; var responseContent = new ODataResponseContent { Count = 12, Value = new[] { item }, }; string jsonResult = JsonSerializer.Serialize(responseContent, TestHelper.JsonSerializerOptions); Assert.Equal("{\"@odata.count\":12,\"value\":[{\"name\":\"Coffee\",\"total\":2.55}]}", jsonResult); }
public void JsonSerializationWith_Context_DynamicContent_Count() { dynamic item = new ExpandoObject(); item.Id = 14225; item.Name = "Fred"; var responseContent = new ODataResponseContent { Context = "http://services.odata.org/OData/$metadata#Products", Count = 12, Value = new[] { item }, }; string jsonResult = JsonConvert.SerializeObject(responseContent, TestHelper.JsonSerializerSettings); Assert.Equal("{\"@odata.context\":\"http://services.odata.org/OData/$metadata#Products\",\"@odata.count\":12,\"value\":[{\"id\":14225,\"name\":\"Fred\"}]}", jsonResult); }
public HttpResponseMessage Get() { var requestOptions = this.Request.ReadODataRequestOptions(); Uri contextUri = this.Request.ResolveODataContextUri(); var serviceDocumentResponse = new ODataResponseContent( contextUri, EntityDataModel.Current.EntitySets.Select( kvp => { var setUri = new Uri(kvp.Key, UriKind.Relative); setUri = requestOptions.MetadataLevel == ODataMetadataLevel.None ? new Uri(requestOptions.DataServiceUri, setUri) : setUri; return(ServiceDocumentItem.EntitySet(kvp.Key, setUri)); })); return(this.Request.CreateODataResponse(HttpStatusCode.OK, serviceDocumentResponse)); }
public void JsonSerializationWith_Context_ClassContent_Count() { var item = new Thing { Name = "Coffee", Total = 2.55M }; var responseContent = new ODataResponseContent { Context = "http://services.odata.org/OData/$metadata#Products", Count = 12, Value = new[] { item }, }; string jsonResult = JsonConvert.SerializeObject(responseContent, TestHelper.JsonSerializerSettings); Assert.Equal("{\"@odata.context\":\"http://services.odata.org/OData/$metadata#Products\",\"@odata.count\":12,\"value\":[{\"name\":\"Coffee\",\"total\":2.55}]}", jsonResult); }
public WhenConstructed() { this.responseContent = new ODataResponseContent(context, value, count, nextLink); }