Skip to content

Commit

Permalink
Update to .NET 8 and Functional DDD 2.0.0-alpha.33 (#24)
Browse files Browse the repository at this point in the history
* Update to .net 8
* Update to Func DDD 2.0.0-alpha.33
  • Loading branch information
xavierjohn authored Apr 17, 2024
1 parent 17b261e commit bb08967
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 77 deletions.
24 changes: 12 additions & 12 deletions Api/tests/2022-12-21/CreateMenuRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void ToMenuItemCommand_Required_parameters_are_validated(string field)
public void ToCreateMenuCommand_Multiple_parameters_are_validated()
{
// Arrange
ValidationError.ModelError badName = new("Name cannot be empty.", "name");
ValidationError.ModelError badDescription = new("Description cannot be empty.", "description");
ValidationError.FieldDetails badName = new("name", ["Name cannot be empty."]);
ValidationError.FieldDetails badDescription = new("description", ["Description cannot be empty."]);

CreateMenuRequest request = new(string.Empty, string.Empty, new List<MenuSectionRequest>());

Expand All @@ -81,16 +81,16 @@ public void ToCreateMenuCommand_Multiple_parameters_are_validated()
result.IsFailure.Should().BeTrue();
result.Error.Should().BeOfType(typeof(ValidationError));
ValidationError validationError = (ValidationError)result.Error;
validationError.Errors[0].Should().Be(badName);
validationError.Errors[1].Should().Be(badDescription);
validationError.Errors[0].Should().BeEquivalentTo(badName);
validationError.Errors[1].Should().BeEquivalentTo(badDescription);
}

[Fact]
public void ToMenuSectionCommand_Multiple_parameters_are_validated()
{
// Arrange
ValidationError.ModelError badName = new("Name cannot be empty.", "name");
ValidationError.ModelError badDescription = new("Description cannot be empty.", "description");
ValidationError.FieldDetails badName = new("name", ["Name cannot be empty."]);
ValidationError.FieldDetails badDescription = new("description", ["Description cannot be empty."]);

MenuSectionRequest request = new(string.Empty, string.Empty, new List<MenuItemRequest>());

Expand All @@ -101,16 +101,16 @@ public void ToMenuSectionCommand_Multiple_parameters_are_validated()
result.IsFailure.Should().BeTrue();
result.Error.Should().BeOfType(typeof(ValidationError));
ValidationError validationError = (ValidationError)result.Error;
validationError.Errors[0].Should().Be(badName);
validationError.Errors[1].Should().Be(badDescription);
validationError.Errors[0].Should().BeEquivalentTo(badName);
validationError.Errors[1].Should().BeEquivalentTo(badDescription);
}

[Fact]
public void ToMenuItemCommand_Multiple_parameters_are_validated()
{
// Arrange
ValidationError.ModelError badName = new("Name cannot be empty.", "name");
ValidationError.ModelError badDescription = new("Description cannot be empty.", "description");
ValidationError.FieldDetails badName = new("name", ["Name cannot be empty."]);
ValidationError.FieldDetails badDescription = new("description", ["Description cannot be empty."]);

MenuItemRequest request = new(string.Empty, string.Empty);

Expand All @@ -121,8 +121,8 @@ public void ToMenuItemCommand_Multiple_parameters_are_validated()
result.IsFailure.Should().BeTrue();
result.Error.Should().BeOfType(typeof(ValidationError));
ValidationError validationError = (ValidationError)result.Error;
validationError.Errors[0].Should().Be(badName);
validationError.Errors[1].Should().Be(badDescription);
validationError.Errors[0].Should().BeEquivalentTo(badName);
validationError.Errors[1].Should().BeEquivalentTo(badDescription);
}

[Fact]
Expand Down
8 changes: 1 addition & 7 deletions Api/tests/BuberDinner.Api.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Xunit.Priority" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\BuberDinner.Api.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions Api/tests/Neutral/RegisterRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void Required_parameters_are_validated(string field)
public void Multiple_parameters_are_validated()
{
// Arrange
var badFirstName = new ValidationError.ModelError("First Name cannot be empty.", "firstName");
var badEmail = new ValidationError.ModelError("Email address is not valid.", "email");
var badFirstName = new ValidationError.FieldDetails("firstName", ["First Name cannot be empty."]);
var badEmail = new ValidationError.FieldDetails("email", ["Email address is not valid."]);

var request = new RegisterRequest("id", string.Empty, "John", "bad email", "password");

Expand All @@ -46,8 +46,8 @@ public void Multiple_parameters_are_validated()
result.IsFailure.Should().BeTrue();
result.Error.Should().BeOfType(typeof(ValidationError));
var validationError = (ValidationError)result.Error;
validationError.Errors[0].Should().Be(badFirstName);
validationError.Errors[1].Should().Be(badEmail);
validationError.Errors[0].Should().BeEquivalentTo(badFirstName);
validationError.Errors[1].Should().BeEquivalentTo(badEmail);
}

[Fact]
Expand Down
6 changes: 0 additions & 6 deletions Application/tests/BuberDinner.Application.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,5 @@
</ItemGroup>


<ItemGroup>
<PackageReference Update="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<SolutionDir Condition=" '$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined if not building a solution or within Visual Studio*' ">$(MSBuildThisFileDirectory)</SolutionDir>
<IsTestProject>$(MSBuildProjectName.EndsWith('.Tests'))</IsTestProject>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
30 changes: 15 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project>
<PropertyGroup>
<FunctionalDddVersion>1.1.1</FunctionalDddVersion>
<FunctionalDddVersion>2.0.0-alpha.33</FunctionalDddVersion>
</PropertyGroup>
<!-- Runtime -->
<ItemGroup>
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.1.0" />
<PackageVersion Include="Azure.Identity" Version="1.10.3" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
<PackageVersion Include="Azure.Identity" Version="1.11.0" />
<PackageVersion Include="FluentValidation" Version="11.3.0" />
<PackageVersion Include="FunctionalDdd.Asp" Version="$(FunctionalDddVersion)" />
<PackageVersion Include="FunctionalDdd.CommonValueObjectGenerator" Version="$(FunctionalDddVersion)" />
Expand All @@ -17,27 +17,27 @@
<PackageVersion Include="Mapster.DependencyInjection" Version="1.0.1" />
<PackageVersion Include="Mediator.Abstractions" Version="2.1.7" />
<PackageVersion Include="Mediator.SourceGenerator" Version="2.1.7" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.39.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
</ItemGroup>
<!-- Test -->
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="Xunit.DependencyInjection" Version="8.9.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="xunit" Version="2.7.1" />
<PackageVersion Include="Xunit.DependencyInjection" Version="9.1.0" />
<PackageVersion Include="Xunit.Priority" Version="1.1.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.8" />
<PackageVersion Include="xunit.categories" Version="2.0.8" />
</ItemGroup>
</Project>
4 changes: 1 addition & 3 deletions Domain/src/Common/Errors/Errors.Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ public partial class Errors
{
public static class Authentication
{
public static Error InvalidCredentials => Error.Unauthorized(
code: "Authentication.InvalidCredentials",
message: "Invalid credentials.");
public static Error InvalidCredentials => new UnauthorizedError("Invalid credentials.", "Authentication.InvalidCredentials");
}

}
8 changes: 2 additions & 6 deletions Domain/src/Common/Errors/Errors.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ public partial class Errors
{
public static class User
{
public static Error AlreadyExists(string id) => Error.Conflict(
code: "User.DuplicateUserId",
message: $"User with this id {id} already exists.");
public static Error AlreadyExists(string id) => new ConflictError("User Id already exists.", "User.DuplicateUserId", id);

public static Error DoesNotExist(string id) => Error.NotFound(
code: "User.DoesNotExist",
message: $"User with this id {id} does not exist.");
public static Error DoesNotExist(string id) => new NotFoundError("User.DoesNotExist", "User Id does not exist.", id);
}
}
6 changes: 3 additions & 3 deletions Domain/src/User/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ private User(UserId id, FirstName firstName, LastName lastName, EmailAddress ema
static readonly InlineValidator<User> s_validator = new()
{
v => v.RuleFor(x => x.Id).NotNull(),
v => v.RuleFor(x => x.FirstName).NotEmpty(),
v => v.RuleFor(x => x.LastName).NotEmpty(),
v => v.RuleFor(x => x.FirstName).NotNull(),
v => v.RuleFor(x => x.LastName).NotNull(),
v => v.RuleFor(x => x.Email).NotNull(),
v => v.RuleFor(x => x.Password).NotEmpty()
v => v.RuleFor(x => x.Password).NotNull()
};
}
8 changes: 1 addition & 7 deletions Domain/tests/BuberDinner.Domain.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\src\BuberDinner.Domain.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions Domain/tests/MenuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void MenuItem_Required_parameters_are_validated(string field)
menuItemResult.IsFailure.Should().BeTrue();
menuItemResult.Error.Should().BeOfType<ValidationError>();
ValidationError validationError = (ValidationError)menuItemResult.Error;
validationError.Errors[0].Message.Should().EndWith($" must not be empty."); ;
validationError.Errors[0].Details[0].Should().EndWith($" must not be empty."); ;
}

