- 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
91 lines
3.4 KiB
C#
91 lines
3.4 KiB
C#
using SharepointToolbox.Core.Models;
|
|
using SharepointToolbox.Services.Export;
|
|
|
|
namespace SharepointToolbox.Tests.Services.Export;
|
|
|
|
/// <summary>
|
|
/// Tests for PERM-06: HTML export output.
|
|
/// These tests reference HtmlExportService which will be implemented in Plan 03.
|
|
/// Until Plan 03 runs they will fail to compile — that is expected.
|
|
/// </summary>
|
|
public class HtmlExportServiceTests
|
|
{
|
|
private static PermissionEntry MakeEntry(
|
|
string users, string userLogins,
|
|
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()
|
|
{
|
|
var entry = MakeEntry("Bob Smith", "bob@contoso.com");
|
|
var svc = new HtmlExportService();
|
|
var html = svc.BuildHtml(new[] { entry });
|
|
|
|
Assert.Contains("Bob Smith", html);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildHtml_WithEmptyList_ReturnsValidHtml()
|
|
{
|
|
var svc = new HtmlExportService();
|
|
var html = svc.BuildHtml(Array.Empty<PermissionEntry>());
|
|
|
|
// Must be non-empty well-formed HTML even with no data rows
|
|
Assert.NotEmpty(html);
|
|
Assert.Contains("<html", html, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildHtml_WithExternalUser_ContainsExtHashMarker()
|
|
{
|
|
// External users have #EXT# in their login — HTML output should make them distinguishable
|
|
var entry = MakeEntry(
|
|
users: "Ext User",
|
|
userLogins: "ext_user_domain.com#EXT#@contoso.onmicrosoft.com");
|
|
|
|
var svc = new HtmlExportService();
|
|
var html = svc.BuildHtml(new[] { entry });
|
|
|
|
// 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);
|
|
}
|
|
}
|