feat(11-02): extend export tests to verify branding injection across all 5 services

- HtmlExportServiceTests: 3 new tests (MSP logo only, null branding no img, both logos)
- SearchExportServiceTests: 1 new branding test (img tag present when branding provided)
- StorageHtmlExportServiceTests: 1 new branding test (img tag present)
- DuplicatesHtmlExportServiceTests: 1 new branding test (img tag present)
- UserAccessHtmlExportServiceTests: 1 new branding test (img tag present)
- MakeBranding helper added to each test class
- All 45 export tests pass; full suite 247/247 with 0 failures
This commit is contained in:
Dev
2026-04-08 14:45:55 +02:00
parent 2233fb86a9
commit d8b66169e6
5 changed files with 109 additions and 0 deletions

View File

@@ -6,6 +6,13 @@ namespace SharepointToolbox.Tests.Services.Export;
public class DuplicatesHtmlExportServiceTests
{
private static ReportBranding MakeBranding(bool msp = true, bool client = false)
{
var mspLogo = msp ? new LogoData { Base64 = "bXNw", MimeType = "image/png" } : null;
var clientLogo = client ? new LogoData { Base64 = "Y2xpZW50", MimeType = "image/jpeg" } : null;
return new ReportBranding(mspLogo, clientLogo);
}
private static DuplicateGroup MakeGroup(string name, int count) => new()
{
GroupKey = $"{name}|1024",
@@ -50,4 +57,15 @@ public class DuplicatesHtmlExportServiceTests
var html = svc.BuildHtml(new List<DuplicateGroup>());
Assert.Contains("<!DOCTYPE html>", html);
}
// ── Branding tests ────────────────────────────────────────────────────────
[Fact]
public void BuildHtml_WithBranding_ContainsLogoImg()
{
var svc = new DuplicatesHtmlExportService();
var groups = new List<DuplicateGroup> { MakeGroup("report.docx", 2) };
var html = svc.BuildHtml(groups, MakeBranding(msp: true));
Assert.Contains("data:image/png;base64,bXNw", html);
}
}

View File

@@ -15,6 +15,13 @@ public class HtmlExportServiceTests
string url = "https://contoso.sharepoint.com/sites/A") =>
new("Web", "Site A", url, true, users, userLogins, "Read", "Direct Permissions", "User");
private static ReportBranding MakeBranding(bool msp = true, bool client = false)
{
var mspLogo = msp ? new LogoData { Base64 = "bXNw", MimeType = "image/png" } : null;
var clientLogo = client ? new LogoData { Base64 = "Y2xpZW50", MimeType = "image/jpeg" } : null;
return new ReportBranding(mspLogo, clientLogo);
}
[Fact]
public void BuildHtml_WithKnownEntries_ContainsUserNames()
{
@@ -50,4 +57,34 @@ public class HtmlExportServiceTests
// The HTML should surface the external marker so admins can identify guests
Assert.Contains("EXT", html, StringComparison.OrdinalIgnoreCase);
}
// ── Branding tests ────────────────────────────────────────────────────────
[Fact]
public void BuildHtml_WithMspBranding_ContainsMspLogoImg()
{
var entry = MakeEntry("Test", "test@contoso.com");
var svc = new HtmlExportService();
var html = svc.BuildHtml(new[] { entry }, MakeBranding(msp: true, client: false));
Assert.Contains("data:image/png;base64,bXNw", html);
}
[Fact]
public void BuildHtml_WithNullBranding_ContainsNoLogoImg()
{
var entry = MakeEntry("Test", "test@contoso.com");
var svc = new HtmlExportService();
var html = svc.BuildHtml(new[] { entry });
Assert.DoesNotContain("data:image/png;base64,", html);
}
[Fact]
public void BuildHtml_WithBothLogos_ContainsTwoImgs()
{
var entry = MakeEntry("Test", "test@contoso.com");
var svc = new HtmlExportService();
var html = svc.BuildHtml(new[] { entry }, MakeBranding(msp: true, client: true));
Assert.Contains("data:image/png;base64,bXNw", html);
Assert.Contains("data:image/jpeg;base64,Y2xpZW50", html);
}
}

View File

@@ -79,4 +79,21 @@ public class SearchExportServiceTests
var html = svc.BuildHtml(new List<SearchResult>());
Assert.Contains("<!DOCTYPE html>", html);
}
// ── Branding tests ────────────────────────────────────────────────────────
private static ReportBranding MakeBranding(bool msp = true, bool client = false)
{
var mspLogo = msp ? new LogoData { Base64 = "bXNw", MimeType = "image/png" } : null;
var clientLogo = client ? new LogoData { Base64 = "Y2xpZW50", MimeType = "image/jpeg" } : null;
return new ReportBranding(mspLogo, clientLogo);
}
[Fact]
public void BuildHtml_WithBranding_ContainsLogoImg()
{
var svc = new SearchHtmlExportService();
var html = svc.BuildHtml(new List<SearchResult> { MakeSample() }, MakeBranding(msp: true));
Assert.Contains("data:image/png;base64,bXNw", html);
}
}

View File

@@ -6,6 +6,12 @@ namespace SharepointToolbox.Tests.Services.Export;
public class StorageHtmlExportServiceTests
{
private static ReportBranding MakeBranding(bool msp = true, bool client = false)
{
var mspLogo = msp ? new LogoData { Base64 = "bXNw", MimeType = "image/png" } : null;
var clientLogo = client ? new LogoData { Base64 = "Y2xpZW50", MimeType = "image/jpeg" } : null;
return new ReportBranding(mspLogo, clientLogo);
}
[Fact]
public void BuildHtml_WithNodes_ContainsToggleJs()
{
@@ -48,4 +54,18 @@ public class StorageHtmlExportServiceTests
Assert.Contains("Documents", html);
Assert.Contains("Images", html);
}
// ── Branding tests ────────────────────────────────────────────────────────
[Fact]
public void BuildHtml_WithBranding_ContainsLogoImg()
{
var svc = new StorageHtmlExportService();
var nodes = new List<StorageNode>
{
new() { Name = "Documents", Library = "Documents", SiteTitle = "Site1", TotalSizeBytes = 1000 }
};
var html = svc.BuildHtml(nodes, MakeBranding(msp: true));
Assert.Contains("data:image/png;base64,bXNw", html);
}
}

View File

@@ -13,6 +13,13 @@ public class UserAccessHtmlExportServiceTests
{
// ── Helper factory ────────────────────────────────────────────────────────
private static ReportBranding MakeBranding(bool msp = true, bool client = false)
{
var mspLogo = msp ? new LogoData { Base64 = "bXNw", MimeType = "image/png" } : null;
var clientLogo = client ? new LogoData { Base64 = "Y2xpZW50", MimeType = "image/jpeg" } : null;
return new ReportBranding(mspLogo, clientLogo);
}
private static UserAccessEntry MakeEntry(
string userDisplay = "Alice Smith",
string userLogin = "alice@contoso.com",
@@ -124,4 +131,14 @@ public class UserAccessHtmlExportServiceTests
// Encoded form must be present
Assert.Contains("&lt;script&gt;", html);
}
// ── Branding tests ────────────────────────────────────────────────────────
[Fact]
public void BuildHtml_WithBranding_ContainsLogoImg()
{
var svc = new UserAccessHtmlExportService();
var html = svc.BuildHtml(new[] { DefaultEntry }, MakeBranding(msp: true));
Assert.Contains("data:image/png;base64,bXNw", html);
}
}