feat(Mock): Hinzufügen von gefälschten Daten und Benutzermodellen zum Testen
Aktualisiert `DigitalData.Core.Tests.csproj`, um `Bogus` zur Erzeugung gefälschter Daten einzuschließen. Fake.cs„ für die Erstellung von gefälschten “User"-Objekten hinzugefügt. MockDbContext" für das Testen von Datenbank-Interaktionen eingeführt. Definierte `User` und `UserDto` Klassen für die Benutzerdarstellung und Datenübertragung.
This commit is contained in:
parent
cf2ee73ca1
commit
cf9041980d
@ -10,6 +10,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Bogus" Version="35.6.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.16" />
|
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.16" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
<PackageReference Include="Moq" Version="4.20.70" />
|
<PackageReference Include="Moq" Version="4.20.70" />
|
||||||
|
|||||||
15
DigitalData.Core.Tests/Mock/Fake.cs
Normal file
15
DigitalData.Core.Tests/Mock/Fake.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Bogus;
|
||||||
|
|
||||||
|
namespace DigitalData.Core.Tests.Mock;
|
||||||
|
|
||||||
|
public static class Fake
|
||||||
|
{
|
||||||
|
private static readonly Faker<User> UserFaker = new Faker<User>()
|
||||||
|
.RuleFor(u => u.FirstName, f => f.Name.FirstName())
|
||||||
|
.RuleFor(u => u.Email, f => f.Internet.Email())
|
||||||
|
.RuleFor(u => u.Age, f => f.Random.Int(18, 99));
|
||||||
|
|
||||||
|
public static User FakeUser => UserFaker.Generate();
|
||||||
|
|
||||||
|
public static List<User> CreateFakeUser(int count) => UserFaker.Generate(count);
|
||||||
|
}
|
||||||
10
DigitalData.Core.Tests/Mock/MockDbContext.cs
Normal file
10
DigitalData.Core.Tests/Mock/MockDbContext.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace DigitalData.Core.Tests.Mock;
|
||||||
|
|
||||||
|
public class MockDbContext : DbContext
|
||||||
|
{
|
||||||
|
public MockDbContext(DbContextOptions options) : base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
12
DigitalData.Core.Tests/Mock/User.cs
Normal file
12
DigitalData.Core.Tests/Mock/User.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace DigitalData.Core.Tests.Mock;
|
||||||
|
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
public required int Id { get; init; }
|
||||||
|
|
||||||
|
public required string FirstName { get; init; }
|
||||||
|
|
||||||
|
public required string Email { get; init; }
|
||||||
|
|
||||||
|
public int Age { get; init; }
|
||||||
|
}
|
||||||
10
DigitalData.Core.Tests/Mock/UserDto.cs
Normal file
10
DigitalData.Core.Tests/Mock/UserDto.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace DigitalData.Core.Tests.Mock;
|
||||||
|
|
||||||
|
public class UserDto
|
||||||
|
{
|
||||||
|
public required string FirstName { get; init; }
|
||||||
|
|
||||||
|
public required string Email { get; init; }
|
||||||
|
|
||||||
|
public int Age { get; init; }
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user