-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): refactor UnitTests to xunit
- Loading branch information
Showing
8 changed files
with
80 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<RootNamespace>VerticalSliceArchitecture.Application.UnitTests</RootNamespace> | ||
<AssemblyName>VerticalSliceArchitecture.Application.UnitTests</AssemblyName> | ||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<IsPackable>false</IsPackable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Moq" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> | ||
<PackageReference Include="nunit" Version="3.13.2" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" Version="6.2.0" /> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Application\Application.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
|
24 changes: 12 additions & 12 deletions
24
tests/Application.UnitTests/Common/Behaviours/RequestLoggerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
using VerticalSliceArchitecture.Application.Common.Behaviours; | ||
using VerticalSliceArchitecture.Application.Common.Interfaces; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging; | ||
|
||
using Moq; | ||
using NUnit.Framework; | ||
|
||
using VerticalSliceArchitecture.Application.Common.Behaviours; | ||
using VerticalSliceArchitecture.Application.Common.Interfaces; | ||
using VerticalSliceArchitecture.Application.Features.TodoItems; | ||
|
||
namespace VerticalSliceArchitecture.Application.UnitTests.Common.Behaviours; | ||
|
||
public class RequestLoggerTests | ||
{ | ||
private Mock<ILogger<CreateTodoItemCommand>> _logger = null!; | ||
private Mock<ICurrentUserService> _currentUserService = null!; | ||
private readonly Mock<ILogger<CreateTodoItemCommand>> _logger; | ||
private readonly Mock<ICurrentUserService> _currentUserService; | ||
|
||
[SetUp] | ||
public void Setup() | ||
public RequestLoggerTests() | ||
{ | ||
_logger = new Mock<ILogger<CreateTodoItemCommand>>(); | ||
_currentUserService = new Mock<ICurrentUserService>(); | ||
} | ||
|
||
[Test] | ||
[Fact] | ||
public async Task ShouldCallGetUserNameAsyncOnceIfAuthenticated() | ||
{ | ||
_currentUserService.Setup(x => x.UserId).Returns(Guid.NewGuid().ToString()); | ||
|
||
var requestLogger = new LoggingBehaviour<CreateTodoItemCommand>(_logger.Object, _currentUserService.Object); | ||
|
||
await requestLogger.Process(new CreateTodoItemCommand { ListId = 1, Title = "title" }, new CancellationToken()); | ||
await requestLogger.Process(new CreateTodoItemCommand { ListId = 1, Title = "title" }, CancellationToken.None); | ||
} | ||
|
||
[Test] | ||
[Fact] | ||
public async Task ShouldNotCallGetUserNameAsyncOnceIfUnauthenticated() | ||
{ | ||
var requestLogger = new LoggingBehaviour<CreateTodoItemCommand>(_logger.Object, _currentUserService.Object); | ||
|
||
await requestLogger.Process(new CreateTodoItemCommand { ListId = 1, Title = "title" }, new CancellationToken()); | ||
await requestLogger.Process(new CreateTodoItemCommand { ListId = 1, Title = "title" }, CancellationToken.None); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
global using FluentAssertions; | ||
|
||
global using Xunit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters