using Microsoft.AspNetCore.Identity; using YesChef.Api.Data; using YesChef.Api.Entities; namespace YesChef.Api.IntegrationTests.Builders; public sealed class UserBuilder { private string _name = $"user-{Guid.NewGuid():N}"[..16]; private string _password = "correct-horse-battery-staple"; private string? _email; public UserBuilder Named(string name) { _name = name; return this; } public UserBuilder WithPassword(string password) { _password = password; return this; } public UserBuilder WithEmail(string email) { _email = email; return this; } public string PlaintextPassword => _password; public User Build() { var user = new User { Name = _name, PasswordHash = "", Email = _email ?? $"{_name}@example.test", }; user.PasswordHash = new PasswordHasher().HashPassword(user, _password); return user; } public async Task PersistAsync(YesChefDb db) { var user = Build(); db.Users.Add(user); await db.SaveChangesAsync(); return user; } }