This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Ludarium.Application;
|
||||
using Ludarium.Domain;
|
||||
|
||||
namespace Ludarium.UnitTests;
|
||||
|
||||
public sealed class SnapshotComparerTests
|
||||
{
|
||||
[Fact]
|
||||
public void ComparisonDistinguishesAddedRemovedMovedChangedAndUnchanged()
|
||||
{
|
||||
var root = Guid.NewGuid();
|
||||
var moved = Guid.NewGuid(); var changed = Guid.NewGuid(); var removed = Guid.NewGuid(); var unchanged = Guid.NewGuid(); var added = Guid.NewGuid();
|
||||
var before = Snapshot("before",
|
||||
new(root, "old/game.bin", 1, Hash('a'), moved, null),
|
||||
new(root, "changed.bin", 1, Hash('b'), changed, null),
|
||||
new(root, "removed.bin", 1, Hash('c'), removed, null),
|
||||
new(root, "same.bin", 1, Hash('d'), unchanged, null));
|
||||
var after = Snapshot("after",
|
||||
new(root, "new/game.bin", 1, Hash('a'), moved, null),
|
||||
new(root, "changed.bin", 2, Hash('e'), changed, null),
|
||||
new(root, "same.bin", 1, Hash('d'), unchanged, null),
|
||||
new(root, "added.bin", 1, Hash('f'), added, null));
|
||||
var result = new SnapshotComparer().Compare(before, after);
|
||||
Assert.Single(result, x => x.Kind == SnapshotChangeKind.Added);
|
||||
Assert.Single(result, x => x.Kind == SnapshotChangeKind.Removed);
|
||||
Assert.Single(result, x => x.Kind == SnapshotChangeKind.Moved);
|
||||
Assert.Single(result, x => x.Kind == SnapshotChangeKind.ContentChanged);
|
||||
Assert.Single(result, x => x.Kind == SnapshotChangeKind.Unchanged);
|
||||
}
|
||||
|
||||
private static IntegritySnapshot Snapshot(string name, params SnapshotItem[] items) => new(Guid.NewGuid(), name, "1", "test", DateTimeOffset.UtcNow, new ReadOnlyCollection<SnapshotItem>(items));
|
||||
private static string Hash(char value) => new(value, 64);
|
||||
}
|
||||
Reference in New Issue
Block a user