[Theory]
Expand Down Expand Up @@ -68,7 +68,7 @@ public void MenuSection_Required_parameters_are_validated(string field)
menuSectionResult.IsFailure.Should().BeTrue();
menuSectionResult.Error.Should().BeOfType<ValidationError>();
ValidationError validationError = (ValidationError)menuSectionResult.Error;
validationError.Errors[0].Message.Should().EndWith($" must not be empty."); ;
validationError.Errors[0].Details[0].Should().EndWith($" must not be empty."); ;
}

[Theory]
Expand Down Expand Up @@ -122,6 +122,6 @@ public void Menu_Required_parameters_are_validated(string field)
menuResult.IsFailure.Should().BeTrue();
menuResult.Error.Should().BeOfType<ValidationError>();
ValidationError validationError = (ValidationError)menuResult.Error;
validationError.Errors[0].Message.Should().EndWith($" must not be empty."); ;
validationError.Errors[0].Details[0].Should().EndWith($" must not be empty."); ;
}
}
2 changes: 1 addition & 1 deletion Domain/tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Required_parameters_are_validated(string field)
userResult.IsFailure.Should().BeTrue();
userResult.Error.Should().BeOfType<ValidationError>();
var validationError = (ValidationError)userResult.Error;
validationError.Errors[0].Message.Should().EndWith($" must not be empty."); ;
validationError.Errors[0].Details[0].Should().EndWith($" must not be empty."); ;
}

[Fact]
Expand Down
8 changes: 1 addition & 7 deletions Infrastructure/tests/BuberDinner.Infrastructure.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="xunit.categories" />
<PackageReference Include="Xunit.Priority" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\BuberDinner.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.202",
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"Microsoft.Build.Traversal": "3.2.0"
"Microsoft.Build.Traversal": "4.1.0"
}
}

0 comments on commit bb08967

Please sign in to comment.