feat(11-04): add UpdateProfileAsync to ProfileService and ImportLogoFromBytesAsync to BrandingService

- ProfileService.UpdateProfileAsync: replaces profile by name and persists the change
- IBrandingService: add ImportLogoFromBytesAsync to interface contract
- BrandingService.ImportLogoFromBytesAsync: validates magic bytes, compresses if > 512KB, returns LogoData
- BrandingService.ImportLogoAsync: refactored to delegate to ImportLogoFromBytesAsync
- ProfileServiceTests: 2 new tests (UpdateProfileAsync happy path + KeyNotFoundException)
- BrandingServiceTests: 2 new tests (ImportLogoFromBytesAsync valid PNG + invalid bytes)
- Tests.csproj: suppress NU1701 for pre-existing LiveCharts2/OpenTK transitive warnings
This commit is contained in:
Dev
2026-04-08 14:34:11 +02:00
parent 1ab2f2e426
commit 9e850b07f2
6 changed files with 69 additions and 2 deletions

View File

@@ -30,7 +30,15 @@ public class BrandingService : IBrandingService
public async Task<LogoData> ImportLogoAsync(string filePath)
{
var bytes = await File.ReadAllBytesAsync(filePath);
return await ImportLogoFromBytesAsync(bytes);
}
/// <summary>
/// Validates raw bytes as PNG or JPEG via magic bytes, auto-compresses if over 512 KB,
/// and returns a LogoData record. Used when bytes are obtained from a stream (e.g. Entra branding API).
/// </summary>
public Task<LogoData> ImportLogoFromBytesAsync(byte[] bytes)
{
var mimeType = DetectMimeType(bytes);
if (bytes.Length > MaxSizeBytes)
@@ -38,11 +46,11 @@ public class BrandingService : IBrandingService
bytes = CompressToLimit(bytes, mimeType, MaxSizeBytes);
}
return new LogoData
return Task.FromResult(new LogoData
{
Base64 = Convert.ToBase64String(bytes),
MimeType = mimeType
};
});
}
public async Task SaveMspLogoAsync(LogoData logo)