Skip to content

Commit

Permalink
Update packages
Browse files Browse the repository at this point in the history
Fix broken net7 test
  • Loading branch information
ardalis committed Sep 11, 2024
1 parent 0a8ba20 commit 67787ee
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 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
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
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 67787ee

Please sign in to comment.