├── tools ├── Key.snk ├── logo.png └── nuget-logo.png ├── src ├── AspNetCore.Mvc.HttpActionResults.Informational │ ├── ContinueResult.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SwitchingProtocolsResult.cs │ └── AspNetCore.Mvc.HttpActionResults.Informational.csproj ├── AspNetCore.Mvc.HttpActionResults.ClientError │ ├── GoneResult.cs │ ├── ConflictResult.cs │ ├── ImATeapotResult.cs │ ├── NotAcceptableResult.cs │ ├── LengthRequiredResult.cs │ ├── RequestTimeoutResult.cs │ ├── PaymentRequiredResult.cs │ ├── ExpectationFailedResult.cs │ ├── RequestUriTooLongResult.cs │ ├── PreconditionFailedResult.cs │ ├── ConflictObjectResult.cs │ ├── NotAcceptableObjectResult.cs │ ├── PreconditionFailedObjectResult.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ProxyAuthenticationRequiredResult.cs │ ├── MethodNotAllowedResult.cs │ ├── AspNetCore.Mvc.HttpActionResults.ClientError.csproj │ ├── RequestEntityTooLargeResult.cs │ └── RequestedRangeNotSatisfiableResult.cs ├── AspNetCore.Mvc.HttpActionResults.ServerError │ ├── BadGetawayResult.cs │ ├── GatewayTimeoutResult.cs │ ├── NotImplementedResult.cs │ ├── InternalServerErrorResult.cs │ ├── HTTPVersionNotSupportedResult.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ServiceUnavailableResult.cs │ ├── ExceptionResult.cs │ └── AspNetCore.Mvc.HttpActionResults.ServerError.csproj ├── AspNetCore.Mvc.HttpActionResults.Success │ ├── ResetContentResult.cs │ ├── NonAuthoritativeInformationResult.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.Success.csproj │ ├── PartialContentResult.cs │ └── PartialContentObjectResult.cs ├── AspNetCore.Mvc.HttpActionResults.Redirection │ ├── NotModifiedResult.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── MultipleChoicesResult.cs │ ├── SeeOtherResult.cs │ ├── MultipleChoicesObjectResult.cs │ ├── UseProxyResult.cs │ ├── SeeOtherObjectResult.cs │ ├── AspNetCore.Mvc.HttpActionResults.Redirection.csproj │ ├── TemporaryRedirectResult.cs │ └── TemporaryRedirectObjectResult.cs ├── AspNetCore.Mvc.HttpActionResults │ ├── Properties │ │ └── AssemblyInfo.cs │ └── AspNetCore.Mvc.HttpActionResults.csproj ├── AspNetCore.Mvc.HttpActionResults.Success.Extensions │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.Success.Extensions.csproj │ └── SuccessControllerBaseExtensions.cs ├── AspNetCore.Mvc.HttpActionResults.ClientError.Extensions │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.ClientError.Extensions.csproj │ └── ClientErrorControllerBaseExtensions.cs ├── AspNetCore.Mvc.HttpActionResults.Redirection.Extensions │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.Redirection.Extensions.csproj │ └── RedirectionControllerBaseExtensions.cs ├── AspNetCore.Mvc.HttpActionResults.ServerError.Extensions │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.ServerError.Extensions.csproj │ └── ServerErrorControllerBaseExtensions.cs └── AspNetCore.Mvc.HttpActionResults.Informational.Extensions │ ├── Properties │ └── AssemblyInfo.cs │ ├── InformationalControllerBaseExtensions.cs │ └── AspNetCore.Mvc.HttpActionResults.Informational.Extensions.csproj ├── test ├── AspNetCore.Mvc.HttpActionResults.Test │ ├── TestHttpResponseStreamWriterFactory .cs │ ├── Logging │ │ ├── FakeLoggerFactory.cs │ │ └── FakeLogger.cs │ ├── AspNetCore.Mvc.HttpActionResults.Test.csproj │ └── BaseHttpResultTests.cs ├── AspNetCore.Mvc.HttpActionResults.ClientError.Test │ ├── RequestUriTooLongResultTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ProxyAuthenticationRequiredResultTests.cs │ ├── AspNetCore.Mvc.HttpActionResults.ClientError.Test.csproj │ ├── RequestEntityTooLargeResultTests.cs.cs │ └── ClientErrorControllerBaseExtensionsTest.cs ├── AspNetCore.Mvc.HttpActionResults.ServerError.Test │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.ServerError.Test.csproj │ └── ServerErrorControllerBaseExtensionsTest.cs ├── AspNetCore.Mvc.HttpActionResults.Success.Test │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AspNetCore.Mvc.HttpActionResults.Success.Test.csproj │ └── SuccessControllerBaseExtensionsTest.cs └── AspNetCore.Mvc.HttpActionResults.Redirection.Test │ ├── AspNetCore.Mvc.HttpActionResults.Redirection.Test.csproj │ └── RedirectionControllerBaseExtensionsTest.cs ├── LICENSE ├── .gitignore ├── README.md └── AspNetCore.Mvc.HttpActionResults.sln /tools/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/HEAD/tools/Key.snk -------------------------------------------------------------------------------- /tools/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/HEAD/tools/logo.png -------------------------------------------------------------------------------- /tools/nuget-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/HEAD/tools/nuget-logo.png -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational/ContinueResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | /// 4 | /// A that when executed will 5 | /// produce a Continue (100) response. 6 | /// 7 | public class ContinueResult : StatusCodeResult 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | public ContinueResult() 13 | : base(100) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Test/TestHttpResponseStreamWriterFactory .cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.Test 2 | { 3 | using System.IO; 4 | using System.Text; 5 | 6 | using Microsoft.AspNetCore.Mvc.Internal; 7 | using Microsoft.AspNetCore.WebUtilities; 8 | 9 | public class TestHttpResponseStreamWriterFactory : IHttpResponseStreamWriterFactory 10 | { 11 | public TextWriter CreateWriter(Stream stream, Encoding encoding) 12 | { 13 | return new HttpResponseStreamWriter(stream, encoding); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/GoneResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class GoneResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public GoneResult() 15 | : base(StatusCodes.Status410Gone) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Test/Logging/FakeLoggerFactory.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.Test.Logging 2 | { 3 | using Microsoft.Extensions.Logging; 4 | 5 | public class FakeLoggerFactory : ILoggerFactory 6 | { 7 | public static readonly FakeLoggerFactory Instance = new FakeLoggerFactory(); 8 | 9 | public ILogger CreateLogger(string name) 10 | { 11 | return FakeLogger.Instance; 12 | } 13 | 14 | public void AddProvider(ILoggerProvider provider) 15 | { 16 | } 17 | 18 | public void Dispose() 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/ConflictResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class ConflictResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public ConflictResult() 15 | : base(StatusCodes.Status409Conflict) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/ImATeapotResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an 7 | /// response. 8 | /// 9 | public class ImATeapotResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public ImATeapotResult() 15 | : base(StatusCodes.Status418ImATeapot) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/BadGetawayResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce a 7 | /// response. 8 | /// 9 | public class BadGatewayResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public BadGatewayResult() 15 | : base(StatusCodes.Status502BadGateway) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success/ResetContentResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce a 7 | /// response. 8 | /// 9 | public class ResetContentResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public ResetContentResult() 15 | : base(StatusCodes.Status205ResetContent) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/NotModifiedResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// An that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class NotModifiedResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public NotModifiedResult() 15 | : base(StatusCodes.Status304NotModified) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/NotAcceptableResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class NotAcceptableResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public NotAcceptableResult() 15 | : base(StatusCodes.Status406NotAcceptable) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/GatewayTimeoutResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce a 7 | /// response. 8 | /// 9 | public class GatewayTimeoutResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public GatewayTimeoutResult() 15 | : base(StatusCodes.Status504GatewayTimeout) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/NotImplementedResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce a 7 | /// response. 8 | /// 9 | public class NotImplementedResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public NotImplementedResult() 15 | : base(StatusCodes.Status501NotImplemented) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/LengthRequiredResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class LengthRequiredResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public LengthRequiredResult() 15 | : base(StatusCodes.Status411LengthRequired) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/RequestTimeoutResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class RequestTimeoutResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public RequestTimeoutResult() 15 | : base(StatusCodes.Status408RequestTimeout) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/PaymentRequiredResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class PaymentRequiredResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public PaymentRequiredResult() 15 | : base(StatusCodes.Status402PaymentRequired) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/ExpectationFailedResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class ExpectationFailedResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public ExpectationFailedResult() 15 | : base(StatusCodes.Status417ExpectationFailed) 16 | { 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/RequestUriTooLongResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class RequestUriTooLongResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public RequestUriTooLongResult() 15 | : base(StatusCodes.Status414RequestUriTooLong) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/PreconditionFailedResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce an empty 7 | /// response. 8 | /// 9 | public class PreconditionFailedResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public PreconditionFailedResult() 15 | : base(StatusCodes.Status412PreconditionFailed) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/InternalServerErrorResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// A that when executed will produce a 7 | /// response. 8 | /// 9 | public class InternalServerErrorResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public InternalServerErrorResult() 15 | : base(StatusCodes.Status500InternalServerError) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success/NonAuthoritativeInformationResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Microsoft.AspNetCore.Http; 4 | 5 | /// 6 | /// A that when executed will produce a 7 | /// response. 8 | /// 9 | public class NonAuthoritativeInformationResult : StatusCodeResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public NonAuthoritativeInformationResult() 15 | : base(StatusCodes.Status203NonAuthoritative) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Test/AspNetCore.Mvc.HttpActionResults.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/HTTPVersionNotSupportedResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// An that when executed performs content negotiation, formats the entity body, and 7 | /// will produce a response if negotiation and formatting succeed. 8 | /// 9 | public class HttpVersionNotSupportedResult : ObjectResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public HttpVersionNotSupportedResult(object value) 15 | : base(value) 16 | { 17 | this.StatusCode = StatusCodes.Status505HttpVersionNotsupported; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/ConflictObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// An that when executed performs content negotiation, formats the entity body, and 7 | /// will produce a response if negotiation and formatting succeed. 8 | /// 9 | public class ConflictObjectResult : ObjectResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The content to format into the entity body. 15 | public ConflictObjectResult(object value) 16 | : base(value) 17 | { 18 | this.StatusCode = StatusCodes.Status409Conflict; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/NotAcceptableObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// An that when executed performs content negotiation, formats the entity body, and 7 | /// will produce a response if negotiation and formatting succeed. 8 | /// 9 | public class NotAcceptableObjectResult : ObjectResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The content to format into the entity body. 15 | public NotAcceptableObjectResult(object value) 16 | : base(value) 17 | { 18 | this.StatusCode = StatusCodes.Status406NotAcceptable; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ClientError.Test/RequestUriTooLongResultTests.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.ClientError.Test 2 | { 3 | using AspNetCore.Mvc.HttpActionResults.Test; 4 | 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | using Xunit; 9 | 10 | public class RequestUriTooLongResultTests : BaseHttpResultTests 11 | { 12 | [Fact] 13 | public async void RequestUriTooLongResultShouldSetStatusCodeCorrectly() 14 | { 15 | // Arrange 16 | var fakeContext = this.CreateFakeActionContext(); 17 | var result = new RequestUriTooLongResult(); 18 | 19 | // Act 20 | await result.ExecuteResultAsync(fakeContext); 21 | 22 | // Assert 23 | Assert.Equal(StatusCodes.Status414RequestUriTooLong, fakeContext.HttpContext.Response.StatusCode); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/PreconditionFailedObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Http; 4 | 5 | /// 6 | /// An that when executed performs content negotiation, formats the entity body, and 7 | /// will produce a response if negotiation and formatting succeed. 8 | /// 9 | public class PreconditionFailedObjectResult : ObjectResult 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The content to format into the entity body. 15 | public PreconditionFailedObjectResult(object value) 16 | : base(value) 17 | { 18 | this.StatusCode = StatusCodes.Status412PreconditionFailed; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("83afff70-971b-41bb-9d32-b88b8965b475")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Success")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("958d691d-a587-45c1-b617-0e9ead05a86a")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.ClientError")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("81fd818d-36d5-4b82-a781-6309ff7eff47")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Informational")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("8a488be4-1ae0-4785-bbf9-6ebb034f3f64")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Redirection")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("6c6f319b-b038-467d-9840-187b4dd3f6b7")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.ServerError")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("1a2ab45e-071e-40f5-b71f-171df9656b51")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success.Extensions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Success.Extensions")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("55d14c10-2354-4517-8f45-adca43301043")] 20 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ClientError.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.ClientError.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("9440b360-66ac-4bed-8434-d40b86966f1d")] 20 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ServerError.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.ServerError.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("4f753c9c-8146-48c4-bfef-6bc0b6e62da9")] 20 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Success.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Success.Extensions.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("99861fb2-3896-4efa-a332-d7f8d8ab6489")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError.Extensions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.ClientError.Extensions")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("46b4c3b6-2e3c-4ef2-814b-bef6141b8ce1")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection.Extensions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Redirection.Extensions")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("8dde7331-5daa-4c63-9df4-ec0850da7a3c")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError.Extensions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.ServerError.Extensions")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("bdd9f3c5-d67d-4b10-b931-3812a4282bc4")] 20 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational.Extensions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspNetCore.Mvc.HttpActionResults.Informational.Extensions")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("b4cc9426-bf47-4712-9b34-d0d3e13980b4")] 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Ivaylo Kenov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Test/Logging/FakeLogger.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.Test.Logging 2 | { 3 | using System; 4 | 5 | using Microsoft.Extensions.Logging; 6 | 7 | public class FakeLogger : ILogger 8 | { 9 | public static FakeLogger Instance { get; } = new FakeLogger(); 10 | 11 | private FakeLogger() 12 | { 13 | } 14 | 15 | /// 16 | public IDisposable BeginScope(TState state) 17 | { 18 | return NullDisposable.Instance; 19 | } 20 | 21 | /// 22 | public bool IsEnabled(LogLevel logLevel) 23 | { 24 | return false; 25 | } 26 | 27 | /// 28 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) 29 | { 30 | } 31 | 32 | private class NullDisposable : IDisposable 33 | { 34 | public static readonly NullDisposable Instance = new NullDisposable(); 35 | 36 | public void Dispose() 37 | { 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational.Extensions/InformationalControllerBaseExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | /// 4 | /// Class containing informational HTTP response extensions methods for . 5 | /// 6 | public static class InformationalControllerBaseExtensions 7 | { 8 | /// 9 | /// Creates a object that produces a Continue (100) response. 10 | /// 11 | /// MVC controller instance. 12 | /// The created for the response. 13 | public static ContinueResult Continue(this ControllerBase controller) 14 | => new ContinueResult(); 15 | 16 | /// 17 | /// Creates a object that produces a Switching Protocols (101) response. 18 | /// 19 | /// MVC controller instance. 20 | /// The protocol to which the communication is upgraded. 21 | /// The created for the response. 22 | public static SwitchingProtocolsResult SwitchingProtocols(this ControllerBase controller, string upgradeTo) 23 | => new SwitchingProtocolsResult(upgradeTo); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Redirection.Test/AspNetCore.Mvc.HttpActionResults.Redirection.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ..\..\..\..\.nuget\packages\microsoft.aspnetcore.mvc.abstractions\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Mvc.Abstractions.dll 21 | 22 | 23 | ..\..\..\..\.nuget\packages\microsoft.aspnetcore.mvc.core\1.1.2\lib\netstandard1.6\Microsoft.AspNetCore.Mvc.Core.dll 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/MultipleChoicesResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Threading.Tasks; 6 | 7 | using Http; 8 | 9 | using Microsoft.Extensions.Primitives; 10 | using Microsoft.Net.Http.Headers; 11 | 12 | /// 13 | /// An that when executed will produce an empty 14 | /// response. 15 | /// 16 | public class MultipleChoicesResult : StatusCodeResult 17 | { 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | /// Preferred resource choice represented as an URI. 22 | public MultipleChoicesResult(string preferedChoiceUri = null) 23 | : base(StatusCodes.Status300MultipleChoices) 24 | { 25 | this.PreferedChoiceUri = preferedChoiceUri; 26 | } 27 | 28 | /// 29 | /// Preferred resource choice represented as an URI. 30 | /// 31 | public string PreferedChoiceUri { get; set; } 32 | 33 | /// 34 | public override Task ExecuteResultAsync(ActionContext context) 35 | { 36 | 37 | if (!string.IsNullOrEmpty(this.PreferedChoiceUri)) 38 | { 39 | context.HttpContext.Response.Headers.Add(HeaderNames.Location, new StringValues(this.PreferedChoiceUri)); 40 | } 41 | 42 | return base.ExecuteResultAsync(context); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/SeeOtherResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Extensions.Primitives; 4 | using Http; 5 | using Net.Http.Headers; 6 | using System.Threading.Tasks; 7 | 8 | /// 9 | /// An that when executed will produce an empty 10 | /// response. 11 | /// 12 | public class SeeOtherResult : StatusCodeResult 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public SeeOtherResult() 18 | : base(StatusCodes.Status303SeeOther) 19 | { 20 | } 21 | 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// Location to put in the response header. 26 | public SeeOtherResult(string location) 27 | : this() 28 | { 29 | this.Location = location; 30 | } 31 | 32 | /// 33 | /// Gets or sets the location to put in the response header. 34 | /// 35 | public string Location { get; set; } 36 | 37 | /// 38 | public override Task ExecuteResultAsync(ActionContext context) 39 | { 40 | if (!string.IsNullOrWhiteSpace(this.Location)) 41 | { 42 | context.HttpContext.Response.Headers.Add(HeaderNames.Location, new StringValues(this.Location)); 43 | } 44 | 45 | return base.ExecuteResultAsync(context); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/ProxyAuthenticationRequiredResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System.Threading.Tasks; 4 | 5 | using Http; 6 | using Extensions.Primitives; 7 | using Net.Http.Headers; 8 | 9 | /// 10 | /// An that when executed will produce a 11 | /// response. 12 | /// 13 | public class ProxyAuthenticationRequiredResult : StatusCodeResult 14 | { 15 | /// 16 | /// An that when executed will produce a 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// Challenge applicable to the proxy for the requested resource. 20 | public ProxyAuthenticationRequiredResult(string proxyAuthenticate) 21 | : base(StatusCodes.Status407ProxyAuthenticationRequired) 22 | { 23 | this.ProxyAuthenticate = proxyAuthenticate; 24 | } 25 | 26 | /// 27 | /// Gets or sets a challenge applicable to the proxy for the requested resource 28 | /// 29 | public string ProxyAuthenticate { get; set; } 30 | 31 | /// 32 | public override Task ExecuteResultAsync(ActionContext context) 33 | { 34 | if (!string.IsNullOrWhiteSpace(this.ProxyAuthenticate)) 35 | { 36 | context.HttpContext.Response.Headers.Add(HeaderNames.ProxyAuthenticate, new StringValues(this.ProxyAuthenticate)); 37 | } 38 | 39 | return base.ExecuteResultAsync(context); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/ServiceUnavailableResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Extensions.Primitives; 4 | using Http; 5 | using Net.Http.Headers; 6 | using System.Threading.Tasks; 7 | 8 | /// 9 | /// An that when executed will produce a 10 | /// response. 11 | /// 12 | public class ServiceUnavailableResult : StatusCodeResult 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public ServiceUnavailableResult() 18 | : base(StatusCodes.Status503ServiceUnavailable) 19 | { 20 | } 21 | 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// Length of delay to put in the response header. 26 | public ServiceUnavailableResult(string lengthOfDelay) 27 | : this() 28 | { 29 | this.LengthOfDelay = lengthOfDelay; 30 | } 31 | 32 | /// 33 | /// Gets or sets the length of the delay to put in the response header. 34 | /// 35 | public string LengthOfDelay { get; set; } 36 | 37 | /// 38 | public override Task ExecuteResultAsync(ActionContext context) 39 | { 40 | if (!string.IsNullOrWhiteSpace(this.LengthOfDelay)) 41 | { 42 | context.HttpContext.Response.Headers.Add(HeaderNames.RetryAfter, new StringValues(this.LengthOfDelay)); 43 | } 44 | 45 | return base.ExecuteResultAsync(context); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/MultipleChoicesObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System.Threading.Tasks; 4 | 5 | using Http; 6 | 7 | using Microsoft.Extensions.Primitives; 8 | using Microsoft.Net.Http.Headers; 9 | 10 | /// 11 | /// An that when executed performs content negotiation, formats the entity body, and 12 | /// will produce a response if negotiation and formatting succeed. 13 | /// 14 | public class MultipleChoicesObjectResult : ObjectResult 15 | { 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// The content to format into the entity body. 20 | /// Preferred resource choice represented as an URI. 21 | public MultipleChoicesObjectResult(object value, string preferedChoiceUri = null) 22 | : base(value) 23 | { 24 | this.StatusCode = StatusCodes.Status300MultipleChoices; 25 | this.PreferedChoiceUri = preferedChoiceUri; 26 | } 27 | 28 | /// 29 | /// Preferred resource choice represented as an URI. 30 | /// 31 | public string PreferedChoiceUri { get; set; } 32 | 33 | /// 34 | public override Task ExecuteResultAsync(ActionContext context) 35 | { 36 | 37 | if (!string.IsNullOrEmpty(this.PreferedChoiceUri)) 38 | { 39 | context.HttpContext.Response.Headers.Add(HeaderNames.Location, new StringValues(this.PreferedChoiceUri)); 40 | } 41 | 42 | return base.ExecuteResultAsync(context); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Success.Test/AspNetCore.Mvc.HttpActionResults.Success.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | true 6 | AspNetCore.Mvc.HttpActionResults.Success.Test 7 | AspNetCore.Mvc.HttpActionResults.Success.Test 8 | true 9 | $(PackageTargetFallback);dotnet5.4 10 | 1.1.1 11 | false 12 | false 13 | false 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ServerError.Test/AspNetCore.Mvc.HttpActionResults.ServerError.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | true 6 | AspNetCore.Mvc.HttpActionResults.ServerError.Test 7 | AspNetCore.Mvc.HttpActionResults.ServerError.Test 8 | true 9 | $(PackageTargetFallback);dotnet5.4 10 | 1.1.1 11 | false 12 | false 13 | false 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ClientError.Test/ProxyAuthenticationRequiredResultTests.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.ClientError.Test 2 | { 3 | using System.Linq; 4 | 5 | using AspNetCore.Mvc.HttpActionResults.Test; 6 | 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Net.Http.Headers; 10 | 11 | using Xunit; 12 | 13 | public class ProxyAuthenticationRequiredResultTests : BaseHttpResultTests 14 | { 15 | [Fact] 16 | public async void ProxyAuthenticationRequiredShouldSetStatusCodeCorrectly() 17 | { 18 | // Arrange 19 | const string fakeHeaderValue = @"Basic realm=""proxy.com"""; 20 | 21 | var fakeContext = this.CreateFakeActionContext(); 22 | var result = new ProxyAuthenticationRequiredResult(fakeHeaderValue); 23 | 24 | // Act 25 | await result.ExecuteResultAsync(fakeContext); 26 | 27 | // Assert 28 | Assert.Equal(StatusCodes.Status407ProxyAuthenticationRequired, fakeContext.HttpContext.Response.StatusCode); 29 | } 30 | 31 | [Fact] 32 | public async void ProxyAuthenticationRequiredShouldSetHeaderCorrectly() 33 | { 34 | // Arrange 35 | const string fakeHeaderValue = @"Basic realm=""proxy.com"""; 36 | 37 | var fakeContext = this.CreateFakeActionContext(); 38 | var result = new ProxyAuthenticationRequiredResult(fakeHeaderValue); 39 | 40 | // Act 41 | await result.ExecuteResultAsync(fakeContext); 42 | 43 | // Assert 44 | var proxyAuthHeader = 45 | fakeContext.HttpContext.Response.Headers.FirstOrDefault(x => x.Key == HeaderNames.ProxyAuthenticate); 46 | 47 | Assert.NotNull(proxyAuthHeader); 48 | Assert.Equal(fakeHeaderValue, proxyAuthHeader.Value); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/UseProxyResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | using Http; 7 | 8 | using Microsoft.Extensions.Primitives; 9 | using Microsoft.Net.Http.Headers; 10 | 11 | /// 12 | /// An that when executed will produce an empty 13 | /// response. 14 | /// 15 | public class UseProxyResult : StatusCodeResult 16 | { 17 | private string proxyUri; 18 | 19 | /// 20 | /// Initializes a new instance of the class. 21 | /// 22 | /// A proxy through which the requested resource must be accessed. 23 | public UseProxyResult(string proxyUri) 24 | : base(StatusCodes.Status305UseProxy) 25 | { 26 | this.ProxyUri = proxyUri; 27 | } 28 | 29 | /// 30 | /// A proxy through which the requested resource must be accessed. 31 | /// 32 | public string ProxyUri 33 | { 34 | get 35 | { 36 | return this.proxyUri; 37 | } 38 | 39 | set 40 | { 41 | if (string.IsNullOrWhiteSpace(value)) 42 | { 43 | throw new ArgumentOutOfRangeException(nameof(value)); 44 | } 45 | 46 | this.proxyUri = value; 47 | } 48 | } 49 | 50 | /// 51 | public override Task ExecuteResultAsync(ActionContext context) 52 | { 53 | context.HttpContext.Response.Headers.Add( 54 | HeaderNames.Location, 55 | new StringValues(this.ProxyUri)); 56 | 57 | return base.ExecuteResultAsync(context); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/SeeOtherObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Extensions.Primitives; 4 | using Http; 5 | using Net.Http.Headers; 6 | 7 | /// 8 | /// An that when executed performs content negotiation, formats the entity body, and 9 | /// will produce a response if negotiation and formatting succeed. 10 | /// 11 | public class SeeOtherObjectResult : ObjectResult 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The content to format into the entity body. 17 | public SeeOtherObjectResult(object value) 18 | : base(value) 19 | { 20 | this.StatusCode = StatusCodes.Status303SeeOther; 21 | } 22 | 23 | /// 24 | /// Initializes a new instance of the class. 25 | /// 26 | /// Location to put in the response header. 27 | /// The content to format into the entity body. 28 | public SeeOtherObjectResult(string location, object value) 29 | : this(value) 30 | { 31 | this.Location = location; 32 | } 33 | 34 | /// 35 | /// Gets or sets the location to put in the response header. 36 | /// 37 | public string Location { get; set; } 38 | 39 | /// 40 | public override void OnFormatting(ActionContext context) 41 | { 42 | base.OnFormatting(context); 43 | 44 | if (!string.IsNullOrEmpty(this.Location)) 45 | { 46 | context.HttpContext.Response.Headers.Add(HeaderNames.Location, new StringValues(this.Location)); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ClientError.Test/AspNetCore.Mvc.HttpActionResults.ClientError.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | true 6 | AspNetCore.Mvc.HttpActionResults.ClientError.Test 7 | AspNetCore.Mvc.HttpActionResults.ClientError.Test 8 | true 9 | $(PackageTargetFallback);dotnet5.4 10 | 1.1.1 11 | false 12 | false 13 | false 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/MethodNotAllowedResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Extensions.Primitives; 4 | using Http; 5 | using Net.Http.Headers; 6 | using System; 7 | using System.Threading.Tasks; 8 | 9 | /// 10 | /// A that when executed will produce an empty 11 | /// response. 12 | /// 13 | public class MethodNotAllowedResult : StatusCodeResult 14 | { 15 | private string allowedMethods; 16 | 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | public MethodNotAllowedResult(string allowedMethods) 21 | : base(StatusCodes.Status405MethodNotAllowed) 22 | { 23 | if (string.IsNullOrWhiteSpace(allowedMethods)) 24 | { 25 | throw new ArgumentException(nameof(allowedMethods)); 26 | } 27 | 28 | this.AllowedMethods = allowedMethods; 29 | } 30 | 31 | /// 32 | /// Gets or sets the value to put in the response header. 33 | /// 34 | public string AllowedMethods 35 | { 36 | get 37 | { 38 | return this.allowedMethods; 39 | } 40 | set 41 | { 42 | if (string.IsNullOrWhiteSpace(value)) 43 | { 44 | throw new ArgumentException(nameof(value)); 45 | } 46 | 47 | this.allowedMethods = value; 48 | } 49 | } 50 | 51 | /// 52 | public override Task ExecuteResultAsync(ActionContext context) 53 | { 54 | context.HttpContext.Response.Headers.Add(HeaderNames.Allow, new StringValues(this.AllowedMethods)); 55 | 56 | return base.ExecuteResultAsync(context); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/ExceptionResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | 5 | using Http; 6 | 7 | /// 8 | /// A that when executed will produce a 9 | /// response. 10 | /// 11 | public class ExceptionResult : ObjectResult 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The exception to include in the error. 17 | /// 18 | /// if the error should include exception messages; otherwise, . 19 | /// 20 | public ExceptionResult(Exception exception, bool includeErrorDetail) 21 | : base(exception) 22 | { 23 | if (exception == null) 24 | { 25 | throw new ArgumentNullException(nameof(exception)); 26 | } 27 | 28 | if (includeErrorDetail) 29 | { 30 | this.Value = exception; 31 | } 32 | else 33 | { 34 | this.Value = exception.Message; 35 | } 36 | 37 | this.Exception = exception; 38 | this.StatusCode = StatusCodes.Status500InternalServerError; 39 | } 40 | 41 | /// 42 | /// Initializes a new instance of the class. 43 | /// 44 | /// The exception to include in the error. 45 | public ExceptionResult(Exception exception) 46 | : this(exception, false) 47 | { 48 | } 49 | 50 | /// 51 | /// Gets the exception to include in the error. 52 | /// 53 | public Exception Exception 54 | { 55 | get; private set; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Test/BaseHttpResultTests.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.Test 2 | { 3 | using System; 4 | using System.Buffers; 5 | using System.IO; 6 | 7 | using AspNetCore.Mvc.HttpActionResults.Test.Logging; 8 | 9 | using Microsoft.AspNetCore.Http; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.AspNetCore.Mvc.Abstractions; 12 | using Microsoft.AspNetCore.Mvc.Formatters; 13 | using Microsoft.AspNetCore.Mvc.Internal; 14 | using Microsoft.AspNetCore.Routing; 15 | using Microsoft.Extensions.DependencyInjection; 16 | using Microsoft.Extensions.Logging; 17 | using Microsoft.Extensions.Options; 18 | 19 | using Newtonsoft.Json; 20 | 21 | public abstract class BaseHttpResultTests 22 | { 23 | protected ActionContext CreateFakeActionContext() 24 | { 25 | var httpContext = new DefaultHttpContext 26 | { 27 | RequestServices = this.CreateServices() 28 | }; 29 | 30 | var stream = new MemoryStream(); 31 | httpContext.Response.Body = stream; 32 | 33 | var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); 34 | 35 | return context; 36 | } 37 | 38 | protected IServiceProvider CreateServices() 39 | { 40 | var options = new OptionsManager(new IConfigureOptions[] { }); 41 | options.Value.OutputFormatters.Add(new StringOutputFormatter()); 42 | options.Value.OutputFormatters.Add(new JsonOutputFormatter( 43 | new JsonSerializerSettings(), 44 | ArrayPool.Shared)); 45 | 46 | var services = new ServiceCollection(); 47 | services.AddSingleton(FakeLoggerFactory.Instance); 48 | services.AddSingleton(new ObjectResultExecutor( 49 | options, 50 | new TestHttpResponseStreamWriterFactory(), 51 | FakeLoggerFactory.Instance)); 52 | 53 | return services.BuildServiceProvider(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational/SwitchingProtocolsResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using Extensions.Primitives; 4 | using Net.Http.Headers; 5 | using System; 6 | using System.Threading.Tasks; 7 | 8 | /// 9 | /// A that when executed will 10 | /// produce a Switching Protocols (101) response. 11 | /// 12 | public class SwitchingProtocolsResult : StatusCodeResult 13 | { 14 | private string upgradeTo; 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// Value to put in the response "Upgrade" header. 20 | public SwitchingProtocolsResult(string upgradeTo) 21 | : base(101) 22 | { 23 | if (string.IsNullOrWhiteSpace(upgradeTo)) 24 | { 25 | throw new ArgumentNullException(nameof(upgradeTo)); 26 | } 27 | 28 | this.UpgradeTo = upgradeTo; 29 | } 30 | 31 | /// 32 | /// Gets or sets the value to put in the response header. 33 | /// 34 | public string UpgradeTo 35 | { 36 | get 37 | { 38 | return this.upgradeTo; 39 | } 40 | set 41 | { 42 | if (string.IsNullOrWhiteSpace(value)) 43 | { 44 | throw new ArgumentNullException(nameof(value)); 45 | } 46 | 47 | this.upgradeTo = value; 48 | } 49 | } 50 | 51 | /// 52 | public override Task ExecuteResultAsync(ActionContext context) 53 | { 54 | context.HttpContext.Response.Headers.Add(HeaderNames.Connection, "upgrade"); 55 | context.HttpContext.Response.Headers.Add(HeaderNames.Upgrade, new StringValues(this.UpgradeTo)); 56 | 57 | return base.ExecuteResultAsync(context); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success/AspNetCore.Mvc.HttpActionResults.Success.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.Success is a collection of success HTTP status code action results for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Success HTTP Action Results 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.Success 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.Success 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/AspNetCore.Mvc.HttpActionResults.ClientError.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.ClientError is a collection of client error HTTP status code action results for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Client Error HTTP Action Results 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.ClientError 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.ClientError 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/AspNetCore.Mvc.HttpActionResults.Redirection.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.Redirection is a collection of redirection HTTP status code action results for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Redirection HTTP Action Results 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.Redirection 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.Redirection 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError/AspNetCore.Mvc.HttpActionResults.ServerError.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.ServerError is a collection of server error HTTP status code action results for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Server Error HTTP Action Results 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.ServerError 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.ServerError 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/RequestEntityTooLargeResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | using Http; 7 | using Extensions.Primitives; 8 | using Net.Http.Headers; 9 | 10 | /// 11 | /// A that when executed will produce an empty 12 | /// response. 13 | /// 14 | public class RequestEntityTooLargeResult : StatusCodeResult 15 | { 16 | private string retryAfter; 17 | 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | public RequestEntityTooLargeResult() 22 | : base(StatusCodes.Status413RequestEntityTooLarge) 23 | { 24 | } 25 | 26 | /// 27 | /// Initializes a new instance of the class. 28 | /// 29 | /// The time after which the client may try the request again. 30 | public RequestEntityTooLargeResult(string retryAfter) 31 | : this() 32 | { 33 | this.RetryAfter = retryAfter; 34 | } 35 | 36 | /// 37 | /// Gets or sets the the time after which the client may try the request again. 38 | /// 39 | public string RetryAfter 40 | { 41 | get 42 | { 43 | return this.retryAfter; 44 | } 45 | 46 | set 47 | { 48 | if (string.IsNullOrWhiteSpace(value)) 49 | { 50 | throw new ArgumentException(nameof(value)); 51 | } 52 | 53 | this.retryAfter = value; 54 | } 55 | } 56 | 57 | /// 58 | public override Task ExecuteResultAsync(ActionContext context) 59 | { 60 | if (!string.IsNullOrWhiteSpace(this.RetryAfter)) 61 | { 62 | context.HttpContext.Response.Headers.Add(HeaderNames.RetryAfter, new StringValues(this.RetryAfter)); 63 | } 64 | 65 | return base.ExecuteResultAsync(context); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational/AspNetCore.Mvc.HttpActionResults.Informational.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.Informational is a collection of informational HTTP status code action results for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Informational HTTP Action Results 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.Informational 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.Informational 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success.Extensions/AspNetCore.Mvc.HttpActionResults.Success.Extensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.Success.Extensions is a collection of success HTTP status code extension methods for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Success HTTP Extensions 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.Success.Extensions 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.Success.Extensions 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError.Extensions/AspNetCore.Mvc.HttpActionResults.ClientError.Extensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.ClientError.Extensions is a collection of client error HTTP status code extension methods for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Client Error HTTP Extensions 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.ClientError.Extensions 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.ClientError.Extensions 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection.Extensions/AspNetCore.Mvc.HttpActionResults.Redirection.Extensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.Redirection.Extensions is a collection of redirection HTTP status code extension methods for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Redirection HTTP Extensions 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.Redirection.Extensions 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.Redirection.Extensions 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError.Extensions/AspNetCore.Mvc.HttpActionResults.ServerError.Extensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.ServerError.Extensions is a collection of server error HTTP status code extension methods for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Server Error HTTP Extensions 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.ServerError.Extensions 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.ServerError.Extensions 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success.Extensions/SuccessControllerBaseExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | /// 4 | /// Class containing success HTTP response extensions methods for . 5 | /// 6 | public static class SuccessControllerBaseExtensions 7 | { 8 | /// 9 | /// Creates an object that produces an Non-Authoritative Information (203) response. 10 | /// 11 | /// MVC controller instance. 12 | /// The created for the response. 13 | public static NonAuthoritativeInformationResult NonAuthoritativeInformation(this ControllerBase controller) 14 | => new NonAuthoritativeInformationResult(); 15 | 16 | /// 17 | /// Creates an object that produces an Reset Content (205) response. 18 | /// 19 | /// MVC controller instance. 20 | /// The created for the response. 21 | public static ResetContentResult ResetContent(this ControllerBase controller) 22 | => new ResetContentResult(); 23 | 24 | /// 25 | /// Creates a object that produces a Partial Content (206) response. 26 | /// 27 | /// MVC controller instance. 28 | /// The created for the response. 29 | public static PartialContentResult PartialContent(this ControllerBase controller) 30 | => new PartialContentResult(); 31 | 32 | /// 33 | /// Creates a object that produces a Partial Content (206) response. 34 | /// 35 | /// MVC controller instance. 36 | /// The data to be returned. 37 | /// The created for the response. 38 | public static PartialContentObjectResult PartialContent(this ControllerBase controller, object value) 39 | => new PartialContentObjectResult(value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Informational.Extensions/AspNetCore.Mvc.HttpActionResults.Informational.Extensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults.Informational.Extensions is a collection of informational HTTP status code extension methods for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC Informational HTTP Extensions 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults.Informational.Extensions 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults.Informational.Extensions 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ClientError.Test/RequestEntityTooLargeResultTests.cs.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.ClientError.Test 2 | { 3 | using System.Linq; 4 | 5 | using AspNetCore.Mvc.HttpActionResults.Test; 6 | 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Net.Http.Headers; 10 | 11 | using Xunit; 12 | 13 | public class RequestEntityTooLargeResultTests : BaseHttpResultTests 14 | { 15 | [Fact] 16 | public async void ProxyAuthenticationRequiredShouldSetStatusCodeCorrectly() 17 | { 18 | // Arrange 19 | const string fakeHeaderValue = "Fake header value"; 20 | 21 | var fakeContext = this.CreateFakeActionContext(); 22 | var result = new RequestEntityTooLargeResult(fakeHeaderValue); 23 | 24 | // Act 25 | await result.ExecuteResultAsync(fakeContext); 26 | 27 | // Assert 28 | Assert.Equal(StatusCodes.Status413RequestEntityTooLarge, fakeContext.HttpContext.Response.StatusCode); 29 | } 30 | 31 | [Fact] 32 | public async void ProxyAuthenticationRequiredShouldSetHeaderCorrectly() 33 | { 34 | // Arrange 35 | const string fakeHeaderValue = "Fake header value"; 36 | 37 | var fakeContext = this.CreateFakeActionContext(); 38 | var result = new RequestEntityTooLargeResult(fakeHeaderValue); 39 | 40 | // Act 41 | await result.ExecuteResultAsync(fakeContext); 42 | 43 | // Assert 44 | var proxyAuthHeader = 45 | fakeContext.HttpContext.Response.Headers.FirstOrDefault(x => x.Key == HeaderNames.RetryAfter); 46 | 47 | Assert.NotNull(proxyAuthHeader); 48 | Assert.Equal(fakeHeaderValue, proxyAuthHeader.Value); 49 | } 50 | 51 | [Fact] 52 | public async void ProxyAuthenticationRequiredShouldNotSendHeaderIfNoValueForRetryAfterIsGiven() 53 | { 54 | // Arrange 55 | var fakeContext = this.CreateFakeActionContext(); 56 | var result = new RequestEntityTooLargeResult(); 57 | 58 | // Act 59 | await result.ExecuteResultAsync(fakeContext); 60 | 61 | // Assert 62 | var requestHasHeaders = 63 | fakeContext.HttpContext.Response.Headers.Any(); 64 | 65 | Assert.False(requestHasHeaders); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError/RequestedRangeNotSatisfiableResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Threading.Tasks; 6 | using Extensions.Primitives; 7 | using Http; 8 | using Net.Http.Headers; 9 | 10 | /// 11 | /// A that when executed will produce an empty 12 | /// response. 13 | /// 14 | public class RequestedRangeNotSatisfiableResult : StatusCodeResult 15 | { 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | public RequestedRangeNotSatisfiableResult() 20 | : base(StatusCodes.Status416RequestedRangeNotSatisfiable) 21 | { 22 | } 23 | 24 | /// 25 | /// Initializes a new instance of the class. 26 | /// 27 | /// 28 | public RequestedRangeNotSatisfiableResult(long? selectedResourceLength) 29 | : this() 30 | { 31 | this.SelectedResourceLength = selectedResourceLength; 32 | } 33 | 34 | /// 35 | /// Gets or sets the current length of the selected resource. 36 | /// 37 | public long? SelectedResourceLength { get; set; } 38 | 39 | /// 40 | public override Task ExecuteResultAsync(ActionContext context) 41 | { 42 | if (context == null) 43 | { 44 | throw new ArgumentNullException(nameof(context)); 45 | } 46 | 47 | if (context.HttpContext.Response.Headers.Contains(new KeyValuePair(HeaderNames.ContentType, new StringValues("multipart/byteranges")))) 48 | { 49 | throw new OperationCanceledException("This response MUST NOT use the multipart/byteranges content-type."); 50 | } 51 | 52 | if (this.SelectedResourceLength.HasValue) 53 | { 54 | context.HttpContext.Response.Headers.Add(HeaderNames.ContentRange, new StringValues(this.SelectedResourceLength.ToString())); 55 | } 56 | 57 | return base.ExecuteResultAsync(context); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/TemporaryRedirectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.Extensions.Primitives; 8 | using Microsoft.Net.Http.Headers; 9 | 10 | /// 11 | /// An that when executed will produce an empty 12 | /// response. 13 | /// 14 | public class TemporaryRedirectResult : StatusCodeResult 15 | { 16 | private string temporaryUri; 17 | 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | /// The temporary URI of the requested resource resides. 22 | public TemporaryRedirectResult(string temporaryUri) 23 | : base(StatusCodes.Status307TemporaryRedirect) 24 | { 25 | this.TemporaryUri = temporaryUri; 26 | } 27 | 28 | /// 29 | /// The temporary URI of the requested resource resides. 30 | /// 31 | public string TemporaryUri 32 | { 33 | get 34 | { 35 | return this.temporaryUri; 36 | } 37 | 38 | set 39 | { 40 | if (string.IsNullOrWhiteSpace(value)) 41 | { 42 | throw new ArgumentOutOfRangeException(nameof(value)); 43 | } 44 | 45 | this.temporaryUri = value; 46 | } 47 | } 48 | 49 | /// 50 | /// Contains the date/time after which the response is considered stale. 51 | /// 52 | public string Expires { get; set; } 53 | 54 | /// 55 | /// Specifies directive for caching mechanisms in the responses. 56 | /// 57 | public string CacheControl { get; set; } 58 | 59 | /// 60 | public override Task ExecuteResultAsync(ActionContext context) 61 | { 62 | context.HttpContext.Response.Headers.Add( 63 | HeaderNames.Location, 64 | new StringValues(this.TemporaryUri)); 65 | 66 | if (!string.IsNullOrWhiteSpace(this.Expires)) 67 | { 68 | context.HttpContext.Response.Headers.Add(HeaderNames.Expires, new StringValues(this.Expires)); 69 | } 70 | 71 | if (!string.IsNullOrWhiteSpace(this.CacheControl)) 72 | { 73 | context.HttpContext.Response.Headers.Add(HeaderNames.CacheControl, new StringValues(this.CacheControl)); 74 | } 75 | 76 | return base.ExecuteResultAsync(context); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults/AspNetCore.Mvc.HttpActionResults.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCore.Mvc.HttpActionResults is a collection of HTTP status code action results and extension methods for ASP.NET Core MVC. See the project repository for more information and available features. 5 | 2016 Ivaylo Kenov 6 | ASP.NET Core MVC HTTP Action Results 7 | 0.3.0 8 | Ivaylo Kenov 9 | netstandard1.6;net451 10 | true 11 | true 12 | AspNetCore.Mvc.HttpActionResults 13 | ../../tools/Key.snk 14 | true 15 | true 16 | AspNetCore.Mvc.HttpActionResults 17 | asp.net core mvc http action result 18 | https://raw.githubusercontent.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/master/tools/nuget-logo.png 19 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 20 | https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE 21 | git 22 | git://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults 23 | false 24 | false 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection/TemporaryRedirectObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | using Http; 7 | 8 | using Microsoft.Extensions.Primitives; 9 | using Microsoft.Net.Http.Headers; 10 | 11 | /// 12 | /// An that when executed performs content negotiation, formats the entity body, and 13 | /// will produce a response if negotiation and formatting succeed. 14 | /// 15 | public class TemporaryRedirectObjectResult : ObjectResult 16 | { 17 | private string temporaryUri; 18 | 19 | /// 20 | /// Initializes a new instance of the class. 21 | /// 22 | /// The content to format into the entity body. 23 | /// The temporary URI of the requested resource resides. 24 | public TemporaryRedirectObjectResult(object value, string temporaryUri) 25 | : base(value) 26 | { 27 | this.StatusCode = StatusCodes.Status307TemporaryRedirect; 28 | this.TemporaryUri = temporaryUri; 29 | } 30 | 31 | /// 32 | /// The temporary URI of the requested resource resides. 33 | /// 34 | public string TemporaryUri 35 | { 36 | get 37 | { 38 | return this.temporaryUri; 39 | } 40 | 41 | set 42 | { 43 | if (string.IsNullOrWhiteSpace(value)) 44 | { 45 | throw new ArgumentOutOfRangeException(nameof(value)); 46 | } 47 | 48 | this.temporaryUri = value; 49 | } 50 | } 51 | 52 | /// 53 | /// Contains the date/time after which the response is considered stale. 54 | /// 55 | public string Expires { get; set; } 56 | 57 | /// 58 | /// Specifies directive for caching mechanisms in the responses. 59 | /// 60 | public string CacheControl { get; set; } 61 | 62 | /// 63 | public override Task ExecuteResultAsync(ActionContext context) 64 | { 65 | context.HttpContext.Response.Headers.Add( 66 | HeaderNames.Location, 67 | new StringValues(this.TemporaryUri)); 68 | 69 | if (!string.IsNullOrWhiteSpace(this.Expires)) 70 | { 71 | context.HttpContext.Response.Headers.Add(HeaderNames.Expires, new StringValues(this.Expires)); 72 | } 73 | 74 | if (!string.IsNullOrWhiteSpace(this.CacheControl)) 75 | { 76 | context.HttpContext.Response.Headers.Add(HeaderNames.CacheControl, new StringValues(this.CacheControl)); 77 | } 78 | 79 | return base.ExecuteResultAsync(context); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Success.Test/SuccessControllerBaseExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.Success.Test 2 | { 3 | using Microsoft.AspNetCore.Mvc; 4 | using Xunit; 5 | 6 | public class SuccessControllerBaseExtensionsTest 7 | { 8 | [Fact] 9 | public void AcceptedShouldReturnAcceptedResult() 10 | { 11 | var controller = new HomeController(); 12 | 13 | var result = controller.TestAcceptedResult(); 14 | 15 | Assert.NotNull(result); 16 | Assert.IsAssignableFrom(result); 17 | } 18 | 19 | [Fact] 20 | public void ResetContentShouldReturnResetContentResult() 21 | { 22 | var controller = new HomeController(); 23 | 24 | var result = controller.TestResetContentResult(); 25 | 26 | Assert.NotNull(result); 27 | Assert.IsAssignableFrom(result); 28 | } 29 | 30 | [Fact] 31 | public void NonAuthoritativeInformationShouldReturnNonAuthoritativeInformationResult() 32 | { 33 | var controller = new HomeController(); 34 | 35 | var result = controller.TestNonAuthoritativeInformationResult(); 36 | 37 | Assert.NotNull(result); 38 | Assert.IsAssignableFrom(result); 39 | } 40 | 41 | [Fact] 42 | public void PartialContentShouldReturnPartialContentResult() 43 | { 44 | var controller = new HomeController(); 45 | 46 | var result = controller.TestPartialContentResult(); 47 | 48 | Assert.NotNull(result); 49 | Assert.IsAssignableFrom(result); 50 | } 51 | 52 | [Fact] 53 | public void PartialContentShouldReturnPartialContentObjectResultResult() 54 | { 55 | var controller = new HomeController(); 56 | const string value = "I'm so fake"; 57 | 58 | var result = controller.TestPartialContentResult(value); 59 | 60 | Assert.NotNull(result); 61 | Assert.IsAssignableFrom(result); 62 | } 63 | 64 | private class HomeController : ControllerBase 65 | { 66 | public IActionResult TestAcceptedResult() 67 | { 68 | return this.Accepted(); 69 | } 70 | 71 | public IActionResult TestResetContentResult() 72 | { 73 | return this.ResetContent(); 74 | } 75 | 76 | public IActionResult TestNonAuthoritativeInformationResult() 77 | { 78 | return this.NonAuthoritativeInformation(); 79 | } 80 | 81 | public IActionResult TestPartialContentResult() 82 | { 83 | return this.PartialContent(); 84 | } 85 | 86 | public IActionResult TestPartialContentResult(object value) 87 | { 88 | return this.PartialContent(value); 89 | } 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success/PartialContentResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | using Microsoft.AspNetCore.Http; 9 | using Microsoft.Extensions.Primitives; 10 | using Microsoft.Net.Http.Headers; 11 | 12 | /// 13 | /// A that when executed will produce a 14 | /// response. 15 | /// 16 | public class PartialContentResult : StatusCodeResult 17 | { 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | public PartialContentResult() 22 | : base(StatusCodes.Status206PartialContent) 23 | { 24 | } 25 | 26 | /// 27 | /// Indicates where in a full body message a partial message belongs. 28 | /// 29 | public string ContentRange { get; set; } 30 | 31 | /// 32 | /// An identifier for a specific version of a resource. 33 | /// 34 | public string ETag { get; set; } 35 | 36 | /// 37 | /// Indicates an alternate location for the returned data. 38 | /// 39 | public string ContentLocation { get; set; } 40 | 41 | /// 42 | /// Contains the date/time after which the response is considered stale. 43 | /// 44 | public string Expires { get; set; } 45 | 46 | /// 47 | /// Specifies directive for caching mechanisms in the responses. 48 | /// 49 | public string CacheControl { get; set; } 50 | 51 | /// 52 | /// Determines how to match future request headers to decide whether a cached response can be used rather than requesting a fresh one from the origin server. 53 | /// 54 | public string Vary { get; set; } 55 | 56 | /// 57 | public override Task ExecuteResultAsync(ActionContext context) 58 | { 59 | context.HttpContext.Response.Headers.Add( 60 | HeaderNames.Date, 61 | new StringValues(DateTime.Now.ToString(CultureInfo.InvariantCulture))); 62 | 63 | this.ValidateContentHeaders(context); 64 | 65 | if (!string.IsNullOrEmpty(this.ContentRange)) 66 | { 67 | context.HttpContext.Response.Headers.Add(HeaderNames.ContentRange, new StringValues(this.ContentRange)); 68 | } 69 | 70 | if (!string.IsNullOrWhiteSpace(this.ETag)) 71 | { 72 | context.HttpContext.Response.Headers.Add(HeaderNames.ETag, new StringValues(this.ETag)); 73 | } 74 | 75 | if (!string.IsNullOrWhiteSpace(this.ContentLocation)) 76 | { 77 | context.HttpContext.Response.Headers.Add(HeaderNames.ContentLocation, new StringValues(this.ContentLocation)); 78 | } 79 | 80 | if (!string.IsNullOrWhiteSpace(this.Expires)) 81 | { 82 | context.HttpContext.Response.Headers.Add(HeaderNames.Expires, new StringValues(this.Expires)); 83 | } 84 | 85 | if (!string.IsNullOrWhiteSpace(this.CacheControl)) 86 | { 87 | context.HttpContext.Response.Headers.Add(HeaderNames.CacheControl, new StringValues(this.CacheControl)); 88 | } 89 | 90 | if (!string.IsNullOrWhiteSpace(this.Vary)) 91 | { 92 | context.HttpContext.Response.Headers.Add(HeaderNames.Vary, new StringValues(this.Vary)); 93 | } 94 | 95 | return base.ExecuteResultAsync(context); 96 | } 97 | 98 | private void ValidateContentHeaders(ActionContext context) 99 | { 100 | var hasMultipartHeader = 101 | context.HttpContext.Response.Headers.Any(x => x.Key == HeaderNames.ContentType && x.Value == "multipart/byteranges"); 102 | 103 | if (!hasMultipartHeader && string.IsNullOrWhiteSpace(this.ContentRange)) 104 | { 105 | throw new InvalidOperationException(@"The response must contain either a Content-Range header field indicating the range included with this response, or a multipart/byteranges Content-Type including Content-Range fields for each part."); 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Success/PartialContentObjectResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | using Extensions.Primitives; 9 | using Http; 10 | using Net.Http.Headers; 11 | 12 | /// 13 | /// An that when executed performs content negotiation, formats the entity body, and 14 | /// will produce a response if negotiation and formatting succeed. 15 | /// 16 | public class PartialContentObjectResult : ObjectResult 17 | { 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | /// The content to format into the entity body. 22 | public PartialContentObjectResult(object value) 23 | : base(value) 24 | { 25 | this.StatusCode = StatusCodes.Status206PartialContent; 26 | } 27 | 28 | /// 29 | /// Indicates where in a full body message a partial message belongs. 30 | /// 31 | public string ContentRange { get; set; } 32 | 33 | /// 34 | /// An identifier for a specific version of a resource. 35 | /// 36 | public string ETag { get; set; } 37 | 38 | /// 39 | /// Indicates an alternate location for the returned data. 40 | /// 41 | public string ContentLocation { get; set; } 42 | 43 | /// 44 | /// Contains the date/time after which the response is considered stale. 45 | /// 46 | public string Expires { get; set; } 47 | 48 | /// 49 | /// Specifies directive for caching mechanisms in the responses. 50 | /// 51 | public string CacheControl { get; set; } 52 | 53 | /// 54 | /// Determines how to match future request headers to decide whether a cached response can be used rather than requesting a fresh one from the origin server. 55 | /// 56 | public string Vary { get; set; } 57 | 58 | /// 59 | public override Task ExecuteResultAsync(ActionContext context) 60 | { 61 | context.HttpContext.Response.Headers.Add( 62 | HeaderNames.Date, 63 | new StringValues(DateTime.Now.ToString(CultureInfo.InvariantCulture))); 64 | 65 | this.ValidateContentHeaders(context); 66 | 67 | if (!string.IsNullOrEmpty(this.ContentRange)) 68 | { 69 | context.HttpContext.Response.Headers.Add(HeaderNames.ContentRange, new StringValues(this.ContentRange)); 70 | } 71 | 72 | if (!string.IsNullOrWhiteSpace(this.ETag)) 73 | { 74 | context.HttpContext.Response.Headers.Add(HeaderNames.ETag, new StringValues(this.ETag)); 75 | } 76 | 77 | if (!string.IsNullOrWhiteSpace(this.ContentLocation)) 78 | { 79 | context.HttpContext.Response.Headers.Add(HeaderNames.ContentLocation, new StringValues(this.ContentLocation)); 80 | } 81 | 82 | if (!string.IsNullOrWhiteSpace(this.Expires)) 83 | { 84 | context.HttpContext.Response.Headers.Add(HeaderNames.Expires, new StringValues(this.Expires)); 85 | } 86 | 87 | if (!string.IsNullOrWhiteSpace(this.CacheControl)) 88 | { 89 | context.HttpContext.Response.Headers.Add(HeaderNames.CacheControl, new StringValues(this.CacheControl)); 90 | } 91 | 92 | if (!string.IsNullOrWhiteSpace(this.Vary)) 93 | { 94 | context.HttpContext.Response.Headers.Add(HeaderNames.Vary, new StringValues(this.Vary)); 95 | } 96 | 97 | return base.ExecuteResultAsync(context); 98 | } 99 | 100 | private void ValidateContentHeaders(ActionContext context) 101 | { 102 | var hasMultipartHeader = 103 | context.HttpContext.Response.Headers.Any(x => x.Key == HeaderNames.ContentType && x.Value == "multipart/byteranges"); 104 | 105 | if (!hasMultipartHeader && string.IsNullOrWhiteSpace(this.ContentRange)) 106 | { 107 | throw new InvalidOperationException(@"The response must contain either a Content-Range header field indicating the range included with this response, or a multipart/byteranges Content-Type including Content-Range fields for each part."); 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ServerError.Test/ServerErrorControllerBaseExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.ServerError.Test 2 | { 3 | using Microsoft.AspNetCore.Mvc; 4 | using System; 5 | using Xunit; 6 | 7 | public class ServerErrorControllerBaseExtensionsTest 8 | { 9 | [Fact] 10 | public void InternalServerErrorShouldReturnInternalServerErrorResult() 11 | { 12 | var controller = new HomeController(); 13 | 14 | var result = controller.TestInternalServerError(); 15 | 16 | Assert.NotNull(result); 17 | Assert.IsAssignableFrom(result); 18 | } 19 | 20 | [Fact] 21 | public void InternalServerErrorShouldReturnExceptionResult() 22 | { 23 | var controller = new HomeController(); 24 | 25 | var result = controller.TestExceptionResult(new Exception()); 26 | 27 | Assert.NotNull(result); 28 | Assert.IsAssignableFrom(result); 29 | } 30 | 31 | [Fact] 32 | public void InternalServerErrorShouldReturnExceptionResultWithErrors() 33 | { 34 | var controller = new HomeController(); 35 | 36 | var result = controller.TestExceptionResult(new Exception(), true); 37 | 38 | Assert.NotNull(result); 39 | Assert.IsAssignableFrom(result); 40 | } 41 | 42 | [Fact] 43 | public void InternalServerErrorNullShouldThrowArgumentNullException() 44 | { 45 | var controller = new HomeController(); 46 | 47 | Assert.Throws(() => controller.TestExceptionResult(null)); 48 | } 49 | 50 | [Fact] 51 | public void InternalServerErrorNullWithParameterShouldThrowArgumentNullException() 52 | { 53 | var controller = new HomeController(); 54 | 55 | Assert.Throws(() => controller.TestExceptionResult(null, true)); 56 | } 57 | 58 | [Fact] 59 | public void NotImplementedShouldReturnNotImplementedResult() 60 | { 61 | var controller = new HomeController(); 62 | 63 | var result = controller.TestNotImplementedResult(); 64 | 65 | Assert.NotNull(result); 66 | Assert.IsAssignableFrom(result); 67 | } 68 | 69 | [Fact] 70 | public void BadGatewayShouldReturnBadGatewayResult() 71 | { 72 | var controller = new HomeController(); 73 | 74 | var result = controller.TestBadGatewayResult(); 75 | 76 | Assert.NotNull(result); 77 | Assert.IsAssignableFrom(result); 78 | } 79 | 80 | [Fact] 81 | public void ServiceUnavailableShouldReturnServiceUnavailableResult() 82 | { 83 | var controller = new HomeController(); 84 | 85 | var result = controller.TestServiceUnavailableResult(); 86 | 87 | Assert.NotNull(result); 88 | Assert.IsAssignableFrom(result); 89 | } 90 | 91 | [Fact] 92 | public void ServiceUnavailableShouldReturnServiceUnavailableResultWithLengthOfDelay() 93 | { 94 | var controller = new HomeController(); 95 | 96 | var lengthOfDelay = "10"; 97 | var result = controller.TestServiceUnavailableResultWithLengthOfDelay(lengthOfDelay); 98 | 99 | Assert.NotNull(result); 100 | Assert.IsAssignableFrom(result); 101 | var actionResult = (ServiceUnavailableResult)result; 102 | Assert.Equal(actionResult.LengthOfDelay, lengthOfDelay); 103 | } 104 | 105 | [Fact] 106 | public void GatewayTimeoutShouldReturnGatewayTimeoutResult() 107 | { 108 | var controller = new HomeController(); 109 | 110 | var result = controller.TestGatewayTimeoutResult(); 111 | 112 | Assert.NotNull(result); 113 | Assert.IsAssignableFrom(result); 114 | } 115 | 116 | [Fact] 117 | public void HttpVersionNotSupportedShouldReturnHttpVersionNotSupportedResult() 118 | { 119 | var controller = new HomeController(); 120 | var value = new object { }; 121 | 122 | var result = controller.TestHttpVersionNotSupportedResult(value); 123 | 124 | Assert.NotNull(result); 125 | Assert.IsAssignableFrom(result); 126 | var actionResult = (HttpVersionNotSupportedResult)result; 127 | Assert.Equal(actionResult.Value, value); 128 | } 129 | 130 | private class HomeController : ControllerBase 131 | { 132 | public IActionResult TestExceptionResult(Exception exception, bool includeErrorDetail) 133 | { 134 | return this.InternalServerError(exception, includeErrorDetail); 135 | } 136 | 137 | public IActionResult TestExceptionResult(Exception exception) 138 | { 139 | return this.InternalServerError(exception); 140 | } 141 | 142 | public IActionResult TestInternalServerError() 143 | { 144 | return this.InternalServerError(); 145 | } 146 | 147 | public IActionResult TestNotImplementedResult() 148 | { 149 | return this.NotImplemented(); 150 | } 151 | 152 | public IActionResult TestBadGatewayResult() 153 | { 154 | return this.BadGateway(); 155 | } 156 | 157 | public IActionResult TestServiceUnavailableResult() 158 | { 159 | return this.ServiceUnavailable(); 160 | } 161 | 162 | public IActionResult TestServiceUnavailableResultWithLengthOfDelay(string lengthOfDelay) 163 | { 164 | return this.ServiceUnavailable(lengthOfDelay); 165 | } 166 | 167 | public IActionResult TestGatewayTimeoutResult() 168 | { 169 | return this.GatewayTimeout(); 170 | } 171 | 172 | public IActionResult TestHttpVersionNotSupportedResult(object value) 173 | { 174 | return this.HTTPVersionNotSupported(value); 175 | } 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ServerError.Extensions/ServerErrorControllerBaseExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | 5 | /// 6 | /// Class containing server error HTTP response extensions methods for . 7 | /// 8 | public static class ServerErrorControllerBaseExtensions 9 | { 10 | /// 11 | /// Creates an object that produces an Internal Server Error (500) response. 12 | /// 13 | /// MVC controller instance. 14 | /// The created for the response. 15 | public static InternalServerErrorResult InternalServerError(this ControllerBase controller) 16 | => new InternalServerErrorResult(); 17 | 18 | /// 19 | /// Creates an object that produces an Internal Server Error (500) response. 20 | /// 21 | /// MVC controller instance. 22 | /// The exception to include in the error. 23 | /// The created for the response. 24 | public static ExceptionResult InternalServerError(this ControllerBase controller, Exception exception) 25 | { 26 | if (exception == null) 27 | { 28 | throw new ArgumentNullException(nameof(exception)); 29 | } 30 | 31 | return new ExceptionResult(exception); 32 | } 33 | 34 | /// 35 | /// Creates an object that produces an Internal Server Error (500) response. 36 | /// 37 | /// MVC controller instance. 38 | /// The exception to include in the error. 39 | /// 40 | /// if the error should include exception messages; otherwise, . 41 | /// 42 | /// The created for the response. 43 | public static ExceptionResult InternalServerError(this ControllerBase controller, Exception exception, bool includeErrorDetail) 44 | { 45 | if (exception == null) 46 | { 47 | throw new ArgumentNullException(nameof(exception)); 48 | } 49 | 50 | return new ExceptionResult(exception, includeErrorDetail); 51 | } 52 | 53 | /// 54 | /// Creates an object that produces a Not Implemented (501) response. 55 | /// 56 | /// MVC controller instance. 57 | /// The created for the response. 58 | public static NotImplementedResult NotImplemented(this ControllerBase controller) 59 | => new NotImplementedResult(); 60 | 61 | /// 62 | /// Creates a object that produces a Bad Getaway (502) response. 63 | /// 64 | /// MVC controller instance. 65 | /// The created for the response. 66 | public static BadGatewayResult BadGateway(this ControllerBase controller) 67 | => new BadGatewayResult(); 68 | 69 | /// 70 | /// Creates a object that produces an empty Service Unavailable (503) response. 71 | /// 72 | /// MVC controller instance. 73 | /// The created for the response. 74 | public static ServiceUnavailableResult ServiceUnavailable(this ControllerBase controller) 75 | => new ServiceUnavailableResult(); 76 | 77 | /// 78 | /// Creates a object that produces a Service Unavailable (503) response. 79 | /// 80 | /// MVC controller instance. 81 | /// Length of delay after which the server will be running again. 82 | /// The created for the response. 83 | public static ServiceUnavailableResult ServiceUnavailable(this ControllerBase controller, string lengthOfDelay) 84 | => new ServiceUnavailableResult(lengthOfDelay); 85 | 86 | /// 87 | /// Creates a object that produces a Gateway Timeout (504) response. 88 | /// 89 | /// MVC controller instance. 90 | /// The created for the response. 91 | public static GatewayTimeoutResult GatewayTimeout(this ControllerBase controller) 92 | => new GatewayTimeoutResult(); 93 | 94 | /// 95 | /// Creates a object that produces a HTTP Version Not Supported (505) response. 96 | /// 97 | /// MVC controller instance. 98 | /// The precondition failed value to format in the entity body. 99 | /// The created for the response. 100 | public static HttpVersionNotSupportedResult HTTPVersionNotSupported(this ControllerBase controller, object value) 101 | => new HttpVersionNotSupportedResult(value); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.Redirection.Test/RedirectionControllerBaseExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.Redirection.Test 2 | { 3 | using System; 4 | 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | using Xunit; 8 | 9 | public class RedirectionControllerBaseExtensionsTest 10 | { 11 | [Fact] 12 | public void MultipleChoicesShouldReturnMultipleChoicesResult() 13 | { 14 | var controller = new HomeController(); 15 | 16 | var result = controller.TestMultipleChoices(); 17 | 18 | Assert.NotNull(result); 19 | Assert.IsAssignableFrom(result); 20 | } 21 | 22 | [Fact] 23 | public void MultipleChoicesShouldReturnMultipleChoicesObjectResult() 24 | { 25 | var controller = new HomeController(); 26 | var sampleValue = "Hello world!"; 27 | 28 | var result = controller.TestMultipleChoices(sampleValue); 29 | 30 | Assert.NotNull(result); 31 | Assert.IsAssignableFrom(result); 32 | } 33 | 34 | [Fact] 35 | public void SeeOtherShouldReturnSeeOtherResult() 36 | { 37 | var controller = new HomeController(); 38 | 39 | var result = controller.TestSeeOther(); 40 | 41 | Assert.NotNull(result); 42 | Assert.IsAssignableFrom(result); 43 | } 44 | 45 | [Fact] 46 | public void SeeOtherShouldReturnSeeOtherObjectResult() 47 | { 48 | var controller = new HomeController(); 49 | var sampleValue = "Hello world!"; 50 | 51 | var result = controller.TestSeeOther(sampleValue); 52 | 53 | Assert.NotNull(result); 54 | Assert.IsAssignableFrom(result); 55 | } 56 | 57 | [Fact] 58 | public void NotModifiedShouldReturnNotModifiedResult() 59 | { 60 | var controller = new HomeController(); 61 | 62 | var result = controller.TestNotModified(); 63 | 64 | Assert.NotNull(result); 65 | Assert.IsAssignableFrom(result); 66 | } 67 | 68 | [Fact] 69 | public void UseProxShouldReturnUseProxResult() 70 | { 71 | var controller = new HomeController(); 72 | var sampleValue = "fakeProxy"; 73 | 74 | var result = controller.TestUseProxy(sampleValue); 75 | 76 | Assert.NotNull(result); 77 | Assert.IsAssignableFrom(result); 78 | } 79 | 80 | [Theory] 81 | [InlineData(null)] 82 | [InlineData("")] 83 | [InlineData(" ")] 84 | public void UseProxShouldThrowExceptionIfInvalidProxyIsGiven(string proxyValue) 85 | { 86 | var controller = new HomeController(); 87 | 88 | Assert.Throws(() => controller.TestUseProxy(proxyValue)); 89 | } 90 | 91 | [Fact] 92 | public void TemporaryRedirectShouldTemporaryRedirectResult() 93 | { 94 | var controller = new HomeController(); 95 | var sampleUri = "fakeUri"; 96 | 97 | var result = controller.TestTemporaryRedirect(sampleUri); 98 | 99 | Assert.NotNull(result); 100 | Assert.IsAssignableFrom(result); 101 | } 102 | 103 | [Fact] 104 | public void TemporaryRedirectShouldTemporaryRedirectObjectResult() 105 | { 106 | var controller = new HomeController(); 107 | var sampleUri = "fakeUri"; 108 | var sampleValue = "HelloWorld"; 109 | 110 | var result = controller.TestTemporaryRedirect(sampleValue, sampleUri); 111 | 112 | Assert.NotNull(result); 113 | Assert.IsAssignableFrom(result); 114 | } 115 | 116 | [Theory] 117 | [InlineData(null)] 118 | [InlineData("")] 119 | [InlineData(" ")] 120 | public void TemporaryRedirectThrowExceptionIfInvalidProxyIsGiven(string proxyValue) 121 | { 122 | var controller = new HomeController(); 123 | var sampleValue = "HelloWorld!"; 124 | 125 | Assert.Throws(() => controller.TemporaryRedirect(proxyValue)); 126 | 127 | Assert.Throws(() => controller.TemporaryRedirect(sampleValue, proxyValue)); 128 | } 129 | 130 | private class HomeController : ControllerBase 131 | { 132 | public IActionResult TestMultipleChoices() 133 | { 134 | return this.MultipleChoices(); 135 | } 136 | 137 | public IActionResult TestMultipleChoices(object value) 138 | { 139 | return this.MultipleChoices(value); 140 | } 141 | 142 | public IActionResult TestSeeOther() 143 | { 144 | return this.SeeOther(); 145 | } 146 | 147 | public IActionResult TestSeeOther(object value) 148 | { 149 | return this.SeeOther(value); 150 | } 151 | 152 | public IActionResult TestNotModified() 153 | { 154 | return this.NotModified(); 155 | } 156 | 157 | public IActionResult TestUseProxy(string proxyUri) 158 | { 159 | return this.UseProxy(proxyUri); 160 | } 161 | 162 | public IActionResult TestTemporaryRedirect(string temporaryUri) 163 | { 164 | return this.TemporaryRedirect(temporaryUri); 165 | } 166 | 167 | public IActionResult TestTemporaryRedirect(object value, string temporaryUri) 168 | { 169 | return this.TemporaryRedirect(value, temporaryUri); 170 | } 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.Redirection.Extensions/RedirectionControllerBaseExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | /// 4 | /// Class containing redirection HTTP response extensions methods for . 5 | /// 6 | public static class RedirectionControllerBaseExtensions 7 | { 8 | /// 9 | /// Creates an object that produces a Multiple Choices (300) response. 10 | /// 11 | /// MVC controller instance. 12 | /// Preferred resource choice represented as an URI. 13 | /// The created for the response. 14 | public static MultipleChoicesResult MultipleChoices(this ControllerBase controller, string preferedChoiceUri = null) 15 | => new MultipleChoicesResult(preferedChoiceUri); 16 | 17 | /// 18 | /// Creates an object that produces a Multiple Choices (300) response. 19 | /// 20 | /// MVC controller instance. 21 | /// List of resource characteristics and location(s) to format in the entity body. 22 | /// Preferred resource choice represented as an URI. 23 | /// The created for the response. 24 | public static MultipleChoicesObjectResult MultipleChoices( 25 | this ControllerBase controller, 26 | object value, 27 | string preferedChoiceUri = null) 28 | => new MultipleChoicesObjectResult(value); 29 | 30 | /// 31 | /// Creates an object that produces a See Other (303) response. 32 | /// 33 | /// MVC controller instance. 34 | /// The created for the response. 35 | public static SeeOtherResult SeeOther(this ControllerBase controller) 36 | => new SeeOtherResult(); 37 | 38 | /// 39 | /// Creates an object that produces a See Other (303) response. 40 | /// 41 | /// MVC controller instance. 42 | /// The URI at which the content has been created. 43 | /// The created for the response. 44 | public static SeeOtherResult SeeOther(this ControllerBase controller, string uri) 45 | => new SeeOtherResult(uri); 46 | 47 | /// 48 | /// Creates an object that produces a See Other (303) response. 49 | /// 50 | /// MVC controller instance. 51 | /// The accepted value to format in the entity body. 52 | /// The created for the response. 53 | public static SeeOtherObjectResult SeeOther(this ControllerBase controller, object value) 54 | => new SeeOtherObjectResult(value); 55 | 56 | /// 57 | /// Creates an object that produces a See Other (303) response. 58 | /// 59 | /// MVC controller instance. 60 | /// The URI at which the content has been created. 61 | /// The accepted value to format in the entity body. 62 | /// The created for the response. 63 | public static SeeOtherObjectResult SeeOther(this ControllerBase controller, string uri, object value) 64 | => new SeeOtherObjectResult(uri, value); 65 | 66 | /// 67 | /// Creates an object that produces a Not Modified (304) response. 68 | /// 69 | /// MVC controller instance. 70 | /// The created for the response. 71 | public static NotModifiedResult NotModified(this ControllerBase controller) 72 | => new NotModifiedResult(); 73 | 74 | /// 75 | /// Creates an object that produces a Use Proxy (305) response. 76 | /// 77 | /// MVC controller instance. 78 | /// A proxy through which the requested resource must be accessed. 79 | /// The created for the response. 80 | public static UseProxyResult UseProxy(this ControllerBase controller, string proxyUri) 81 | => new UseProxyResult(proxyUri); 82 | 83 | /// 84 | /// Creates an object that produces a Temporary Redirect (307) response. 85 | /// 86 | /// MVC controller instance. 87 | /// The temporary URI of the requested resource resides. 88 | /// The created for the response. 89 | public static TemporaryRedirectResult TemporaryRedirect(this ControllerBase controller, string temporaryUri) 90 | => new TemporaryRedirectResult(temporaryUri); 91 | 92 | /// 93 | /// Creates an object that produces a Temporary Redirect (307) response. 94 | /// 95 | /// MVC controller instance. 96 | /// The accepted value to format in the entity body. 97 | /// The temporary URI of the requested resource resides. 98 | /// The created for the response. 99 | public static TemporaryRedirectObjectResult TemporaryRedirect(this ControllerBase controller, object value, string temporaryUri) 100 | => new TemporaryRedirectObjectResult(value, temporaryUri); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

