Skip to content

Commit

Permalink
Merge branch 'main' into fix-issue196
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis authored Sep 11, 2024
2 parents ddbb6a9 + 67787ee commit 9535f03
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Ardalis.ApiEndpoints" Version="4.0.1" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="Ardalis.ApiEndpoints" Version="4.1.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.10.0" />
<PackageVersion Include="FluentValidation" Version="11.5.1" />
<PackageVersion Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.3" />
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.3" />
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.8" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.5.0" />
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.4" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Runtime" Version="4.3.1" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.8)
strscan (>= 3.0.9)
rexml (3.3.6)
strscan
rouge (4.1.3)
safe_yaml (1.0.5)
sass-embedded (1.67.0-x86_64-linux-gnu)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,7 +11,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Ardalis.Result.AspNetCore\Ardalis.Result.AspNetCore.csproj">
<SetTargetFramework>TargetFramework=net7.0</SetTargetFramework>
<SetTargetFramework>TargetFramework=net8.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\Ardalis.Result.Sample.Core\Ardalis.Result.Sample.Core.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Testing;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Ardalis.Result.Sample.Core.DTOs;
using Xunit;
using System.Text.Json;

namespace Ardalis.Result.SampleWeb.FunctionalTests;

Expand Down Expand Up @@ -34,15 +34,15 @@ public async Task ReturnsConflictGivenExistPerson(string route)
FirstName = "John",
LastName = "Smith"
};
var json = JsonConvert.SerializeObject(createPersonRequestDto);
var json = JsonSerializer.Serialize(createPersonRequestDto);
var response = await _client.PostAsync(route, new StringContent(json, Encoding.UTF8, "application/json"));

Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();

var problemDetails = JsonConvert.DeserializeObject<ProblemDetails>(stringResponse);
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(stringResponse);

Assert.Contains("There was a conflict.", problemDetails.Title);
Assert.Contains("There was a conflict.", problemDetails!.Title);
Assert.Contains("Next error(s) occurred:* Person (John Smith) already exists in the system", problemDetails.Detail);
Assert.Equal(409, problemDetails.Status);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Testing;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Ardalis.Result.Sample.Core.DTOs;
using Xunit;
using System.Text.Json;

namespace Ardalis.Result.SampleWeb.FunctionalTests;

Expand Down Expand Up @@ -48,9 +48,9 @@ public async Task ReturnsNotFoundGivenUnknownId(string route)
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();

var problemDetails = JsonConvert.DeserializeObject<ProblemDetails>(stringResponse);
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(stringResponse);

Assert.Contains("Resource not found.", problemDetails.Title);
Assert.Contains("Resource not found.", problemDetails!.Title);
Assert.Contains("Person with id 2 Not Found", problemDetails.Detail);
Assert.Equal(404, problemDetails.Status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using Ardalis.Result.Sample.Core.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Testing;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -30,10 +30,10 @@ public async Task Returns400BadRequestNot500()

Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();
var problemDetails = JsonConvert.DeserializeObject<ProblemDetails>(stringResponse);
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(stringResponse);

Assert.Equal("One or more validation errors occurred.", problemDetails?.Title);
Assert.Equal(400, problemDetails.Status);
Assert.Equal(400, problemDetails!.Status);
}
}

Expand All @@ -58,7 +58,7 @@ public async Task ReturnsOkWithValueGivenValidPostalCode(string route)
response.EnsureSuccessStatusCode();

var stringResponse = await response.Content.ReadAsStringAsync();
var forecasts = JsonConvert.DeserializeObject<List<WeatherForecast>>(stringResponse);
var forecasts = JsonSerializer.Deserialize<List<WeatherForecast>>(stringResponse);

Assert.Equal("Freezing", forecasts?.First()?.Summary);
}
Expand All @@ -74,9 +74,9 @@ public async Task ReturnsBadRequestGivenNoPostalCode(string route)
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();

var validationProblemDetails = JsonConvert.DeserializeObject<ValidationProblemDetails>(stringResponse);
var validationProblemDetails = JsonSerializer.Deserialize<ValidationProblemDetails>(stringResponse);

Assert.Contains(validationProblemDetails.Errors, d => d.Key == nameof(ForecastRequestDto.PostalCode));
Assert.Contains(validationProblemDetails!.Errors, d => d.Key == nameof(ForecastRequestDto.PostalCode));
Assert.Equal(400, validationProblemDetails.Status);
}

Expand All @@ -91,9 +91,9 @@ public async Task ReturnsNotFoundGivenNonExistentPostalCode(string route)
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();

var problemDetails = JsonConvert.DeserializeObject<ProblemDetails>(stringResponse);
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(stringResponse);

Assert.Equal("Resource not found.", problemDetails.Title);
Assert.Equal("Resource not found.", problemDetails!.Title);
Assert.Equal(404, problemDetails.Status);
}

