Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/http status code to status codes constant #318

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.146" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.155" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.26.0.92422" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions docs/CodeDoc/Atc/IndexExtended.md
Original file line number Diff line number Diff line change
Expand Up @@ -5193,6 +5193,7 @@
- TryParseDate(this string value, out DateTime dateTime)
- TryParseDate(this string value, out DateTime dateTime, CultureInfo cultureInfo, DateTimeStyles dateTimeStyles = None)
- TryParseDateFromIso8601(this string value, out DateTime dateTime)
- TryParseToHttpStatusCode(this string value, out HttpStatusCode httpStatusCode)
- WordCount(this string value)
- XmlDecode(this string xml)
- XmlEncode(this string xml)
Expand Down Expand Up @@ -5389,6 +5390,7 @@
- IsServerError(this HttpStatusCode httpStatusCode)
- IsSuccessful(this HttpStatusCode httpStatusCode)
- ToNormalizedString(this HttpStatusCode httpStatusCode)
- ToStatusCodesConstant(this HttpStatusCode httpStatusCode)

## [System.Reflection](System.Reflection.md)

Expand Down
4 changes: 4 additions & 0 deletions docs/CodeDoc/Atc/System.Net.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
>```csharp
>string ToNormalizedString(this HttpStatusCode httpStatusCode)
>```
#### ToStatusCodesConstant
>```csharp
>string ToStatusCodesConstant(this HttpStatusCode httpStatusCode)
>```
<hr /><div style='text-align: right'><i>Generated by MarkdownCodeDoc version 1.2</i></div>
4 changes: 4 additions & 0 deletions docs/CodeDoc/Atc/System.md
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,10 @@ Extensions for the string class.
><b>Parameters:</b><br>
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`value`&nbsp;&nbsp;-&nbsp;&nbsp;The value.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`dateTime`&nbsp;&nbsp;-&nbsp;&nbsp;The date time.<br />
#### TryParseToHttpStatusCode
>```csharp
>bool TryParseToHttpStatusCode(this string value, out HttpStatusCode httpStatusCode)
>```
#### WordCount
>```csharp
>int WordCount(this string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions sample/Demo.Atc.Dotnet.Cli/Demo.Atc.Dotnet.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Atc.Console.Spectre/Atc.Console.Spectre.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Atc.Rest.Extended/Atc.Rest.Extended.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Rest.HealthChecks/Atc.Rest.HealthChecks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Atc.XUnit/Atc.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPPlus" Version="7.1.0" />
<PackageReference Include="EPPlus" Version="7.1.3" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.2.0.7535" />
<PackageReference Include="Mono.Reflection" Version="2.0.0">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit" Version="2.8.1" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 14 additions & 4 deletions src/Atc/Extensions/HttpStatusCodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ namespace System.Net;

public static class HttpStatusCodeExtensions
{
public static string ToNormalizedString(this HttpStatusCode httpStatusCode)
{
return httpStatusCode switch
public static string ToNormalizedString(
this HttpStatusCode httpStatusCode)
=> httpStatusCode switch
{
HttpStatusCode.OK => "Ok",
HttpStatusCode.IMUsed => "ImUsed",
_ => httpStatusCode.ToString(),
};
}

public static string ToStatusCodesConstant(
this HttpStatusCode httpStatusCode)
=> httpStatusCode switch
{
HttpStatusCode.NonAuthoritativeInformation => "Status203NonAuthoritative",
HttpStatusCode.Unused => "Status306SwitchProxy",
HttpStatusCode.RedirectKeepVerb => "Status307TemporaryRedirect",
HttpStatusCode.HttpVersionNotSupported => "Status505HttpVersionNotsupported",
_ => $"Status{(int)httpStatusCode}{httpStatusCode}",
};

public static bool IsInformational(this HttpStatusCode httpStatusCode)
=> (int)httpStatusCode >= 100 && (int)httpStatusCode < 200;
Expand Down
6 changes: 6 additions & 0 deletions src/Atc/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,12 @@ public static Stream ToStream(this string value)
return stream;
}

public static bool TryParseToHttpStatusCode(
this string value,
out HttpStatusCode httpStatusCode)
=> Enum<HttpStatusCode>.TryParse(value, false, out httpStatusCode) &&
!NumberHelper.IsInt(httpStatusCode.ToString());

/// <summary>
/// Gets the value between less and greater than chars if exist.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.DotNet.Tests/Atc.DotNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.OpenApi.Tests/Atc.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.Rest.Extended.Tests/Atc.Rest.Extended.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.Rest.Tests/Atc.Rest.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

<ItemGroup>
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions test/Atc.Tests/Atc.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
64 changes: 64 additions & 0 deletions test/Atc.Tests/Extensions/HttpStatusCodeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,70 @@ public class HttpStatusCodeExtensionsTests
public void ToNormalizedString(string expected, HttpStatusCode httpStatusCode)
=> Assert.Equal(expected, httpStatusCode.ToNormalizedString());

[Theory]
[InlineData(HttpStatusCode.Continue, "Status100Continue")]
[InlineData(HttpStatusCode.SwitchingProtocols, "Status101SwitchingProtocols")]
[InlineData(HttpStatusCode.Processing, "Status102Processing")]
[InlineData(HttpStatusCode.OK, "Status200OK")]
[InlineData(HttpStatusCode.Created, "Status201Created")]
[InlineData(HttpStatusCode.Accepted, "Status202Accepted")]
[InlineData(HttpStatusCode.NonAuthoritativeInformation, "Status203NonAuthoritative")]
[InlineData(HttpStatusCode.NoContent, "Status204NoContent")]
[InlineData(HttpStatusCode.ResetContent, "Status205ResetContent")]
[InlineData(HttpStatusCode.PartialContent, "Status206PartialContent")]
[InlineData(HttpStatusCode.MultiStatus, "Status207MultiStatus")]
[InlineData(HttpStatusCode.AlreadyReported, "Status208AlreadyReported")]
[InlineData(HttpStatusCode.IMUsed, "Status226IMUsed")]
[InlineData(HttpStatusCode.MultipleChoices, "Status300MultipleChoices")]
[InlineData(HttpStatusCode.MovedPermanently, "Status301MovedPermanently")]
[InlineData(HttpStatusCode.Found, "Status302Found")]
[InlineData(HttpStatusCode.SeeOther, "Status303SeeOther")]
[InlineData(HttpStatusCode.NotModified, "Status304NotModified")]
[InlineData(HttpStatusCode.UseProxy, "Status305UseProxy")]
[InlineData(HttpStatusCode.Unused, "Status306SwitchProxy")]
[InlineData(HttpStatusCode.TemporaryRedirect, "Status307TemporaryRedirect")]
[InlineData(HttpStatusCode.PermanentRedirect, "Status308PermanentRedirect")]
[InlineData(HttpStatusCode.BadRequest, "Status400BadRequest")]
[InlineData(HttpStatusCode.Unauthorized, "Status401Unauthorized")]
[InlineData(HttpStatusCode.PaymentRequired, "Status402PaymentRequired")]
[InlineData(HttpStatusCode.Forbidden, "Status403Forbidden")]
[InlineData(HttpStatusCode.NotFound, "Status404NotFound")]
[InlineData(HttpStatusCode.MethodNotAllowed, "Status405MethodNotAllowed")]
[InlineData(HttpStatusCode.NotAcceptable, "Status406NotAcceptable")]
[InlineData(HttpStatusCode.ProxyAuthenticationRequired, "Status407ProxyAuthenticationRequired")]
[InlineData(HttpStatusCode.RequestTimeout, "Status408RequestTimeout")]
[InlineData(HttpStatusCode.Conflict, "Status409Conflict")]
[InlineData(HttpStatusCode.Gone, "Status410Gone")]
[InlineData(HttpStatusCode.LengthRequired, "Status411LengthRequired")]
[InlineData(HttpStatusCode.PreconditionFailed, "Status412PreconditionFailed")]
[InlineData(HttpStatusCode.RequestEntityTooLarge, "Status413RequestEntityTooLarge")]
[InlineData(HttpStatusCode.RequestUriTooLong, "Status414RequestUriTooLong")]
[InlineData(HttpStatusCode.UnsupportedMediaType, "Status415UnsupportedMediaType")]
[InlineData(HttpStatusCode.RequestedRangeNotSatisfiable, "Status416RequestedRangeNotSatisfiable")]
[InlineData(HttpStatusCode.ExpectationFailed, "Status417ExpectationFailed")]
[InlineData(HttpStatusCode.MisdirectedRequest, "Status421MisdirectedRequest")]
[InlineData(HttpStatusCode.UnprocessableEntity, "Status422UnprocessableEntity")]
[InlineData(HttpStatusCode.Locked, "Status423Locked")]
[InlineData(HttpStatusCode.FailedDependency, "Status424FailedDependency")]
[InlineData(HttpStatusCode.UpgradeRequired, "Status426UpgradeRequired")]
[InlineData(HttpStatusCode.PreconditionRequired, "Status428PreconditionRequired")]
[InlineData(HttpStatusCode.TooManyRequests, "Status429TooManyRequests")]
[InlineData(HttpStatusCode.RequestHeaderFieldsTooLarge, "Status431RequestHeaderFieldsTooLarge")]
[InlineData(HttpStatusCode.UnavailableForLegalReasons, "Status451UnavailableForLegalReasons")]
[InlineData(HttpStatusCode.InternalServerError, "Status500InternalServerError")]
[InlineData(HttpStatusCode.NotImplemented, "Status501NotImplemented")]
[InlineData(HttpStatusCode.BadGateway, "Status502BadGateway")]
[InlineData(HttpStatusCode.ServiceUnavailable, "Status503ServiceUnavailable")]
[InlineData(HttpStatusCode.GatewayTimeout, "Status504GatewayTimeout")]
[InlineData(HttpStatusCode.HttpVersionNotSupported, "Status505HttpVersionNotsupported")]
[InlineData(HttpStatusCode.VariantAlsoNegotiates, "Status506VariantAlsoNegotiates")]
[InlineData(HttpStatusCode.InsufficientStorage, "Status507InsufficientStorage")]
[InlineData(HttpStatusCode.LoopDetected, "Status508LoopDetected")]
[InlineData(HttpStatusCode.NotExtended, "Status510NotExtended")]
[InlineData(HttpStatusCode.NetworkAuthenticationRequired, "Status511NetworkAuthenticationRequired")]
public void ToStatusCodesConstant(HttpStatusCode httpStatusCode, string expected)
=> Assert.Equal(expected, httpStatusCode.ToStatusCodesConstant());

[Theory]
[InlineData(true, HttpStatusCode.Continue)]
[InlineData(false, HttpStatusCode.OK)]
Expand Down
23 changes: 23 additions & 0 deletions test/Atc.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,27 @@ public void ToStreamFromBase64()
// Assert
Assert.NotNull(actual);
}

[Theory]
[InlineData("OK", true, (int)HttpStatusCode.OK)]
[InlineData("NotFound", true, (int)HttpStatusCode.NotFound)]
[InlineData("BadRequest", true, (int)HttpStatusCode.BadRequest)]
[InlineData("InternalServerError", true, (int)HttpStatusCode.InternalServerError)]
[InlineData("InvalidStatusCode", false, 0)]
[InlineData("", false, 0)]
public void TryParseToHttpStatusCode(
string input,
bool expectedResult,
int expectedStatusCodeAsInt)
{
// Arrange
var expectedStatusCode = (HttpStatusCode)expectedStatusCodeAsInt;

// Act
var result = input.TryParseToHttpStatusCode(out var httpStatusCode);

// Assert
Assert.Equal(expectedResult, result);
Assert.Equal(expectedStatusCode, httpStatusCode);
}
}
Loading