Skip to content
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
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ jobs:
working-directory: ./backend

- name: Test with the dotnet CLI
run: dotnet test --project MenuApi.Tests/MenuApi.Tests.csproj --configuration Release --no-build
run: |
Get-ChildItem -Recurse -Filter "*.Tests.csproj" | Where-Object { $_.FullName -notlike "*Integration*" } | ForEach-Object {
dotnet test $_.FullName --configuration Release --no-build
}
shell: pwsh
working-directory: ./backend


Expand Down
16 changes: 8 additions & 8 deletions backend/MenuApi.Integration.Tests/Factory/ApiAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ public ApiAuthentication()
.AddUserSecrets<ApiTestFixture>() // User secrets for local development.
.Build();

config = Configuration.GetRequiredSection("Parameters").Get<TestParameters>();
config = Configuration.GetRequiredSection("Parameters").Get<TestParameters>()!;
}


public class Auth0AuthenticationRequest
{
public string client_id { get; set; }
public string client_secret { get; set; }
public string audience { get; set; }
public string grant_type { get; set; }
public string client_id { get; set; } = null!;
public string client_secret { get; set; } = null!;
public string audience { get; set; } = null!;
public string grant_type { get; set; } = null!;
}



public class Auth0AuthenticationResponse
{
public string access_token { get; set; }
public string token_type { get; set; }
public string access_token { get; set; } = null!;
public string token_type { get; set; } = null!;
}


Expand All @@ -58,6 +58,6 @@ public async Task<AuthenticationHeaderValue> GetAuthenticationHeaderValue()
authResponse.EnsureSuccessStatusCode();
var responseBody = await authResponse.Content.ReadFromJsonAsync<Auth0AuthenticationResponse>();

return new AuthenticationHeaderValue(responseBody.token_type, responseBody.access_token);
return new AuthenticationHeaderValue(responseBody!.token_type, responseBody.access_token);
}
}
8 changes: 4 additions & 4 deletions backend/MenuApi.Integration.Tests/Factory/ApiTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace MenuApi.Integration.Tests.Factory;

