-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Adding a new ActionResult to process IResult #40710
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
brunolins16
merged 22 commits into
dotnet:main
from
brunolins16:brunolins16/issues/40639
Mar 23, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8193ecc
Initial functionality
brunolins16 97dab79
Adding functional test
brunolins16 796aff3
Adding a test with filter
brunolins16 6a26ae1
adding test filter
brunolins16 cf0d365
PR feedback
brunolins16 9e5a1d4
remove empty line
brunolins16 d1f16f7
Adding tests and IResult default metadata
brunolins16 61a8808
Adding test for IResult convention
brunolins16 608262f
Adding new unit test
brunolins16 e515441
Rollback change
brunolins16 803b548
Remove unnecessary change
brunolins16 c9c4b89
Updating unit tests
brunolins16 98d8cbe
Merge branch 'main' into brunolins16/issues/40639
brunolins16 73c70a1
Renaming to HttpActionResult and making it internal
brunolins16 6608481
Removing public API
brunolins16 8805a53
Removing tests
brunolins16 dc0b88b
Renaming unit tests
brunolins16 b56abcb
Renaming types
brunolins16 bb0a805
PR Feedback
brunolins16 6047c97
PR Feeback
brunolins16 939c542
Removing HttpResultMetadataConvention
brunolins16 9e19ea5
Unit testing IResult and IConvertToActionResult at same type
brunolins16 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.AspNetCore.Http; | ||
|
|
||
| namespace Microsoft.AspNetCore.Mvc; | ||
|
|
||
| /// <summary> | ||
| /// An <see cref="ActionResult"/> that when executed will produce a response based on the <see cref="IResult"/> provided. | ||
| /// </summary> | ||
| internal sealed class HttpActionResult : ActionResult | ||
| { | ||
| /// <summary> | ||
| /// Gets the instance of the current <see cref="IResult"/>. | ||
| /// </summary> | ||
| public IResult Result { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="HttpActionResult"/> class with the | ||
| /// <see cref="IResult"/> provided. | ||
| /// </summary> | ||
| /// <param name="result">The <see cref="IResult"/> instance to be used during the <see cref="ExecuteResultAsync"/> invocation.</param> | ||
| public HttpActionResult(IResult result) | ||
| { | ||
| Result = result; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override Task ExecuteResultAsync(ActionContext context) | ||
| => Result.ExecuteAsync(context.HttpContext); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc.Abstractions; | ||
| using Microsoft.AspNetCore.Routing; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
| using Moq; | ||
|
|
||
| namespace Microsoft.AspNetCore.Mvc; | ||
|
|
||
| public class HttpActionResultTests | ||
| { | ||
| [Fact] | ||
| public void HttpActionResult_InitializesWithResultsStaticMethods() | ||
| { | ||
| // Arrange & Act | ||
| var httpResult = Mock.Of<IResult>(); | ||
| var result = new HttpActionResult(httpResult); | ||
|
|
||
| // Assert | ||
| Assert.Equal(httpResult, result.Result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task HttpActionResult_InvokesInternalHttpResult() | ||
| { | ||
| // Arrange | ||
| var httpContext = new DefaultHttpContext | ||
| { | ||
| RequestServices = CreateServices().BuildServiceProvider() | ||
| }; | ||
|
|
||
| var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); | ||
|
|
||
| var httpResult = new Mock<IResult>(); | ||
| httpResult.Setup(s => s.ExecuteAsync(httpContext)) | ||
| .Returns(() => Task.CompletedTask) | ||
| .Verifiable(); | ||
| var result = new HttpActionResult(httpResult.Object); | ||
|
|
||
| // Act | ||
| await result.ExecuteResultAsync(context); | ||
|
|
||
| // Assert | ||
| httpResult.Verify(); | ||
| } | ||
|
|
||
| private static IServiceCollection CreateServices() | ||
| { | ||
| var services = new ServiceCollection(); | ||
| services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance); | ||
| return services; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Json; | ||
| using BasicWebSite.Models; | ||
|
|
||
| namespace Microsoft.AspNetCore.Mvc.FunctionalTests; | ||
|
|
||
| public class HttpActionResultTests : IClassFixture<MvcTestFixture<BasicWebSite.StartupWithSystemTextJson>> | ||
| { | ||
| public HttpActionResultTests(MvcTestFixture<BasicWebSite.StartupWithSystemTextJson> fixture) | ||
| { | ||
| Client = fixture.CreateDefaultClient(); | ||
| } | ||
|
|
||
| public HttpClient Client { get; } | ||
|
|
||
| [Fact] | ||
| public async Task ActionCanReturnIResultWithContent() | ||
| { | ||
| // Arrange | ||
| var id = 1; | ||
| var url = $"/contact/{nameof(BasicWebSite.ContactApiController.ActionReturningObjectIResult)}/{id}"; | ||
| var response = await Client.GetAsync(url); | ||
|
|
||
| // Assert | ||
| await response.AssertStatusCodeAsync(HttpStatusCode.OK); | ||
| var result = await response.Content.ReadFromJsonAsync<Contact>(); | ||
| Assert.NotNull(result); | ||
| Assert.Equal(id, result.ContactId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ActionCanReturnIResultWithStatusCodeOnly() | ||
| { | ||
| // Arrange | ||
| var url = $"/contact/{nameof(BasicWebSite.ContactApiController.ActionReturningStatusCodeIResult)}"; | ||
| var response = await Client.GetAsync(url); | ||
|
|
||
| // Assert | ||
| await response.AssertStatusCodeAsync(HttpStatusCode.NoContent); | ||
| } | ||
| } |
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.