diff --git a/Api.SeaHavenIndustries.Tests/UserDataServiceTests.cs b/Api.SeaHavenIndustries.Tests/UserDataServiceTests.cs new file mode 100644 index 0000000..f4f1a6a --- /dev/null +++ b/Api.SeaHavenIndustries.Tests/UserDataServiceTests.cs @@ -0,0 +1,40 @@ +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() + .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"); + } +} diff --git a/SeaHaven.DataServices/Implementation/UserDataService.cs b/SeaHaven.DataServices/Implementation/UserDataService.cs index 6ad82cc..055f870 100644 --- a/SeaHaven.DataServices/Implementation/UserDataService.cs +++ b/SeaHaven.DataServices/Implementation/UserDataService.cs @@ -44,7 +44,7 @@ namespace SeaHaven.DataServices.Implementation Id = user.Id, RoleName = user.PhoneNumber, Email = user.Email, - Name = user.FirstName, + Name = ((user.FirstName ?? "") + " " + (user.LastName ?? "")).Trim(), CreatedDate = user.CreatedDate, Status = user.UniqueName })