Skip to content

Commit

Permalink
test: Fix unit tests for application
Browse files Browse the repository at this point in the history
  • Loading branch information
a.civier committed May 17, 2024
1 parent 95fd37c commit f2070d6
Show file tree
Hide file tree
Showing 27 changed files with 504 additions and 198 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ dotnet_diagnostic.IDE0005.severity = warning

# IDE0052: Remove unread private members
dotnet_diagnostic.IDE0052.severity = warning

# SA1601: Partial elements should be documented
dotnet_diagnostic.SA1601.severity = silent
11 changes: 8 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" NoWarn="NU1605" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.3" NoWarn="NU1605" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.5" />
<PackageVersion Include="Microsoft.Identity.Web" Version="2.15.2" />
<PackageVersion Include="Microsoft.Identity.Web.DownstreamApi" Version="2.15.2" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
Expand All @@ -33,9 +34,13 @@ https://devblogs.microsoft.com/nuget/introducing-central-package-management/ -->
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.5" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="moq" Version="4.20.70" />
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="nunit" Version="4.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
</ItemGroup>
</Project>
14 changes: 7 additions & 7 deletions WebAppStarter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solutions Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{41D3ECC0-AB64-4994-8B5E-73A7876C4F5F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api.UnitTests", "tests\Api.UnitTests\Api.UnitTests.csproj", "{31BDF5B0-70C7-4802-B0C8-63A88C0DFD67}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{19D0CD06-CCE9-4918-B178-F0D49D3D830E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{F8DB058D-EE5F-4CC7-9136-98B910FE49D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Application\Application.csproj", "{ECEE2966-F534-4939-8446-FDCE3E28A054}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application.FunctionalTests", "tests\Application.FunctionalTests\Application.FunctionalTests.csproj", "{475E9335-BA53-4587-8058-2E684053EE87}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -45,10 +45,6 @@ Global
{0261127C-E97A-4350-AFFD-FBFF75F12AD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0261127C-E97A-4350-AFFD-FBFF75F12AD3}.Release|Any CPU.Build.0 = Release|Any CPU
{0261127C-E97A-4350-AFFD-FBFF75F12AD3}.Release|Any CPU.Deploy.0 = Release|Any CPU
{31BDF5B0-70C7-4802-B0C8-63A88C0DFD67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31BDF5B0-70C7-4802-B0C8-63A88C0DFD67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31BDF5B0-70C7-4802-B0C8-63A88C0DFD67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31BDF5B0-70C7-4802-B0C8-63A88C0DFD67}.Release|Any CPU.Build.0 = Release|Any CPU
{19D0CD06-CCE9-4918-B178-F0D49D3D830E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19D0CD06-CCE9-4918-B178-F0D49D3D830E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19D0CD06-CCE9-4918-B178-F0D49D3D830E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -61,17 +57,21 @@ Global
{ECEE2966-F534-4939-8446-FDCE3E28A054}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECEE2966-F534-4939-8446-FDCE3E28A054}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECEE2966-F534-4939-8446-FDCE3E28A054}.Release|Any CPU.Build.0 = Release|Any CPU
{475E9335-BA53-4587-8058-2E684053EE87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{475E9335-BA53-4587-8058-2E684053EE87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{475E9335-BA53-4587-8058-2E684053EE87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{475E9335-BA53-4587-8058-2E684053EE87}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{24717492-0735-485A-A0A9-DF837633E3DD} = {D34D9A25-2206-4972-BC45-EC8363A695C0}
{0261127C-E97A-4350-AFFD-FBFF75F12AD3} = {D34D9A25-2206-4972-BC45-EC8363A695C0}
{31BDF5B0-70C7-4802-B0C8-63A88C0DFD67} = {41D3ECC0-AB64-4994-8B5E-73A7876C4F5F}
{19D0CD06-CCE9-4918-B178-F0D49D3D830E} = {D34D9A25-2206-4972-BC45-EC8363A695C0}
{F8DB058D-EE5F-4CC7-9136-98B910FE49D0} = {D34D9A25-2206-4972-BC45-EC8363A695C0}
{ECEE2966-F534-4939-8446-FDCE3E28A054} = {D34D9A25-2206-4972-BC45-EC8363A695C0}
{475E9335-BA53-4587-8058-2E684053EE87} = {41D3ECC0-AB64-4994-8B5E-73A7876C4F5F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A727A511-A414-4DD0-A3C6-3DCCCBB5C3FB}
Expand Down
4 changes: 4 additions & 0 deletions src/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
app.MapControllers();

app.Run();

public partial class Program
{
}
2 changes: 1 addition & 1 deletion src/Application/Common/Behaviours/LoggingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CleanArchitecture.Application.Common.Behaviours;
namespace WebAppStarter.Application.Common.Behaviours;

using MediatR.Pipeline;
using Microsoft.Extensions.Logging;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Common/Behaviours/PerformanceBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CleanArchitecture.Application.Common.Behaviours;
namespace WebAppStarter.Application.Common.Behaviours;

using System.Diagnostics;
using MediatR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CleanArchitecture.Application.Common.Behaviours;
namespace WebAppStarter.Application.Common.Behaviours;

using MediatR;
using Microsoft.Extensions.Logging;
Expand Down
3 changes: 2 additions & 1 deletion src/Application/Common/Behaviours/ValidationBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CleanArchitecture.Application.Common.Behaviours;
namespace WebAppStarter.Application.Common.Behaviours;

using FluentValidation;
using MediatR;
Expand All @@ -22,6 +22,7 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
.SelectMany(r => r.Errors)
.ToList();

// TODO: Maybe return a Result.Invalid instead of throwing an error
if (failures.Any())
throw new ValidationException(failures);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Microsoft.Extensions.DependencyInjection;

using System.Reflection;
using CleanArchitecture.Application.Common.Behaviours;
using FluentValidation;
using MediatR;
using WebAppStarter.Application.Common.Behaviours;

public static class DependencyInjection
{
Expand Down
1 change: 1 addition & 0 deletions src/Domain/Entities/TodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel.DataAnnotations;
using WebAppStarter.Domain.Common;

// TODO: inherit from BaseAuditableEntity
public class TodoItem : BaseEntity
{
[Required]
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
#if USE_SQL_LITE
options.UseSqlite(connectionString);
#else
options.UseInMemoryDatabase("ToDos");
options.UseInMemoryDatabase("AppDatabase");
#endif
});

Expand Down
25 changes: 0 additions & 25 deletions tests/Api.UnitTests/Api.UnitTests.csproj

This file was deleted.

44 changes: 0 additions & 44 deletions tests/Api.UnitTests/Controllers/TodoListControllerTestsWithApp.cs

This file was deleted.

71 changes: 0 additions & 71 deletions tests/Api.UnitTests/Controllers/TodoListControllerTestsWithUser.cs

This file was deleted.

32 changes: 0 additions & 32 deletions tests/Api.UnitTests/Mocks/MockHttpContext.cs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/Api.UnitTests/UnitTest1.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ardalis.Result" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="nunit" />
<PackageReference Include="NUnit.Analyzers">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

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

</Project>
13 changes: 13 additions & 0 deletions tests/Application.FunctionalTests/BaseTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace WebAppStarter.Application.FunctionalTests;

using static Testing;

[TestFixture]
public abstract class BaseTestFixture
{
[SetUp]
public async Task TestSetUp()
{
await ResetState();
}
}
Loading

0 comments on commit f2070d6

Please sign in to comment.