- Add StorageCsvExportService, StorageHtmlExportService stub (Plan 03-03) - Add SearchCsvExportService, SearchHtmlExportService stub (Plan 03-05) - Add DuplicatesHtmlExportService stub (Plan 03-05) - Add StorageServiceTests, SearchServiceTests, DuplicatesServiceTests scaffolds - Add export test scaffolds for all 4 Phase 3 export services - 7 pure-logic tests pass (VersionSizeBytes + MakeKey); 4 CSOM stubs skip
81 lines
3.4 KiB
C#
81 lines
3.4 KiB
C#
using SharepointToolbox.Core.Models;
|
|
using SharepointToolbox.Services;
|
|
using Xunit;
|
|
|
|
namespace SharepointToolbox.Tests.Services;
|
|
|
|
/// <summary>
|
|
/// Pure-logic tests for the MakeKey composite key function (no CSOM needed).
|
|
/// Inline helper matches the implementation DuplicatesService will produce in Plan 03-04.
|
|
/// </summary>
|
|
public class DuplicatesServiceTests
|
|
{
|
|
// Inline copy of MakeKey to test logic before Plan 03-04 creates the real class
|
|
private static string MakeKey(DuplicateItem item, DuplicateScanOptions opts)
|
|
{
|
|
var parts = new System.Collections.Generic.List<string> { item.Name.ToLowerInvariant() };
|
|
if (opts.MatchSize && item.SizeBytes.HasValue) parts.Add(item.SizeBytes.Value.ToString());
|
|
if (opts.MatchCreated && item.Created.HasValue) parts.Add(item.Created.Value.Date.ToString("yyyy-MM-dd"));
|
|
if (opts.MatchModified && item.Modified.HasValue) parts.Add(item.Modified.Value.Date.ToString("yyyy-MM-dd"));
|
|
if (opts.MatchSubfolderCount && item.FolderCount.HasValue) parts.Add(item.FolderCount.Value.ToString());
|
|
if (opts.MatchFileCount && item.FileCount.HasValue) parts.Add(item.FileCount.Value.ToString());
|
|
return string.Join("|", parts);
|
|
}
|
|
|
|
[Fact]
|
|
public void MakeKey_NameOnly_ReturnsLowercaseName()
|
|
{
|
|
var item = new DuplicateItem { Name = "Report.docx", SizeBytes = 1000 };
|
|
var opts = new DuplicateScanOptions(MatchSize: false);
|
|
Assert.Equal("report.docx", MakeKey(item, opts));
|
|
}
|
|
|
|
[Fact]
|
|
public void MakeKey_WithSizeMatch_AppendsSizeToKey()
|
|
{
|
|
var item = new DuplicateItem { Name = "Report.docx", SizeBytes = 1024 };
|
|
var opts = new DuplicateScanOptions(MatchSize: true);
|
|
Assert.Equal("report.docx|1024", MakeKey(item, opts));
|
|
}
|
|
|
|
[Fact]
|
|
public void MakeKey_WithCreatedAndModified_AppendsDateStrings()
|
|
{
|
|
var item = new DuplicateItem
|
|
{
|
|
Name = "file.pdf",
|
|
SizeBytes = 500,
|
|
Created = new DateTime(2024, 3, 15),
|
|
Modified = new DateTime(2024, 6, 1)
|
|
};
|
|
var opts = new DuplicateScanOptions(MatchSize: false, MatchCreated: true, MatchModified: true);
|
|
Assert.Equal("file.pdf|2024-03-15|2024-06-01", MakeKey(item, opts));
|
|
}
|
|
|
|
[Fact]
|
|
public void MakeKey_SameKeyForSameItems_GroupsCorrectly()
|
|
{
|
|
var opts = new DuplicateScanOptions(MatchSize: true);
|
|
var item1 = new DuplicateItem { Name = "Budget.xlsx", SizeBytes = 2048 };
|
|
var item2 = new DuplicateItem { Name = "BUDGET.xlsx", SizeBytes = 2048 };
|
|
Assert.Equal(MakeKey(item1, opts), MakeKey(item2, opts));
|
|
}
|
|
|
|
[Fact]
|
|
public void MakeKey_DifferentSize_ProducesDifferentKeys()
|
|
{
|
|
var opts = new DuplicateScanOptions(MatchSize: true);
|
|
var item1 = new DuplicateItem { Name = "file.docx", SizeBytes = 100 };
|
|
var item2 = new DuplicateItem { Name = "file.docx", SizeBytes = 200 };
|
|
Assert.NotEqual(MakeKey(item1, opts), MakeKey(item2, opts));
|
|
}
|
|
|
|
[Fact(Skip = "Requires live CSOM context — covered by Plan 03-04 implementation")]
|
|
public Task ScanDuplicatesAsync_Files_GroupsByCompositeKey()
|
|
=> Task.CompletedTask;
|
|
|
|
[Fact(Skip = "Requires live CSOM context — covered by Plan 03-04 implementation")]
|
|
public Task ScanDuplicatesAsync_Folders_UsesCamlFSObjType1()
|
|
=> Task.CompletedTask;
|
|
}
|