Expand All @@ -108,9 +108,9 @@ public async Task ReturnsBadRequestGivenPostalCodeTooLong(string route)
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();

var validationProblemDetails = JsonConvert.DeserializeObject<ValidationProblemDetails>(stringResponse);
var validationProblemDetails = JsonSerializer.Deserialize<ValidationProblemDetails>(stringResponse);

Assert.Contains(validationProblemDetails.Errors, d => d.Key == nameof(ForecastRequestDto.PostalCode));
Assert.Contains(validationProblemDetails!.Errors, d => d.Key == nameof(ForecastRequestDto.PostalCode));
Assert.Contains(validationProblemDetails.Errors[nameof(ForecastRequestDto.PostalCode)], e => e.Equals("PostalCode cannot exceed 10 characters.", System.StringComparison.OrdinalIgnoreCase));
Assert.Equal(400, validationProblemDetails.Status);
}
Expand All @@ -126,15 +126,15 @@ public async Task ReturnsConflictGivenNonExistentPostalCode(string route)
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
var stringResponse = await response.Content.ReadAsStringAsync();

var problemDetails = JsonConvert.DeserializeObject<ProblemDetails>(stringResponse);
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(stringResponse);

Assert.Equal("There was a conflict.", problemDetails.Title);
Assert.Equal("There was a conflict.", problemDetails!.Title);
Assert.Equal(409, problemDetails.Status);
}

private async Task<HttpResponseMessage> PostDTOAndGetResponse(ForecastRequestDto dto, string route)
{
var jsonContent = new StringContent(JsonConvert.SerializeObject(dto),
var jsonContent = new StringContent(JsonSerializer.Serialize(dto),
Encoding.Default, "application/json");
return await _client.PostAsync(route, jsonContent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
namespace Ardalis.Result.AspNetCore;

public static partial class ResultExtensions
Expand Down
2 changes: 1 addition & 1 deletion src/Ardalis.Result.AspNetCore/ResultStatusMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ResultStatusMap AddDefaultMap()
/// Allows to override default status code for specific Http Methods
/// </summary>
/// <param name="status">Result Status to map.</param>
/// <param name="defaultStatusCode">Default Status Code.<param>
/// <param name="defaultStatusCode">Default Status Code.</param>
/// <param name="configure">A <see cref="Action"/> to configure Status Codes for specific Http Methods.</param>
public ResultStatusMap For(ResultStatus status, HttpStatusCode defaultStatusCode, Action<ResultStatusOptions> configure)
{
Expand Down
13 changes: 7 additions & 6 deletions src/Ardalis.Result/Result.Void.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public static Result Success()
/// Represents a successful operation without return type
/// </summary>
/// <param name="successMessage">Sets the SuccessMessage property</param>
/// <returns>A Result></returns>
/// <returns>A Result</returns>
public static Result SuccessWithMessage(string successMessage)
{
return new Result() { SuccessMessage = successMessage };
return new Result { SuccessMessage = successMessage };
}

/// <summary>
Expand Down Expand Up @@ -69,8 +69,8 @@ public static Result<T> Success<T>(T value, string successMessage)
/// A single error message may be provided and will be exposed via the Errors property.
/// </summary>
/// <param name="errorMessage"></param>
/// <returns></returns>
public static Result Error(string errorMessage)
/// <returns>A Result</returns>
public new static Result Error(string errorMessage)
{
return new Result(ResultStatus.Error) { Errors = new[] { errorMessage } };
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public static Result Error(string errorMessage)
/// such as an edit conflict between multiple concurrent updates.
/// See also HTTP 409 Conflict: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
/// </summary>
/// <returns>A Result<typeparamref name="T"/></returns>
/// <returns>A Result</returns>
public new static Result Conflict()
{
return new Result(ResultStatus.Conflict);
Expand All @@ -186,7 +186,7 @@ public static Result Error(string errorMessage)
/// See also HTTP 409 Conflict: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
/// </summary>
/// <param name="errorMessages">A list of string error messages.</param>
/// <returns>A Result<typeparamref name="T"/></returns>
/// <returns>A Result</returns>
public new static Result Conflict(params string[] errorMessages)
{
return new Result(ResultStatus.Conflict) { Errors = errorMessages };
Expand All @@ -204,6 +204,7 @@ public static Result Error(string errorMessage)
return new Result(ResultStatus.Unavailable) { Errors = errorMessages };
}

/// <summary>
/// Represents a critical error that occurred during the execution of the service.
/// Everything provided by the user was valid, but the service was unable to complete due to an exception.
/// See also HTTP 500 Internal Server Error: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_server_errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER

using Ardalis.Result.AspNetCore;
using Xunit;
Expand Down

0 comments on commit 9535f03

Please sign in to comment.