初步
This commit is contained in:
1 parent
a1f48945e8
commit
ab935480b0
26 files changed
+829
-5
No files matched your search
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ElectionSystem.Api\ElectionSystem.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
using ElectionSystem.Api.Infrastructure.Auditing;
|
||||
using ElectionSystem.Api.Infrastructure.Persistence;
|
||||
using ElectionSystem.Api.Modules.Identity.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ElectionSystem.Api.Tests;
|
||||
|
||||
public sealed class PersistenceModelTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task UserName_must_be_unique()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<ElectionDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
|
||||
await using var context = new ElectionDbContext(options);
|
||||
context.Users.Add(new ApplicationUser { UserName = "admin", DisplayName = "Administrator" });
|
||||
await context.SaveChangesAsync();
|
||||
var index = context.Model.FindEntityType(typeof(ApplicationUser))!.GetIndexes().Single(x => x.Properties.Single().Name == nameof(ApplicationUser.UserName));
|
||||
Assert.True(index.IsUnique);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Audit_entry_does_not_contain_vote_content_field()
|
||||
{
|
||||
var properties = typeof(AuditEntry).GetProperties().Select(property => property.Name);
|
||||
Assert.DoesNotContain(properties, property => property.Contains("Vote", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user