diff options
author | youssefm <youssefm@microsoft.com> | 2012-09-18 03:01:40 +0400 |
---|---|---|
committer | youssefm <youssefm@microsoft.com> | 2012-09-18 03:22:20 +0400 |
commit | ace8494b4e887f859a31aa8c0910e0dec2bcedb8 (patch) | |
tree | 97178f958d3191c0f15db6d0e9923f984f20138a | |
parent | 1d34d93f06658fd66a9449664ccfffba505319fe (diff) |
Getting the partial trust tests for the OData formatter to also test deserialization
4 files changed, 51 insertions, 12 deletions
diff --git a/test/System.Web.Http.OData.Test/BaselineResource.Designer.cs b/test/System.Web.Http.OData.Test/BaselineResource.Designer.cs index 0df8d84a..c0210cc4 100644 --- a/test/System.Web.Http.OData.Test/BaselineResource.Designer.cs +++ b/test/System.Web.Http.OData.Test/BaselineResource.Designer.cs @@ -232,6 +232,24 @@ namespace System.Web.Http.OData { } /// <summary> + /// Looks up a localized string similar to { + /// "PerId":10, + /// "Age":10, + /// "MyGuid":"f99080c0-2f9e-472e-8c72-1a8ecd9f902d", + /// "Name":"Asha", + /// "Order":{ + /// "OrderAmount":235342, + /// "OrderName":"FirstOrder" + /// } + ///}. + /// </summary> + internal static string ODataJsonPersonRequest { + get { + return ResourceManager.GetString("ODataJsonPersonRequest", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8" standalone="yes"?> ///<entry xml:base="http://services.odata.org/OData/OData.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> /// <title type="text">Bread</title> diff --git a/test/System.Web.Http.OData.Test/BaselineResource.resx b/test/System.Web.Http.OData.Test/BaselineResource.resx index 92495c02..320f74cb 100644 --- a/test/System.Web.Http.OData.Test/BaselineResource.resx +++ b/test/System.Web.Http.OData.Test/BaselineResource.resx @@ -210,6 +210,18 @@ <value><?xml version="1.0" encoding="utf-8"?> <d:ID xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:null="true" /></value> </data> + <data name="ODataJsonPersonRequest" xml:space="preserve"> + <value>{ + "PerId":10, + "Age":10, + "MyGuid":"f99080c0-2f9e-472e-8c72-1a8ecd9f902d", + "Name":"Asha", + "Order":{ + "OrderAmount":235342, + "OrderName":"FirstOrder" + } +}</value> + </data> <data name="ProductInsertData" xml:space="preserve"> <value><?xml version="1.0" encoding="utf-8" standalone="yes"?> <entry xml:base="http://services.odata.org/OData/OData.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> diff --git a/test/System.Web.Http.OData.Test/OData/Formatter/PartialTrustTest.cs b/test/System.Web.Http.OData.Test/OData/Formatter/PartialTrustTest.cs index 8b61a69c..77cd29dc 100644 --- a/test/System.Web.Http.OData.Test/OData/Formatter/PartialTrustTest.cs +++ b/test/System.Web.Http.OData.Test/OData/Formatter/PartialTrustTest.cs @@ -3,6 +3,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Text; using Microsoft.TestCommon; namespace System.Web.Http.OData.Formatter @@ -13,23 +14,23 @@ namespace System.Web.Http.OData.Formatter const string baseAddress = "http://localhost:8081/"; [Fact] - public void GetEntry_InODataAtomFormat() + public void PostEntry_InODataAtomFormat() { var _config = new HttpConfiguration(); _config.Routes.MapHttpRoute(ODataRouteNames.GetById, "{controller}({id})"); _config.Routes.MapHttpRoute(ODataRouteNames.Default, "{controller}"); - _config.Formatters.Insert(0, new ODataMediaTypeFormatter(ODataTestUtil.GetEdmModel())); + _config.SetODataFormatter(new ODataMediaTypeFormatter(ODataTestUtil.GetEdmModel())); using (HttpServer host = new HttpServer(_config)) { var _client = new HttpClient(host); - HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(baseAddress + "People(10)")); - requestMessage.Headers.Accept.Add(ODataTestUtil.ApplicationAtomMediaTypeWithQuality); + HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(baseAddress + "People")); + requestMessage.Content = new StringContent(BaselineResource.EntryTypePersonAtom, Encoding.UTF8, "application/atom+xml"); using (HttpResponseMessage response = _client.SendAsync(requestMessage).Result) { Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(ODataTestUtil.ApplicationAtomMediaType.MediaType, response.Content.Headers.ContentType.MediaType); + Assert.Equal(HttpStatusCode.Created, response.StatusCode); + Assert.Equal("application/atom+xml", response.Content.Headers.ContentType.MediaType); ODataTestUtil.VerifyResponse(response.Content, BaselineResource.EntryTypePersonAtom); } @@ -37,23 +38,24 @@ namespace System.Web.Http.OData.Formatter } [Fact] - public void GetEntry_InODataJsonFormat() + public void PostEntry_InODataJsonFormat() { var _config = new HttpConfiguration(); _config.Routes.MapHttpRoute(ODataRouteNames.GetById, "{controller}({id})"); _config.Routes.MapHttpRoute(ODataRouteNames.Default, "{controller}"); - _config.Formatters.Insert(0, new ODataMediaTypeFormatter(ODataTestUtil.GetEdmModel())); + _config.SetODataFormatter(new ODataMediaTypeFormatter(ODataTestUtil.GetEdmModel())); using (HttpServer host = new HttpServer(_config)) { var _client = new HttpClient(host); - HttpRequestMessage requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Get, new Uri(baseAddress + "People(10)")); - requestMessage.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata=verbose")); + HttpRequestMessage requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, new Uri(baseAddress + "People")); + requestMessage.Content = new StringContent(BaselineResource.ODataJsonPersonRequest); + requestMessage.Content.Headers.ContentType = ODataTestUtil.ApplicationJsonMediaType; using (HttpResponseMessage response = _client.SendAsync(requestMessage).Result) { Assert.NotNull(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Equal(ODataTestUtil.ApplicationJsonMediaType.MediaType, response.Content.Headers.ContentType.MediaType); + Assert.Equal(HttpStatusCode.Created, response.StatusCode); + Assert.Equal("application/json;odata=verbose", response.Content.Headers.ContentType.MediaType); ODataTestUtil.VerifyJsonResponse(response.Content, BaselineResource.EntryTypePersonODataJson); } diff --git a/test/System.Web.Http.OData.Test/OData/Formatter/PeopleController.cs b/test/System.Web.Http.OData.Test/OData/Formatter/PeopleController.cs index aaaf16a8..ae6c175c 100644 --- a/test/System.Web.Http.OData.Test/OData/Formatter/PeopleController.cs +++ b/test/System.Web.Http.OData.Test/OData/Formatter/PeopleController.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Net; +using System.Net.Http; namespace System.Web.Http.OData.Formatter { @@ -21,5 +23,10 @@ namespace System.Web.Http.OData.Formatter FormatterPerson obj = new FormatterPerson() { MyGuid = new Guid("f99080c0-2f9e-472e-8c72-1a8ecd9f902d"), PerId = id, Age = 10, Name = "Asha", Order = new FormatterOrder() { OrderName = "FirstOrder", OrderAmount = 235342 } }; return obj; } + + public HttpResponseMessage PostPerson(FormatterPerson person) + { + return Request.CreateResponse(HttpStatusCode.Created, person); + } } } |