mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-07-16 17:47:22 +00:00
Format ./web/backend/Features/Features.UserManagement.Tests
This commit is contained in:
@@ -19,4 +19,4 @@ public class UpdateUserHandlerTests
|
|||||||
|
|
||||||
repoMock.Verify(r => r.UpdateAsync(user), Times.Once);
|
repoMock.Verify(r => r.UpdateAsync(user), Times.Once);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,19 +8,19 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1"/>
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||||
<PackageReference Include="xunit" Version="2.9.2"/>
|
<PackageReference Include="xunit" Version="2.9.2" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||||
<PackageReference Include="Moq" Version="4.20.72"/>
|
<PackageReference Include="Moq" Version="4.20.72" />
|
||||||
<PackageReference Include="FluentAssertions" Version="6.9.0"/>
|
<PackageReference Include="FluentAssertions" Version="6.9.0" />
|
||||||
<PackageReference Include="DbMocker" Version="1.26.0"/>
|
<PackageReference Include="DbMocker" Version="1.26.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Xunit"/>
|
<Using Include="Xunit" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Features.UserManagement\Features.UserManagement.csproj"/>
|
<ProjectReference Include="..\Features.UserManagement\Features.UserManagement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ public class GetAllUsersHandlerTests
|
|||||||
GetAllUsersHandler handler = new(repoMock.Object);
|
GetAllUsersHandler handler = new(repoMock.Object);
|
||||||
repoMock.Setup(r => r.GetAllAsync(10, 5)).ReturnsAsync(Array.Empty<UserAccount>());
|
repoMock.Setup(r => r.GetAllAsync(10, 5)).ReturnsAsync(Array.Empty<UserAccount>());
|
||||||
|
|
||||||
IEnumerable<UserAccount> result = await handler.Handle(new GetAllUsersQuery(10, 5), CancellationToken.None);
|
IEnumerable<UserAccount> result = await handler.Handle(
|
||||||
|
new GetAllUsersQuery(10, 5),
|
||||||
|
CancellationToken.None
|
||||||
|
);
|
||||||
|
|
||||||
result.Should().BeEmpty();
|
result.Should().BeEmpty();
|
||||||
repoMock.Verify(r => r.GetAllAsync(10, 5), Times.Once);
|
repoMock.Verify(r => r.GetAllAsync(10, 5), Times.Once);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ public class GetUserByIdHandlerTests
|
|||||||
UserAccount user = new() { UserAccountId = Guid.NewGuid(), Username = "test" };
|
UserAccount user = new() { UserAccountId = Guid.NewGuid(), Username = "test" };
|
||||||
_repoMock.Setup(r => r.GetByIdAsync(user.UserAccountId)).ReturnsAsync(user);
|
_repoMock.Setup(r => r.GetByIdAsync(user.UserAccountId)).ReturnsAsync(user);
|
||||||
|
|
||||||
UserAccount result = await _handler.Handle(new GetUserByIdQuery(user.UserAccountId), CancellationToken.None);
|
UserAccount result = await _handler.Handle(
|
||||||
|
new GetUserByIdQuery(user.UserAccountId),
|
||||||
|
CancellationToken.None
|
||||||
|
);
|
||||||
|
|
||||||
result.Should().Be(user);
|
result.Should().Be(user);
|
||||||
}
|
}
|
||||||
@@ -34,8 +37,9 @@ public class GetUserByIdHandlerTests
|
|||||||
Guid id = Guid.NewGuid();
|
Guid id = Guid.NewGuid();
|
||||||
_repoMock.Setup(r => r.GetByIdAsync(id)).ReturnsAsync((UserAccount?)null);
|
_repoMock.Setup(r => r.GetByIdAsync(id)).ReturnsAsync((UserAccount?)null);
|
||||||
|
|
||||||
Func<Task<UserAccount>> act = async () => await _handler.Handle(new GetUserByIdQuery(id), CancellationToken.None);
|
Func<Task<UserAccount>> act = async () =>
|
||||||
|
await _handler.Handle(new GetUserByIdQuery(id), CancellationToken.None);
|
||||||
|
|
||||||
await act.Should().ThrowAsync<NotFoundException>();
|
await act.Should().ThrowAsync<NotFoundException>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ internal class TestConnectionFactory(DbConnection conn) : ISqlConnectionFactory
|
|||||||
{
|
{
|
||||||
return _conn;
|
return _conn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,19 +98,14 @@ public class UserAccountRepositoryTests
|
|||||||
UserAccountRepository repo = CreateRepo(conn);
|
UserAccountRepository repo = CreateRepo(conn);
|
||||||
List<UserAccount> results = (await repo.GetAllAsync(null, null)).ToList();
|
List<UserAccount> results = (await repo.GetAllAsync(null, null)).ToList();
|
||||||
results.Should().HaveCount(2);
|
results.Should().HaveCount(2);
|
||||||
results
|
results.Select(r => r.Username).Should().BeEquivalentTo("a", "b");
|
||||||
.Select(r => r.Username)
|
|
||||||
.Should()
|
|
||||||
.BeEquivalentTo("a", "b");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetByUsername_ReturnsRow()
|
public async Task GetByUsername_ReturnsRow()
|
||||||
{
|
{
|
||||||
MockDbConnection conn = new();
|
MockDbConnection conn = new();
|
||||||
conn.Mocks.When(cmd =>
|
conn.Mocks.When(cmd => cmd.CommandText == "usp_GetUserAccountByUsername")
|
||||||
cmd.CommandText == "usp_GetUserAccountByUsername"
|
|
||||||
)
|
|
||||||
.ReturnsTable(
|
.ReturnsTable(
|
||||||
MockTable
|
MockTable
|
||||||
.WithColumns(
|
.WithColumns(
|
||||||
@@ -179,4 +174,4 @@ public class UserAccountRepositoryTests
|
|||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
result!.Username.Should().Be("byemail");
|
result!.Username.Should().Be("byemail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user