AspNetCore.Mvc.HttpActionResults  AspNetCore.Mvc.HttpActionResults - HTTP
  status code results for ASP.NET Core MVC
 

2 | ==================================== 3 | 4 | AspNetCore.Mvc.HttpActionResults is a collection of HTTP status code action results and controller extension methods for [ASP.NET Core MVC](https://github.com/aspnet/Mvc). Implemented as per the [HTTP status code specifications](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html). 5 | 6 | ## Installation 7 | 8 | You can install this library using NuGet into your project (or reference it directly in your `project.json` file). There is no need to add any namespace usings since the package uses the default ones to add extension methods. 9 | 10 | Install-Package AspNetCore.Mvc.HttpActionResults 11 | 12 | This package will include all available action results and extension methods in your test project. If you prefer, you can be more specific by including only some of the packages. 13 | 14 | ### Action results packages: 15 | 16 | - `AspNetCore.Mvc.HttpActionResults.Informational` - Contains Informational (1xx) HTTP action results 17 | - `AspNetCore.Mvc.HttpActionResults.Success` - Contains Success (2xx) HTTP action results 18 | - `AspNetCore.Mvc.HttpActionResults.Redirection` - Contains Redirection (3xx) HTTP action results 19 | - `AspNetCore.Mvc.HttpActionResults.ClientError` - Contains Client Error (4xx) HTTP action results 20 | - `AspNetCore.Mvc.HttpActionResults.ServerError` - Contains Server Error (5xx) HTTP action results 21 | 22 | ### ControllerBase extension methods packages: 23 | 24 | - `AspNetCore.Mvc.HttpActionResults.Informational.Extensions` - Contains Informational (1xx) HTTP extension methods 25 | - `AspNetCore.Mvc.HttpActionResults.Success.Extensions` - Contains Success (2xx) HTTP extension methods 26 | - `AspNetCore.Mvc.HttpActionResults.Redirection.Extensions` - Contains Redirection (3xx) HTTP extension methods 27 | - `AspNetCore.Mvc.HttpActionResults.ClientError.Extensions` - Contains Client Error (4xx) HTTP extension methods 28 | - `AspNetCore.Mvc.HttpActionResults.ServerError.Extensions` - Contains Server Error (5xx) HTTP extension methods 29 | 30 | ## How to use 31 | 32 | After the downloading is complete, you can use the provided action results and controller extension methods. 33 | 34 | ### Available action results: 35 | 36 | ```c# 37 | // 100 Continue 38 | ContinueResult 39 | 40 | // 101 Switching Protocols 41 | SwitchingProtocolsResult 42 | 43 | // 203 Non-Authoritative Information 44 | NonAuthoritativeInformationResult 45 | 46 | // 205 Reset Content 47 | ResetContentResult 48 | 49 | // 206 Partial Content 50 | PartialContentResult 51 | PartialContentObjectResult 52 | 53 | // 300 Multiple Choices 54 | MultipleChoicesResult 55 | MultipleChoicesObjectResult 56 | 57 | // 303 See Other 58 | SeeOtherResult 59 | SeeOtherObjectResult 60 | 61 | // 304 Not Modified 62 | NotModifiedResult 63 | 64 | // 305 Use Proxy 65 | UseProxyResult 66 | 67 | // 305 Temporary Redirect 68 | TemporaryRedirectResult 69 | TemporaryRedirectObjectResult 70 | 71 | // 402 Payment Required 72 | PaymentRequiredResult 73 | 74 | // 405 Method Not Allowed 75 | MethodNotAllowedResult 76 | 77 | // 406 Not Acceptable 78 | NotAcceptableResult 79 | NotAcceptableObjectResult 80 | 81 | // 407 Proxy Authentication Required 82 | ProxyAuthenticationRequiredResult 83 | 84 | // 408 Request Timeout 85 | RequestTimeoutResult 86 | 87 | // 409 Conflict 88 | ConflictResult 89 | ConflictObjectResult 90 | 91 | // 410 Gone 92 | GoneResult 93 | 94 | // 411 Length Required 95 | LengthRequiredResult 96 | 97 | // 412 Precondition Failed 98 | PreconditionFailedResult 99 | PreconditionFailedObjectResult 100 | 101 | // 413 Request Entity Too Large 102 | RequestEntityTooLargeResult 103 | 104 | // 414 Request URI Too Long 105 | RequestUriTooLongResult 106 | 107 | // 415 Unsupported Media Type 108 | UnsupportedMediaTypeResult 109 | 110 | // 418 Im A Teapot 111 | ImATeapotResult 112 | 113 | // 500 Internal Server Error 114 | InternalServerErrorResult 115 | ExceptionResult 116 | 117 | // 501 Not Implemented 118 | NotImplementedResult 119 | 120 | // 502 Bad Gateway 121 | BadGatewayResult 122 | 123 | // 503 Service Unavailable 124 | ServiceUnavailableResult 125 | 126 | // 504 Gateway Timeout 127 | GatewayTimeoutResult 128 | 129 | // 505 HTTP Version Not Supported 130 | HTTPVersionNotSupportedResult 131 | ``` 132 | 133 | ### Available ControllerBase extension methods: 134 | 135 | ```c# 136 | // returns 100 Continue 137 | controller.Continue(); 138 | 139 | // returns 101 Switching Protocols 140 | controller.SwitchingProtocols(upgradeValue); 141 | 142 | // returns 203 Non-Authoritative Information 143 | controller.NonAuthoritativeInformation(); 144 | 145 | // returns 205 Reset Content 146 | controller.ResetContent(); 147 | 148 | // returns 205 Partial Content 149 | controller.PartialContent(); 150 | 151 | // returns 205 Partial Content with formatted value 152 | controller.PartialContent(someObject); 153 | 154 | // returns 300 Multiple Choices 155 | controller.MultipleChoices(); 156 | 157 | // returns 300 Multiple Choices with formatted value 158 | controller.MultipleChoices(someObject); 159 | 160 | // returns 303 See Other 161 | controller.SeeOther(); 162 | 163 | // returns 303 See Other with Location header 164 | controller.SeeOther(someUri); 165 | 166 | // returns 303 See Other with formatted value 167 | controller.SeeOther(someObject); 168 | 169 | // returns 303 See Other with Location header and formatted value 170 | controller.SeeOther(someUri, someObject); 171 | 172 | // returns 304 Not Modified 173 | controller.NotModified(); 174 | 175 | // returns 305 Use Proxy with Location header(containing the proxy URI) 176 | controller.UseProxy(proxyUri); 177 | 178 | // returns 307 Temporary Redirect wtih Location header 179 | controller.TemporaryRedirect(temporaryUri); 180 | 181 | // returns 307 Temporary Redirect wtih Location header and formatted value 182 | controller.TemporaryRedirect(someObject, temporaryUri); 183 | 184 | // returns 402 Payment Required 185 | controller.PaymentRequired(); 186 | 187 | // returns 405 Method Not Allowed 188 | controller.MethodNotAllowed(); 189 | 190 | // returns 406 Not Acceptable 191 | controller.NotAcceptable(); 192 | 193 | // returns 406 Not Acceptable with formatted value 194 | controller.NotAcceptable(someObject); 195 | 196 | // returns 407 Proxy Authentication Required witch Proxy-Authenticate header 197 | controller.ProxyAuthenticationRequired(proxyAuthenticate); 198 | 199 | // returns 408 Request Timeout 200 | controller.RequestTimeout(); 201 | 202 | // returns 409 Conflict 203 | controller.Conflict(); 204 | 205 | // returns 409 Conflict with formatted value 206 | controller.Conflict(someObject); 207 | 208 | // returns 410 Gone 209 | controller.Gone(); 210 | 211 | // returns 411 Length Required 212 | controller.LengthRequired(); 213 | 214 | // returns 412 Precondition Failed 215 | controller.PreconditionFailed(); 216 | 217 | // returns 412 Precondition Failed with formatted value 218 | controller.PreconditionFailed(someObject); 219 | 220 | // returns 413 Request Entity Too Large 221 | controller.PreconditionFailed(); 222 | 223 | // returns 413 Request Entity Too Large with Retry-After header 224 | controller.PreconditionFailed(retryAfter); 225 | 226 | // returns 414 Request URI Too Long 227 | controller.RequestUriTooLong(); 228 | 229 | // returns 415 Unsupported Media Type 230 | controller.UnsupportedMediaType(); 231 | 232 | // returns 416 Requested Range Not Satisfiable 233 | controller.RequestedRangeNotSatisfiable(); 234 | 235 | // returns 417 Expectation Failed 236 | controller.ExpectationFailed(); 237 | 238 | // returns 418 Im A Teapot 239 | controller.ImATeapot(); 240 | 241 | // returns 500 Internal Server Error 242 | controller.InternalServerError(); 243 | 244 | // returns 501 Not Implemented 245 | controller.NotImplemented(); 246 | 247 | // returns 502 Bad Gateway 248 | controller.BadGateway(); 249 | 250 | // returns 503 Service Unavailable 251 | controller.ServiceUnavailable(); 252 | 253 | // returns 504 Gateway Timeout 254 | controller.GatewayTimeout(); 255 | 256 | // returns 505 HTTP Version Not Supported 257 | controller.HTTPVersionNotSupported(); 258 | ``` 259 | 260 | ## License 261 | 262 | Code by Ivaylo Kenov. Copyright 2016 Ivaylo Kenov. 263 | 264 | This package has MIT license. Refer to the [LICENSE](https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/blob/master/LICENSE) for detailed information. 265 | 266 | ## Any questions, comments or additions? 267 | 268 | If you have a feature request or bug report, leave an issue on the [issues page](https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/issues) or send a [pull request](https://github.com/ivaylokenov/AspNetCore.Mvc.HttpActionResults/pulls). For general questions and comments, use the [StackOverflow](http://stackoverflow.com/) forum. 269 | -------------------------------------------------------------------------------- /AspNetCore.Mvc.HttpActionResults.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26228.10 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0250AF09-DBA6-4024-B551-56B65338BC67}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "globals", "globals", "{9CBF7DB8-D11C-4EA9-A3BB-EDCA14423546}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2DE37686-2EBC-47AD-8419-612AEDBCA40D}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults", "src\AspNetCore.Mvc.HttpActionResults\AspNetCore.Mvc.HttpActionResults.csproj", "{83AFFF70-971B-41BB-9D32-B88B8965B475}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Informational", "src\AspNetCore.Mvc.HttpActionResults.Informational\AspNetCore.Mvc.HttpActionResults.Informational.csproj", "{8A488BE4-1AE0-4785-BBF9-6EBB034F3F64}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Success", "src\AspNetCore.Mvc.HttpActionResults.Success\AspNetCore.Mvc.HttpActionResults.Success.csproj", "{958D691D-A587-45C1-B617-0E9EAD05A86A}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Redirection", "src\AspNetCore.Mvc.HttpActionResults.Redirection\AspNetCore.Mvc.HttpActionResults.Redirection.csproj", "{6C6F319B-B038-467D-9840-187B4DD3F6B7}" 19 | EndProject 20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.ClientError", "src\AspNetCore.Mvc.HttpActionResults.ClientError\AspNetCore.Mvc.HttpActionResults.ClientError.csproj", "{81FD818D-36D5-4B82-A781-6309FF7EFF47}" 21 | EndProject 22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.ServerError", "src\AspNetCore.Mvc.HttpActionResults.ServerError\AspNetCore.Mvc.HttpActionResults.ServerError.csproj", "{1A2AB45E-071E-40F5-B71F-171DF9656B51}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Success.Extensions", "src\AspNetCore.Mvc.HttpActionResults.Success.Extensions\AspNetCore.Mvc.HttpActionResults.Success.Extensions.csproj", "{55D14C10-2354-4517-8F45-ADCA43301043}" 25 | EndProject 26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.ClientError.Extensions", "src\AspNetCore.Mvc.HttpActionResults.ClientError.Extensions\AspNetCore.Mvc.HttpActionResults.ClientError.Extensions.csproj", "{46B4C3B6-2E3C-4EF2-814B-BEF6141B8CE1}" 27 | EndProject 28 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Informational.Extensions", "src\AspNetCore.Mvc.HttpActionResults.Informational.Extensions\AspNetCore.Mvc.HttpActionResults.Informational.Extensions.csproj", "{B4CC9426-BF47-4712-9B34-D0D3E13980B4}" 29 | EndProject 30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Redirection.Extensions", "src\AspNetCore.Mvc.HttpActionResults.Redirection.Extensions\AspNetCore.Mvc.HttpActionResults.Redirection.Extensions.csproj", "{8DDE7331-5DAA-4C63-9DF4-EC0850DA7A3C}" 31 | EndProject 32 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.ServerError.Extensions", "src\AspNetCore.Mvc.HttpActionResults.ServerError.Extensions\AspNetCore.Mvc.HttpActionResults.ServerError.Extensions.csproj", "{BDD9F3C5-D67D-4B10-B931-3812A4282BC4}" 33 | EndProject 34 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.ClientError.Test", "test\AspNetCore.Mvc.HttpActionResults.ClientError.Test\AspNetCore.Mvc.HttpActionResults.ClientError.Test.csproj", "{9440B360-66AC-4BED-8434-D40B86966F1D}" 35 | EndProject 36 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.Success.Test", "test\AspNetCore.Mvc.HttpActionResults.Success.Test\AspNetCore.Mvc.HttpActionResults.Success.Test.csproj", "{99861FB2-3896-4EFA-A332-D7F8D8AB6489}" 37 | EndProject 38 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Mvc.HttpActionResults.ServerError.Test", "test\AspNetCore.Mvc.HttpActionResults.ServerError.Test\AspNetCore.Mvc.HttpActionResults.ServerError.Test.csproj", "{4F753C9C-8146-48C4-BFEF-6BC0B6E62DA9}" 39 | EndProject 40 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Mvc.HttpActionResults.Test", "test\AspNetCore.Mvc.HttpActionResults.Test\AspNetCore.Mvc.HttpActionResults.Test.csproj", "{B3959A96-C0BA-45F7-89B5-9597F506046C}" 41 | EndProject 42 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.Mvc.HttpActionResults.Redirection.Test", "test\AspNetCore.Mvc.HttpActionResults.Redirection.Test\AspNetCore.Mvc.HttpActionResults.Redirection.Test.csproj", "{048525D5-5D52-4DB7-AD46-A394215C04C8}" 43 | EndProject 44 | Global 45 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 46 | Debug|Any CPU = Debug|Any CPU 47 | Release|Any CPU = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 50 | {83AFFF70-971B-41BB-9D32-B88B8965B475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {83AFFF70-971B-41BB-9D32-B88B8965B475}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {83AFFF70-971B-41BB-9D32-B88B8965B475}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {83AFFF70-971B-41BB-9D32-B88B8965B475}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {8A488BE4-1AE0-4785-BBF9-6EBB034F3F64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {8A488BE4-1AE0-4785-BBF9-6EBB034F3F64}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {8A488BE4-1AE0-4785-BBF9-6EBB034F3F64}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {8A488BE4-1AE0-4785-BBF9-6EBB034F3F64}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {958D691D-A587-45C1-B617-0E9EAD05A86A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {958D691D-A587-45C1-B617-0E9EAD05A86A}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {958D691D-A587-45C1-B617-0E9EAD05A86A}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {958D691D-A587-45C1-B617-0E9EAD05A86A}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {6C6F319B-B038-467D-9840-187B4DD3F6B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {6C6F319B-B038-467D-9840-187B4DD3F6B7}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {6C6F319B-B038-467D-9840-187B4DD3F6B7}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {6C6F319B-B038-467D-9840-187B4DD3F6B7}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {81FD818D-36D5-4B82-A781-6309FF7EFF47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {81FD818D-36D5-4B82-A781-6309FF7EFF47}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {81FD818D-36D5-4B82-A781-6309FF7EFF47}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {81FD818D-36D5-4B82-A781-6309FF7EFF47}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {1A2AB45E-071E-40F5-B71F-171DF9656B51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 71 | {1A2AB45E-071E-40F5-B71F-171DF9656B51}.Debug|Any CPU.Build.0 = Debug|Any CPU 72 | {1A2AB45E-071E-40F5-B71F-171DF9656B51}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 | {1A2AB45E-071E-40F5-B71F-171DF9656B51}.Release|Any CPU.Build.0 = Release|Any CPU 74 | {55D14C10-2354-4517-8F45-ADCA43301043}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 75 | {55D14C10-2354-4517-8F45-ADCA43301043}.Debug|Any CPU.Build.0 = Debug|Any CPU 76 | {55D14C10-2354-4517-8F45-ADCA43301043}.Release|Any CPU.ActiveCfg = Release|Any CPU 77 | {55D14C10-2354-4517-8F45-ADCA43301043}.Release|Any CPU.Build.0 = Release|Any CPU 78 | {46B4C3B6-2E3C-4EF2-814B-BEF6141B8CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 | {46B4C3B6-2E3C-4EF2-814B-BEF6141B8CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 | {46B4C3B6-2E3C-4EF2-814B-BEF6141B8CE1}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 | {46B4C3B6-2E3C-4EF2-814B-BEF6141B8CE1}.Release|Any CPU.Build.0 = Release|Any CPU 82 | {B4CC9426-BF47-4712-9B34-D0D3E13980B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 83 | {B4CC9426-BF47-4712-9B34-D0D3E13980B4}.Debug|Any CPU.Build.0 = Debug|Any CPU 84 | {B4CC9426-BF47-4712-9B34-D0D3E13980B4}.Release|Any CPU.ActiveCfg = Release|Any CPU 85 | {B4CC9426-BF47-4712-9B34-D0D3E13980B4}.Release|Any CPU.Build.0 = Release|Any CPU 86 | {8DDE7331-5DAA-4C63-9DF4-EC0850DA7A3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 87 | {8DDE7331-5DAA-4C63-9DF4-EC0850DA7A3C}.Debug|Any CPU.Build.0 = Debug|Any CPU 88 | {8DDE7331-5DAA-4C63-9DF4-EC0850DA7A3C}.Release|Any CPU.ActiveCfg = Release|Any CPU 89 | {8DDE7331-5DAA-4C63-9DF4-EC0850DA7A3C}.Release|Any CPU.Build.0 = Release|Any CPU 90 | {BDD9F3C5-D67D-4B10-B931-3812A4282BC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 91 | {BDD9F3C5-D67D-4B10-B931-3812A4282BC4}.Debug|Any CPU.Build.0 = Debug|Any CPU 92 | {BDD9F3C5-D67D-4B10-B931-3812A4282BC4}.Release|Any CPU.ActiveCfg = Release|Any CPU 93 | {BDD9F3C5-D67D-4B10-B931-3812A4282BC4}.Release|Any CPU.Build.0 = Release|Any CPU 94 | {9440B360-66AC-4BED-8434-D40B86966F1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 95 | {9440B360-66AC-4BED-8434-D40B86966F1D}.Debug|Any CPU.Build.0 = Debug|Any CPU 96 | {9440B360-66AC-4BED-8434-D40B86966F1D}.Release|Any CPU.ActiveCfg = Release|Any CPU 97 | {9440B360-66AC-4BED-8434-D40B86966F1D}.Release|Any CPU.Build.0 = Release|Any CPU 98 | {99861FB2-3896-4EFA-A332-D7F8D8AB6489}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 99 | {99861FB2-3896-4EFA-A332-D7F8D8AB6489}.Debug|Any CPU.Build.0 = Debug|Any CPU 100 | {99861FB2-3896-4EFA-A332-D7F8D8AB6489}.Release|Any CPU.ActiveCfg = Release|Any CPU 101 | {99861FB2-3896-4EFA-A332-D7F8D8AB6489}.Release|Any CPU.Build.0 = Release|Any CPU 102 | {4F753C9C-8146-48C4-BFEF-6BC0B6E62DA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 103 | {4F753C9C-8146-48C4-BFEF-6BC0B6E62DA9}.Debug|Any CPU.Build.0 = Debug|Any CPU 104 | {4F753C9C-8146-48C4-BFEF-6BC0B6E62DA9}.Release|Any CPU.ActiveCfg = Release|Any CPU 105 | {4F753C9C-8146-48C4-BFEF-6BC0B6E62DA9}.Release|Any CPU.Build.0 = Release|Any CPU 106 | {B3959A96-C0BA-45F7-89B5-9597F506046C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 107 | {B3959A96-C0BA-45F7-89B5-9597F506046C}.Debug|Any CPU.Build.0 = Debug|Any CPU 108 | {B3959A96-C0BA-45F7-89B5-9597F506046C}.Release|Any CPU.ActiveCfg = Release|Any CPU 109 | {B3959A96-C0BA-45F7-89B5-9597F506046C}.Release|Any CPU.Build.0 = Release|Any CPU 110 | {048525D5-5D52-4DB7-AD46-A394215C04C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 111 | {048525D5-5D52-4DB7-AD46-A394215C04C8}.Debug|Any CPU.Build.0 = Debug|Any CPU 112 | {048525D5-5D52-4DB7-AD46-A394215C04C8}.Release|Any CPU.ActiveCfg = Release|Any CPU 113 | {048525D5-5D52-4DB7-AD46-A394215C04C8}.Release|Any CPU.Build.0 = Release|Any CPU 114 | EndGlobalSection 115 | GlobalSection(SolutionProperties) = preSolution 116 | HideSolutionNode = FALSE 117 | EndGlobalSection 118 | GlobalSection(NestedProjects) = preSolution 119 | {83AFFF70-971B-41BB-9D32-B88B8965B475} = {0250AF09-DBA6-4024-B551-56B65338BC67} 120 | {8A488BE4-1AE0-4785-BBF9-6EBB034F3F64} = {0250AF09-DBA6-4024-B551-56B65338BC67} 121 | {958D691D-A587-45C1-B617-0E9EAD05A86A} = {0250AF09-DBA6-4024-B551-56B65338BC67} 122 | {6C6F319B-B038-467D-9840-187B4DD3F6B7} = {0250AF09-DBA6-4024-B551-56B65338BC67} 123 | {81FD818D-36D5-4B82-A781-6309FF7EFF47} = {0250AF09-DBA6-4024-B551-56B65338BC67} 124 | {1A2AB45E-071E-40F5-B71F-171DF9656B51} = {0250AF09-DBA6-4024-B551-56B65338BC67} 125 | {55D14C10-2354-4517-8F45-ADCA43301043} = {0250AF09-DBA6-4024-B551-56B65338BC67} 126 | {46B4C3B6-2E3C-4EF2-814B-BEF6141B8CE1} = {0250AF09-DBA6-4024-B551-56B65338BC67} 127 | {B4CC9426-BF47-4712-9B34-D0D3E13980B4} = {0250AF09-DBA6-4024-B551-56B65338BC67} 128 | {8DDE7331-5DAA-4C63-9DF4-EC0850DA7A3C} = {0250AF09-DBA6-4024-B551-56B65338BC67} 129 | {BDD9F3C5-D67D-4B10-B931-3812A4282BC4} = {0250AF09-DBA6-4024-B551-56B65338BC67} 130 | {9440B360-66AC-4BED-8434-D40B86966F1D} = {2DE37686-2EBC-47AD-8419-612AEDBCA40D} 131 | {99861FB2-3896-4EFA-A332-D7F8D8AB6489} = {2DE37686-2EBC-47AD-8419-612AEDBCA40D} 132 | {4F753C9C-8146-48C4-BFEF-6BC0B6E62DA9} = {2DE37686-2EBC-47AD-8419-612AEDBCA40D} 133 | {B3959A96-C0BA-45F7-89B5-9597F506046C} = {2DE37686-2EBC-47AD-8419-612AEDBCA40D} 134 | {048525D5-5D52-4DB7-AD46-A394215C04C8} = {2DE37686-2EBC-47AD-8419-612AEDBCA40D} 135 | EndGlobalSection 136 | EndGlobal 137 | -------------------------------------------------------------------------------- /src/AspNetCore.Mvc.HttpActionResults.ClientError.Extensions/ClientErrorControllerBaseExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.AspNetCore.Mvc 2 | { 3 | using System; 4 | 5 | using Extensions.Primitives; 6 | 7 | /// 8 | /// Class containing client error HTTP response extensions methods for . 9 | /// 10 | public static class ClientErrorControllerBaseExtensions 11 | { 12 | /// 13 | /// Creates a object that produces a Payment Required (402) response. 14 | /// 15 | /// MVC controller instance. 16 | /// The created for the response. 17 | public static PaymentRequiredResult PaymentRequired(this ControllerBase controller) 18 | => new PaymentRequiredResult(); 19 | 20 | /// 21 | /// Creates a object that produces a Method Not Allowed (405) response. 22 | /// 23 | /// MVC controller instance. 24 | /// Allowed HTTPS methods for this request. 25 | /// The created for the response. 26 | public static MethodNotAllowedResult MethodNotAllowed(this ControllerBase controller, string allowedMethods) 27 | => new MethodNotAllowedResult(allowedMethods); 28 | 29 | /// 30 | /// Creates a object that produces a Method Not Allowed (405) response. 31 | /// 32 | /// MVC controller instance. 33 | /// Allowed HTTPS methods for this request. 34 | /// The created for the response. 35 | public static MethodNotAllowedResult MethodNotAllowed(this ControllerBase controller, params string[] allowedMethods) 36 | => new MethodNotAllowedResult(new StringValues(allowedMethods)); 37 | 38 | /// 39 | /// Creates a object that produces a Conflict (409) response. 40 | /// 41 | /// MVC controller instance. 42 | /// The created for the response. 43 | public static ConflictResult Conflict(this ControllerBase controller) 44 | => new ConflictResult(); 45 | 46 | /// 47 | /// Creates a object that produces a Conflict (409) response. 48 | /// 49 | /// MVC controller instance. 50 | /// Information regarding the source of the conflict. 51 | /// The created for the response. 52 | public static ConflictObjectResult Conflict(this ControllerBase controller, object value) 53 | => new ConflictObjectResult(value); 54 | 55 | /// 56 | /// Creates a object that produces a Precondition Failed (412) response. 57 | /// 58 | /// MVC controller instance. 59 | /// The created for the response. 60 | public static NotAcceptableResult NotAcceptable(this ControllerBase controller) 61 | => new NotAcceptableResult(); 62 | 63 | /// 64 | /// Creates a object that produces a Not Acceptable (406) response. 65 | /// 66 | /// MVC controller instance. 67 | /// 68 | /// An object containing information about available entity characteristics and location(s) 69 | /// from which the user can choose the one most appropriate. 70 | /// 71 | /// The created for the response. 72 | public static NotAcceptableObjectResult NotAcceptable(this ControllerBase controller, object value) 73 | => new NotAcceptableObjectResult(value); 74 | 75 | /// 76 | /// Creates a object that produces a Proxy Authentication Required (407) response. 77 | /// 78 | /// MVC controller instance. 79 | /// Challenge applicable to the proxy for the requested resource. 80 | /// The created for the response. 81 | public static ProxyAuthenticationRequiredResult ProxyAuthenticationRequired(this ControllerBase controller, string proxyAuthenticate) 82 | => new ProxyAuthenticationRequiredResult(proxyAuthenticate); 83 | 84 | /// 85 | /// Creates a object that produces a Gone (410) response. 86 | /// 87 | /// MVC controller instance. 88 | /// The created for the response. 89 | public static GoneResult Gone(this ControllerBase controller) 90 | => new GoneResult(); 91 | 92 | /// 93 | /// Creates a object that produces a Length Required (411) response. 94 | /// 95 | /// MVC controller instance. 96 | /// The created for the response. 97 | public static LengthRequiredResult LengthRequired(this ControllerBase controller) 98 | => new LengthRequiredResult(); 99 | 100 | /// 101 | /// Creates a object that produces a Precondition Failed (412) response. 102 | /// 103 | /// MVC controller instance. 104 | /// The created for the response. 105 | public static PreconditionFailedResult PreconditionFailed(this ControllerBase controller) 106 | => new PreconditionFailedResult(); 107 | 108 | /// 109 | /// Creates a object that produces a Precondition Failed (412) response. 110 | /// 111 | /// MVC controller instance. 112 | /// The precondition failed value to format in the entity body. 113 | /// The created for the response. 114 | public static PreconditionFailedObjectResult PreconditionFailed(this ControllerBase controller, object value) 115 | => new PreconditionFailedObjectResult(value); 116 | 117 | /// 118 | /// Creates a object that produces a Request Entity Too Large (413) response. 119 | /// 120 | /// MVC controller instance. 121 | /// The created for the response. 122 | public static RequestEntityTooLargeResult RequestEntityTooLarge(this ControllerBase controller) 123 | => new RequestEntityTooLargeResult(); 124 | 125 | /// 126 | /// Creates a object that produces a Request Entity Too Large (413) response. 127 | /// 128 | /// MVC controller instance. 129 | /// The time after which the client may try the request again in seconds. 130 | /// The created for the response. 131 | public static RequestEntityTooLargeResult RequestEntityTooLarge(this ControllerBase controller, long retryAfter) 132 | => new RequestEntityTooLargeResult(retryAfter.ToString()); 133 | 134 | /// 135 | /// Creates a object that produces a Request Entity Too Large (413) response. 136 | /// 137 | /// MVC controller instance. 138 | /// The after which the client may try the request again. 139 | /// The created for the response. 140 | public static RequestEntityTooLargeResult RequestEntityTooLarge(this ControllerBase controller, DateTime retryAfter) 141 | => new RequestEntityTooLargeResult(retryAfter.ToUniversalTime().ToString("r")); 142 | 143 | /// 144 | /// Creates a object that produces a Request Timeout (408) response. 145 | /// 146 | /// MVC controller instance. 147 | /// The created for the response. 148 | public static RequestTimeoutResult RequestTimeout(this ControllerBase controller) 149 | => new RequestTimeoutResult(); 150 | 151 | /// 152 | /// Creates a object that produces an Request URI Too Long (414) response. 153 | /// 154 | /// MVC controller instance. 155 | /// The created for the response. 156 | public static RequestUriTooLongResult RequestUriTooLong(this ControllerBase controller) 157 | => new RequestUriTooLongResult(); 158 | 159 | /// 160 | /// Creates an object that produces an Unsupported Media Type (415) response. 161 | /// 162 | /// MVC controller instance. 163 | /// The created for the response. 164 | public static UnsupportedMediaTypeResult UnsupportedMediaType(this ControllerBase controller) 165 | => new UnsupportedMediaTypeResult(); 166 | 167 | /// 168 | /// Creates an object that produces an Im a Teapot (418) response. 169 | /// 170 | /// MVC controller instance. 171 | /// The created for the response. 172 | public static ImATeapotResult ImATeapot(this ControllerBase controller) 173 | => new ImATeapotResult(); 174 | 175 | /// 176 | /// Creates an object that produces an Requested Range Not Satisfiable (416) response. 177 | /// 178 | /// MVC controller instance. 179 | /// The created for the response. 180 | public static RequestedRangeNotSatisfiableResult RequestedRangeNotSatisfiable(this ControllerBase controller) 181 | => new RequestedRangeNotSatisfiableResult(); 182 | 183 | /// 184 | /// Creates an object that produces an Requested Range Not Satisfiable (416) response. 185 | /// 186 | /// MVC controller instance. 187 | /// The current length of the selected resource 188 | /// The created for the response. 189 | public static RequestedRangeNotSatisfiableResult RequestedRangeNotSatisfiable(this ControllerBase controller, long? selectedResourceLength) 190 | => new RequestedRangeNotSatisfiableResult(selectedResourceLength); 191 | 192 | /// 193 | /// Creates an object that produces an Expectation Failed (417) response. 194 | /// 195 | /// MVC controller instance. 196 | /// The created for the response. 197 | public static ExpectationFailedResult ExpectationFailed(this ControllerBase controller) 198 | => new ExpectationFailedResult(); 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /test/AspNetCore.Mvc.HttpActionResults.ClientError.Test/ClientErrorControllerBaseExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | namespace AspNetCore.Mvc.HttpActionResults.ClientError.Test 2 | { 3 | using System; 4 | 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.Net.Http.Headers; 8 | 9 | using Xunit; 10 | using Microsoft.Extensions.Primitives; 11 | using System.Threading.Tasks; 12 | 13 | public class ClientErrorControllerBaseExtensionsTest 14 | { 15 | [Fact] 16 | public void PaymentRequiredShouldReturnPaymentRequiredResult() 17 | { 18 | var controller = new HomeController(); 19 | 20 | var result = controller.TestPaymentRequiredResult(); 21 | 22 | Assert.NotNull(result); 23 | Assert.IsAssignableFrom(result); 24 | } 25 | 26 | [Fact] 27 | public void ProxyAuthenticationRequiredShouldReturnProxyAuthenticationRequiredResult() 28 | { 29 | var controller = new HomeController(); 30 | const string fakeHeaderValue = @"Basic realm=""proxy.com"""; 31 | 32 | var result = controller.TestProxyAuthenticationRequiredResult(fakeHeaderValue); 33 | 34 | Assert.NotNull(result); 35 | Assert.IsAssignableFrom(result); 36 | 37 | var castResult = (ProxyAuthenticationRequiredResult)result; 38 | Assert.Equal(fakeHeaderValue, castResult.ProxyAuthenticate); 39 | } 40 | 41 | [Fact] 42 | public void GoneShouldReturnGoneResult() 43 | { 44 | var controller = new HomeController(); 45 | 46 | var result = controller.TestGoneResult(); 47 | 48 | Assert.NotNull(result); 49 | Assert.IsAssignableFrom(result); 50 | } 51 | 52 | [Fact] 53 | public void ConflictShouldReturnConflictResult() 54 | { 55 | var controller = new HomeController(); 56 | 57 | var result = controller.TestConflictResult(); 58 | 59 | Assert.NotNull(result); 60 | Assert.IsAssignableFrom(result); 61 | } 62 | 63 | [Fact] 64 | public void ConflictShouldReturnConflictObjectResult() 65 | { 66 | var controller = new HomeController(); 67 | const string value = "I'm so fake"; 68 | 69 | var result = controller.TestConflictObjectResult(value); 70 | 71 | Assert.NotNull(result); 72 | Assert.IsAssignableFrom(result); 73 | var actionResult = (ConflictObjectResult)result; 74 | Assert.Equal(actionResult.Value, value); 75 | } 76 | 77 | [Fact] 78 | public void NotAcceptableShouldReturnNotAcceptableResult() 79 | { 80 | var controller = new HomeController(); 81 | 82 | var result = controller.TestNotAcceptableResult(); 83 | 84 | Assert.NotNull(result); 85 | Assert.IsAssignableFrom(result); 86 | } 87 | 88 | [Fact] 89 | public void NotAcceptableShouldReturnNotAcceptableObjectResult() 90 | { 91 | var controller = new HomeController(); 92 | const string value = "I'm so fake"; 93 | 94 | var result = controller.TestNotAcceptableObjectResult(value); 95 | 96 | Assert.NotNull(result); 97 | Assert.IsAssignableFrom(result); 98 | var actionResult = (NotAcceptableObjectResult)result; 99 | Assert.Equal(actionResult.Value, value); 100 | } 101 | 102 | [Fact] 103 | public void LengthRequiredShouldReturnLengthRequiredResult() 104 | { 105 | var controller = new HomeController(); 106 | 107 | var result = controller.TestLengthRequiredResult(); 108 | 109 | Assert.NotNull(result); 110 | Assert.IsAssignableFrom(result); 111 | } 112 | 113 | [Fact] 114 | public void RequestEntityTooLargedShouldReturnRequestEntityTooLargeResult() 115 | { 116 | var controller = new HomeController(); 117 | 118 | var result = controller.TestRequestEntityTooLargeResult(); 119 | 120 | Assert.NotNull(result); 121 | Assert.IsAssignableFrom(result); 122 | } 123 | 124 | [Fact] 125 | public void RequestEntityTooLargedWithRetryTimeShouldReturnRequestEntityTooLargeResult() 126 | { 127 | var controller = new HomeController(); 128 | var retryAfterTime = 120L; 129 | 130 | var result = controller.TestRequestEntityTooLargeResult(retryAfterTime); 131 | var actionResult = (RequestEntityTooLargeResult)result; 132 | 133 | Assert.NotNull(result); 134 | Assert.IsAssignableFrom(result); 135 | Assert.Equal(actionResult.RetryAfter, retryAfterTime.ToString()); 136 | } 137 | 138 | [Fact] 139 | public void RequestEntityTooLargedWithRetryDateShouldReturnRequestEntityTooLargeResult() 140 | { 141 | var controller = new HomeController(); 142 | var retryAfterDate = DateTime.Now; 143 | 144 | var result = controller.TestRequestEntityTooLargeResult(retryAfterDate); 145 | var actionResult = (RequestEntityTooLargeResult)result; 146 | 147 | Assert.NotNull(result); 148 | Assert.IsAssignableFrom(result); 149 | Assert.Equal(actionResult.RetryAfter, retryAfterDate.ToUniversalTime().ToString("r")); 150 | } 151 | 152 | [Fact] 153 | public void RequestUriTooLongShouldReturnTestRequestUriTooLongResult() 154 | { 155 | var controller = new HomeController(); 156 | 157 | var result = controller.TestRequestUriTooLongResult(); 158 | 159 | Assert.NotNull(result); 160 | Assert.IsAssignableFrom(result); 161 | } 162 | 163 | [Fact] 164 | public void UnsupportedMediaTypeShouldReturnUnsupportedMediaTypeResult() 165 | { 166 | var controller = new HomeController(); 167 | 168 | var result = controller.TestUnsupportedMediaTypeResult(); 169 | 170 | Assert.NotNull(result); 171 | Assert.IsAssignableFrom(result); 172 | } 173 | 174 | [Fact] 175 | public void RequestTimeoutShouldReturnRequestTimeoutResult() 176 | { 177 | var controller = new HomeController(); 178 | 179 | var result = controller.TestRequestTimeoutResult(); 180 | 181 | Assert.NotNull(result); 182 | Assert.IsAssignableFrom(result); 183 | } 184 | 185 | [Fact] 186 | public void ImATeapotShouldReturnImATeapotResult() 187 | { 188 | var controller = new HomeController(); 189 | 190 | var result = controller.TestImATeapotResult(); 191 | 192 | Assert.NotNull(result); 193 | Assert.IsAssignableFrom(result); 194 | } 195 | 196 | [Fact] 197 | public void RequestedRangeNotSatisfiableShouldReturnRequestedRangeNotSatisfiableResult() 198 | { 199 | var controller = new HomeController(); 200 | 201 | var result = controller.TestRequestedRangeNotSatisfiableResult(); 202 | 203 | Assert.NotNull(result); 204 | Assert.IsAssignableFrom(result); 205 | } 206 | 207 | [Fact] 208 | public void RequestedRangeNotSatisfiableShouldReturnRequestedRangeNotSatisfiableResultWithLengthOfSelectedResource() 209 | { 210 | var controller = new HomeController(); 211 | 212 | long? selectedResourceLength = 1L; 213 | 214 | var result = controller.TestRequestedRangeNotSatisfiableResultWithPassedSelectedResourceLength(selectedResourceLength); 215 | var actionResult = (RequestedRangeNotSatisfiableResult)result; 216 | 217 | Assert.NotNull(result); 218 | Assert.IsAssignableFrom(result); 219 | Assert.Equal(actionResult.SelectedResourceLength, selectedResourceLength); 220 | } 221 | 222 | [Fact] 223 | public void RequestedRangeNotSatisfiableResultShouldThrowOperationCanceledExceptionIfResponseHasContentTypeMultipart() 224 | { 225 | var controller = new HomeController(); 226 | 227 | Assert.ThrowsAsync(typeof(OperationCanceledException), async () => await controller.RequestedRangeNotSatisfiableResultShouldThrowOperationCanceledExceptionIfResponseHasContentTypeMultipart(null)); 228 | } 229 | 230 | [Fact] 231 | public void ExpectationFailedShouldReturnExpectationFailedResult() 232 | { 233 | var controller = new HomeController(); 234 | 235 | var result = controller.TestExpectationFailedResult(); 236 | 237 | Assert.NotNull(result); 238 | Assert.IsAssignableFrom(result); 239 | } 240 | 241 | private class HomeController : ControllerBase 242 | { 243 | public IActionResult TestPaymentRequiredResult() 244 | { 245 | return this.PaymentRequired(); 246 | } 247 | 248 | public IActionResult TestGoneResult() 249 | { 250 | return this.Gone(); 251 | } 252 | 253 | public IActionResult TestNotAcceptableResult() 254 | { 255 | return this.NotAcceptable(); 256 | } 257 | 258 | public IActionResult TestNotAcceptableObjectResult(object data) 259 | { 260 | return this.NotAcceptable(data); 261 | } 262 | 263 | public IActionResult TestConflictResult() 264 | { 265 | return this.Conflict(); 266 | } 267 | 268 | public IActionResult TestConflictObjectResult(object data) 269 | { 270 | return this.Conflict(data); 271 | } 272 | 273 | public IActionResult TestProxyAuthenticationRequiredResult(string proxyAuthenticate) 274 | { 275 | return this.ProxyAuthenticationRequired(proxyAuthenticate); 276 | } 277 | 278 | public IActionResult TestLengthRequiredResult() 279 | { 280 | return this.LengthRequired(); 281 | } 282 | 283 | public IActionResult TestRequestEntityTooLargeResult() 284 | { 285 | return this.RequestEntityTooLarge(); 286 | } 287 | 288 | public IActionResult TestRequestEntityTooLargeResult(long retryAfter) 289 | { 290 | return this.RequestEntityTooLarge(retryAfter); 291 | } 292 | 293 | public IActionResult TestRequestEntityTooLargeResult(DateTime retryAfter) 294 | { 295 | return this.RequestEntityTooLarge(retryAfter); 296 | } 297 | 298 | public IActionResult TestRequestUriTooLongResult() 299 | { 300 | return this.RequestUriTooLong(); 301 | } 302 | 303 | public IActionResult TestUnsupportedMediaTypeResult() 304 | { 305 | return this.UnsupportedMediaType(); 306 | } 307 | 308 | public IActionResult TestRequestTimeoutResult() 309 | { 310 | return this.RequestTimeout(); 311 | } 312 | 313 | public IActionResult TestImATeapotResult() 314 | { 315 | return this.ImATeapot(); 316 | } 317 | 318 | public IActionResult TestRequestedRangeNotSatisfiableResult() 319 | { 320 | return this.RequestedRangeNotSatisfiable(); 321 | } 322 | 323 | public IActionResult TestRequestedRangeNotSatisfiableResultWithPassedSelectedResourceLength(long? selectedResourceLength) 324 | { 325 | return this.RequestedRangeNotSatisfiable(selectedResourceLength); 326 | } 327 | 328 | public Task RequestedRangeNotSatisfiableResultShouldThrowOperationCanceledExceptionIfResponseHasContentTypeMultipart(long? selectedResourceLength) 329 | { 330 | this.ControllerContext = new ControllerContext 331 | { 332 | HttpContext = new DefaultHttpContext() 333 | }; 334 | 335 | this.ControllerContext.HttpContext.Response.Headers.Add(HeaderNames.ContentType, new StringValues("multipart/byteranges")); 336 | 337 | return this.RequestedRangeNotSatisfiable(selectedResourceLength).ExecuteResultAsync(this.ControllerContext); 338 | } 339 | 340 | public IActionResult TestExpectationFailedResult() 341 | { 342 | return this.ExpectationFailed(); 343 | } 344 | } 345 | } 346 | } 347 | --------------------------------------------------------------------------------