diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/E2ETestBase.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/E2ETestBase.cs
index 2f212378..e2855c5f 100644
--- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/E2ETestBase.cs
+++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/E2ETestBase.cs
@@ -155,6 +155,21 @@ protected void TestPostStatusCodeIs(string uriStringAfterServiceRoot, int status
Assert.Equal(statusCode, response.StatusCode);
}
}
+
+ protected async void TestPatchStatusCodeIs(string uriStringAfterServiceRoot, string patchContent, HttpStatusCode statusCode)
+ {
+ var requestUri = string.Format("{0}/{1}", this.ServiceBaseUri, uriStringAfterServiceRoot);
+ var request = new HttpRequestMessage(new HttpMethod("PATCH"), requestUri);
+
+ request.Content = new StringContent(patchContent);
+ request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
+
+ HttpClient client = new HttpClient();
+ HttpResponseMessage response = await client.SendAsync(request);
+
+ Assert.Equal(statusCode, response.StatusCode);
+ }
+
#endregion
protected void ResetDataSource()
diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/Microsoft.OData.Service.Sample.Tests.csproj b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/Microsoft.OData.Service.Sample.Tests.csproj
index 1938e67e..d845fe7a 100644
--- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/Microsoft.OData.Service.Sample.Tests.csproj
+++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/Microsoft.OData.Service.Sample.Tests.csproj
@@ -80,6 +80,7 @@
..\..\..\packages\FluentAssertions.4.13.0\lib\net45\FluentAssertions.Core.dll
True
+
..\..\..\packages\Microsoft.OData.Client.6.15.0\lib\net40\Microsoft.OData.Client.dll
True
@@ -96,6 +97,10 @@
..\..\..\packages\Microsoft.Spatial.6.15.0\lib\portable-net45+win+wpa81\Microsoft.Spatial.dll
True
+
+ ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
+ True
+
diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/TrippinInMemoryE2ETest.cs b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/TrippinInMemoryE2ETest.cs
index bcc6d1e0..fbf5449f 100644
--- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/TrippinInMemoryE2ETest.cs
+++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/TrippinInMemoryE2ETest.cs
@@ -1,6 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
+using System;
+using System.Net;
+using System.Text.RegularExpressions;
+using Newtonsoft.Json;
using Xunit;
namespace Microsoft.OData.Service.Sample.Tests
@@ -158,5 +162,46 @@ public void TestRawValuedEnumPropertyAccess()
{
TestGetPayloadIs("People('russellwhyte')/FavoriteFeature/$value", "Feature1");
}
+
+ [Fact]
+ public void TestPatchSuccessfully()
+ {
+ // Get origin content and sessionId.
+ var uriStringAfterServiceRoot = "Airports('KLAX')";
+ var originContent = default(string);
+ Action getContent = p => originContent = p;
+ TestGetPayload(uriStringAfterServiceRoot, getContent);
+ var sessionId = GetSessionIdFromResponse(originContent);
+ Assert.NotNull(sessionId);
+
+ // Patch it.
+ uriStringAfterServiceRoot = string.Format(@"(S({0}))/{1}", sessionId, uriStringAfterServiceRoot);
+ var changedRegion = "TestRegion";
+ var changedAddress = "1 World Way, Los Angeles, CA, 90045";
+ string patchContent =
+ string.Format(
+ "{{\r\n \"Location\":{{\r\n \"Address\":\"{0}\",\r\n \"City\":{{\r\n \"Region\":\"{1}\"\r\n }}\r\n }}\r\n}}",
+ changedAddress,
+ changedRegion);
+ TestPatchStatusCodeIs(uriStringAfterServiceRoot, patchContent, HttpStatusCode.NoContent);
+
+ // Test patch results.
+ dynamic content = JsonConvert.DeserializeObject(originContent);
+ content.Location.Address = changedAddress;
+ content.Location.City.Region = changedRegion;
+ string changedContent = JsonConvert.SerializeObject(content);
+ TestGetPayloadContains(uriStringAfterServiceRoot, changedContent);
+ }
+
+ private static string GetSessionIdFromResponse(string response)
+ {
+ var match = Regex.Match(response, @"/\(S\((\w+)\)\)");
+ if (match.Success)
+ {
+ return match.Groups[1].Value;
+ }
+
+ return default(string);
+ }
}
}
\ No newline at end of file
diff --git a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/packages.config b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/packages.config
index 740423ac..ad199180 100644
--- a/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/packages.config
+++ b/test/ODataEndToEnd/Microsoft.OData.Service.Sample.Tests/packages.config
@@ -5,6 +5,7 @@
+
diff --git a/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Submit/ChangeSetInitializer.cs b/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Submit/ChangeSetInitializer.cs
index de00f286..ec7bc2a9 100644
--- a/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Submit/ChangeSetInitializer.cs
+++ b/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Submit/ChangeSetInitializer.cs
@@ -202,7 +202,7 @@ private static void SetValues(object instance, Type type, IReadOnlyDictionary