shoc-backend/Api.SeaHavenIndustries.Tests/UserDataServiceTests.cs
2026-08-31 10:22:27 -03:00

40 lines
1.2 KiB
C#

using Data.SeaHavenIndustries;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using SeaHaven.DataServices.Implementation;
using Xunit;
namespace Api.SeaHavenIndustries.Tests;
public class UserDataServiceTests
{
private static ApplicationDbContext NewContext()
{
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
.Options;
return new ApplicationDbContext(options);
}
[Fact]
public async Task GetAllForListAsync_ComposesFullDisplayName()
{
await using var context = NewContext();
context.Users.Add(new ApplicationUser
{
Id = "s1",
UserName = "alex.smith",
Email = "alex.smith@example.com",
FirstName = "Alex",
LastName = "Smith"
});
await context.SaveChangesAsync();
var service = new UserDataService(context);
var rows = await service.GetAllForListAsync(CancellationToken.None);
rows.Should().ContainSingle();
rows[0].Id.Should().Be("s1");
rows[0].Name.Should().Be("Alex Smith");
}
}