-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Revert media type change for Newtonsoft JsonPatch package #65559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f76da1a
Revert media type change for Newtonsoft JsonPatch package
halter73 81e2e34
Update src/Features/JsonPatch/test/JsonPatchContentTypeEndToEndTest.cs
halter73 165b727
Merge branch 'main' into halter73/65325
halter73 ff373c2
Simplify tests to not need to find solution root
halter73 f67034f
Add back `using System.Threading.Tasks;`
halter73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/Features/JsonPatch.SystemTextJson/test/JsonPatchContentTypeEndToEndTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.IO; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.AspNetCore.InternalTesting; | ||
| using Microsoft.AspNetCore.Mvc.Testing; | ||
| using Microsoft.AspNetCore.TestHost; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.AspNetCore.JsonPatch.SystemTextJson; | ||
|
|
||
| public class JsonPatchContentTypeEndToEndTest : LoggedTest | ||
| { | ||
| [Theory] | ||
| [InlineData("/untyped", "application/json-patch+json", true)] | ||
| [InlineData("/typed", "application/json-patch+json", true)] | ||
| [InlineData("/untyped", "application/json", false)] | ||
| [InlineData("/typed", "application/json", false)] | ||
| [InlineData("/untyped", "text/plain", false)] | ||
| [InlineData("/typed", "text/plain", false)] | ||
| public async Task PatchContentTypes_AreHandledAsExpected(string route, string contentType, bool shouldBeAccepted) | ||
| { | ||
| using var factory = new JsonPatchWebApplicationFactory(LoggerFactory); | ||
| using var client = factory.CreateClient(); | ||
|
|
||
| using var content = new StringContent("[]", Encoding.UTF8, contentType); | ||
|
|
||
| using var response = await client.PatchAsync(route, content); | ||
|
|
||
| var expectedStatusCode = shouldBeAccepted ? HttpStatusCode.OK : HttpStatusCode.UnsupportedMediaType; | ||
| Assert.Equal(expectedStatusCode, response.StatusCode); | ||
| } | ||
|
|
||
| private sealed class JsonPatchWebApplicationFactory(ILoggerFactory loggerFactory) : WebApplicationFactory<JsonPatchContentTypeEndToEndTest> | ||
| { | ||
| protected override void ConfigureWebHost(IWebHostBuilder builder) => builder.UseContentRoot(Directory.GetCurrentDirectory()); | ||
|
|
||
| protected override IHostBuilder CreateHostBuilder() | ||
| { | ||
| return new HostBuilder().ConfigureWebHost(webHostBuilder => | ||
| { | ||
| webHostBuilder | ||
| .UseTestServer() | ||
| .ConfigureServices(services => services.AddRouting().AddSingleton(loggerFactory)) | ||
| .Configure(app => | ||
| { | ||
| app.UseRouting(); | ||
| app.UseEndpoints(endpoints => | ||
| { | ||
| endpoints.MapPatch("/untyped", (JsonPatchDocument patch) => { }); | ||
| endpoints.MapPatch("/typed", (JsonPatchDocument<SimpleObject> patch) => { }); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Features/JsonPatch/test/JsonPatchContentTypeEndToEndTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #if NET | ||
| using System.IO; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.InternalTesting; | ||
| using Microsoft.AspNetCore.Mvc.Testing; | ||
| using Microsoft.AspNetCore.TestHost; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.AspNetCore.JsonPatch; | ||
|
|
||
| public class JsonPatchContentTypeEndToEndTest : LoggedTest | ||
| { | ||
| [Theory] | ||
| [InlineData("/untyped", "application/json-patch+json", true)] | ||
| [InlineData("/typed", "application/json-patch+json", true)] | ||
| [InlineData("/untyped", "application/json", true)] | ||
| [InlineData("/typed", "application/json", true)] | ||
| [InlineData("/untyped", "text/plain", false)] | ||
| [InlineData("/typed", "text/plain", false)] | ||
| public async Task PatchContentTypes_AreHandledAsExpected(string route, string contentType, bool shouldBeAccepted) | ||
| { | ||
| using var factory = new JsonPatchWebApplicationFactory(LoggerFactory); | ||
| using var client = factory.CreateClient(); | ||
|
|
||
| using var content = new StringContent("""{ "operations": [] }""", Encoding.UTF8, contentType); | ||
|
|
||
| using var response = await client.PatchAsync(route, content); | ||
|
|
||
| var expectedStatusCode = shouldBeAccepted ? HttpStatusCode.OK : HttpStatusCode.UnsupportedMediaType; | ||
| Assert.Equal(expectedStatusCode, response.StatusCode); | ||
| } | ||
|
|
||
| private sealed class JsonPatchWebApplicationFactory(ILoggerFactory loggerFactory) : WebApplicationFactory<JsonPatchContentTypeEndToEndTest> | ||
| { | ||
| protected override void ConfigureWebHost(IWebHostBuilder builder) => builder.UseContentRoot(Directory.GetCurrentDirectory()); | ||
|
|
||
| protected override IHostBuilder CreateHostBuilder() | ||
| { | ||
| return new HostBuilder().ConfigureWebHost(webHostBuilder => | ||
| { | ||
| webHostBuilder | ||
| .UseTestServer() | ||
| .ConfigureServices(services => services.AddRouting().AddSingleton(loggerFactory)) | ||
| .Configure(app => | ||
| { | ||
| app.UseRouting(); | ||
| app.UseEndpoints(endpoints => | ||
| { | ||
| endpoints.MapPatch("/untyped", (JsonPatchDocument patch) => { }); | ||
| endpoints.MapPatch("/typed", (JsonPatchDocument<SimpleObject> patch) => { }); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.