public class ApiTestFixture : IAsyncLifetime
{
public DistributedApplication app { get; private set; }
private IDistributedApplicationTestingBuilder appHost;
private AuthenticationHeaderValue cachedAuthHeader;
public DistributedApplication app { get; private set; } = null!;
private IDistributedApplicationTestingBuilder appHost = null!;
private AuthenticationHeaderValue cachedAuthHeader = null!;

public async Task<HttpClient> GetHttpClient()
{
Expand Down Expand Up @@ -48,7 +48,7 @@ async ValueTask IAsyncLifetime.InitializeAsync()
// Retry app startup to handle Docker daemon health checks in CI environments
const int maxRetries = 3;
const int delayMs = 2000;
Exception lastException = null;
Exception? lastException = null;
for (int attempt = 1; attempt <= maxRetries; attempt++)
{
try
Expand Down
8 changes: 4 additions & 4 deletions backend/MenuApi.Integration.Tests/Factory/TestParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
internal class TestParameters
{
public string Auth0TestClientId { get; set; }
public string Auth0TestClientSecret { get; set; }
public string Auth0Audience { get; set; }
public string Auth0Domain { get; set; }
public string Auth0TestClientId { get; set; } = null!;
public string Auth0TestClientSecret { get; set; } = null!;
public string Auth0Audience { get; set; } = null!;
public string Auth0Domain { get; set; } = null!;
}
}
14 changes: 7 additions & 7 deletions backend/MenuApi.Integration.Tests/IngredientIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,24 @@ private class Ingredient
{
#pragma warning disable S1144 // Unused private types or members should be removed
public int Id { get; set; }
public string Name { get; set; }
public List<IngredientUnit> Units { get; set; }
public string Name { get; set; } = null!;
public List<IngredientUnit> Units { get; set; } = null!;
#pragma warning restore S1144 // Unused private types or members should be removed
}

public class IngredientUnit
{
#pragma warning disable S1144 // Unused private types or members should be removed
public string Name { get; set; }
public string Abbreviation { get; set; }
public string Type { get; set; }
public string Name { get; set; } = null!;
public string? Abbreviation { get; set; }
public string Type { get; set; } = null!;
#pragma warning restore S1144 // Unused private types or members should be removed
}

public class NewIngredient
{
public string Name { get; set; }
public List<int> UnitIds { get; set; }
public string Name { get; set; } = null!;
public List<int> UnitIds { get; set; } = null!;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<UserSecretsId>ea3aa4c7-9b32-4485-a5b2-fb1cb0def863</UserSecretsId>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>xUnit1051</NoWarn>
</PropertyGroup>

Expand Down
10 changes: 5 additions & 5 deletions backend/MenuApi.Integration.Tests/RecipeIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private static (int Id, string Name) GetRecipeFromJson(JsonDocument doc)
var rootElement = doc.RootElement;
return (
rootElement.GetProperty("id").GetInt32(),
rootElement.GetProperty("name").GetString()
rootElement.GetProperty("name").GetString()!
);
}

Expand All @@ -227,22 +227,22 @@ private class Recipe
#pragma warning disable S1144 // Unused private types or members should be removed
public int Id { get; set; }

public string Name { get; set; }
public string Name { get; set; } = null!;
#pragma warning restore S1144 // Unused private types or members should be removed
}

public class NewRecipe
{
public List<RecipeIngredient> Ingredients { get; set; } = [];

public string Name { get; set; }
public string Name { get; set; } = null!;
}

public class RecipeIngredient
{
public string Name { get; set; }
public string Name { get; set; } = null!;

public string Unit { get; set; }
public string Unit { get; set; } = null!;

public decimal Amount { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,24 +351,24 @@ private async Task PostIngredientAsync(HttpClient client, string name, List<int>
private class NewIngredient
{
#pragma warning disable S1144 // Unused private types or members should be removed
public string Name { get; set; }
public List<int> UnitIds { get; set; }
public string Name { get; set; } = null!;
public List<int> UnitIds { get; set; } = null!;
#pragma warning restore S1144 // Unused private types or members should be removed
}

public class NewRecipe
{
#pragma warning disable S1144 // Unused private types or members should be removed
public string Name { get; set; }
public string Name { get; set; } = null!;
public List<RecipeIngredient> Ingredients { get; set; } = [];
#pragma warning restore S1144 // Unused private types or members should be removed
}

public class RecipeIngredient
{
#pragma warning disable S1144 // Unused private types or members should be removed
public string Name { get; set; }
public string Unit { get; set; }
public string Name { get; set; } = null!;
public string Unit { get; set; } = null!;
public decimal Amount { get; set; }
#pragma warning restore S1144 // Unused private types or members should be removed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@ private async Task PostIngredientAsync(HttpClient client, string name)
public class NewRecipe
{
public List<RecipeIngredient> Ingredients { get; set; } = [];
public string Name { get; set; }
public string Name { get; set; } = null!;
}

public class RecipeIngredient
{
public string Name { get; set; }
public string Unit { get; set; }
public string Name { get; set; } = null!;
public string Unit { get; set; } = null!;
public decimal Amount { get; set; }
}

public class NewIngredient
{
public string Name { get; set; }
public string Name { get; set; } = null!;
public List<int> UnitIds { get; set; } = [];
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/MenuApi.Tests/CustomGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public object Create(object request, ISpecimenContext context)
{
var value = context.Resolve(GetUnderlyingType(type));

return type.GetMethod("From").Invoke(null, [value]);
return type.GetMethod("From")!.Invoke(null, [value])!;
}

return new NoSpecimen();
Expand Down
1 change: 1 addition & 0 deletions backend/MenuApi.Tests/MenuApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<IsPackable>false</IsPackable>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
4 changes: 2 additions & 2 deletions backend/MenuApi.Tests/Services/RecipeServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task GetRecipeSuccess(DBModel.Recipe recipe, IEnumerable<DBModel.Ge

var result = await sut.GetRecipeAsync(recipe.Id);

result.Name.Should().Be(recipe.Name);
result!.Name.Should().Be(recipe.Name);
result.Id.Should().Be(recipe.Id);
result.Ingredients.Should().BeEquivalentTo(expected);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public async Task UpdateRecipeAsync_Deduplicates_Exact_Duplicate_Ingredients_Bef
[Theory, CustomAutoData]
public async Task UpdateRecipe_Should_Throw_Exception_For_null_newRecipeAsync(RecipeId recipeId)
{
Func<Task> fun = () => sut.UpdateRecipeAsync(recipeId, null);
Func<Task> fun = () => sut.UpdateRecipeAsync(recipeId, null!);

var result = await fun.Should().ThrowAsync<ArgumentNullException>();
result.And.ParamName.Should().Be("newRecipe");
Expand Down
14 changes: 14 additions & 0 deletions backend/MenuApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MenuDB", "MenuDB\MenuDB.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Menu.MigrationService", "Menu.MigrationService\Menu.MigrationService.csproj", "{678A54EA-9237-49D6-B4DC-ACEF67F6385E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MenuDB.Tests", "MenuDB.Tests\MenuDB.Tests.csproj", "{E780A213-994B-4759-9FC6-DB589E8C0DE2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -125,6 +127,18 @@ Global
{678A54EA-9237-49D6-B4DC-ACEF67F6385E}.Release|x64.Build.0 = Release|Any CPU
{678A54EA-9237-49D6-B4DC-ACEF67F6385E}.Release|x86.ActiveCfg = Release|Any CPU
{678A54EA-9237-49D6-B4DC-ACEF67F6385E}.Release|x86.Build.0 = Release|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Debug|x64.ActiveCfg = Debug|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Debug|x64.Build.0 = Debug|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Debug|x86.ActiveCfg = Debug|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Debug|x86.Build.0 = Debug|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Release|Any CPU.Build.0 = Release|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Release|x64.ActiveCfg = Release|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Release|x64.Build.0 = Release|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Release|x86.ActiveCfg = Release|Any CPU
{E780A213-994B-4759-9FC6-DB589E8C0DE2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions backend/MenuApi/ValueObjects/MenuUserId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Vogen;

namespace MenuApi.ValueObjects;

[ValueObject<int>]
public readonly partial struct MenuUserId { }
38 changes: 38 additions & 0 deletions backend/MenuDB.Tests/MenuDB.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">
Comment thread
dgee2 marked this conversation as resolved.

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.8" />
<PackageReference Include="Microsoft.Testing.Platform" Version="2.2.3" />
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
<PackageReference Include="AwesomeAssertions.Analyzers" Version="9.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="GitHubActionsTestLogger" Version="3.0.4" />
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MenuDB\MenuDB.csproj" />
</ItemGroup>

</Project>
Loading
Loading