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().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)); } }