Skip to content

Commit

Permalink
Further unit test improvements. Prevented incrementing progress for e…
Browse files Browse the repository at this point in the history
…ach of multiple multiple pre-archiving messages
  • Loading branch information
tombogle committed Oct 4, 2024
1 parent 82efbd3 commit 29b08b2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
32 changes: 27 additions & 5 deletions SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,34 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau

var model = new IMDIArchivingDlgViewModel("Test App", "Test Title", "tst", true,
(a, b) => { filesToArchiveCalled = true; }, "whatever");

var progress = new TestProgress("IMDI");
var customSummaryShown = 0;
model.OverrideDisplayInitialSummary = (d, c) => { customSummaryShown++; };

model.OverrideDisplayInitialSummary = (d, c) =>
{
customSummaryShown++;
progress.IncrementProgress();
};
model.GetOverriddenPreArchivingMessages = d => throw new AssertionException(
$"{nameof(ArchivingDlgViewModel.GetOverriddenPreArchivingMessages)} should not have been invoked");
model.OverrideGetFileGroupDisplayMessage = s => throw new AssertionException(
$"{nameof(ArchivingDlgViewModel.OverrideGetFileGroupDisplayMessage)} should not have been invoked");

model.InitializationFailed += (sender, e) => Assert.Fail("Initialization failed");

await model.Initialize(progress, new CancellationToken());
try
{
await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false);
}
catch (Exception ex)
{
Assert.Fail($"Initialization threw an exception: {ex}");
}

Assert.True(filesToArchiveCalled);
Assert.That(customSummaryShown, Is.EqualTo(1));
Assert.That(progress.Step, Is.EqualTo(1));
}
}

Expand Down Expand Up @@ -337,10 +351,17 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type)
model.GetOverriddenPreArchivingMessages = GetMessages;
model.InitialFileGroupDisplayMessageType = Success;
model.OverrideGetFileGroupDisplayMessage = s => (s == String.Empty) ? "Frogs" : $"Label: {s}";
model.InitializationFailed += (sender, e) => Assert.Fail("Initialization failed");


var progress = new TestProgress("RAMP");
await model.Initialize(progress, new CancellationToken());
var progress = new TestProgress("IMDI");
try
{
await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false);
}
catch (Exception ex)
{
Assert.Fail($"Initialization threw an exception: {ex}");
}

Assert.That(messagesDisplayed.Count, Is.EqualTo(7));
Assert.That(messagesDisplayed[0].Item1, Is.EqualTo("First pre-archiving message"));
Expand All @@ -357,6 +378,7 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type)
Assert.That(messagesDisplayed[5].Item2, Is.EqualTo(Bullet));
Assert.That(messagesDisplayed[6].Item1, Is.EqualTo("blue.toad"));
Assert.That(messagesDisplayed[6].Item2, Is.EqualTo(Bullet));
Assert.That(progress.Step, Is.EqualTo(1));
}
}
}
30 changes: 26 additions & 4 deletions SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,18 +753,33 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau

var model = new RampArchivingDlgViewModel("Test App", "Test Title", "tst",
(a, b) => { filesToArchiveCalled = true; }, (k, f) => throw new NotImplementedException());

var progress = new TestProgress("RAMP");
var customSummaryShown = 0;
model.OverrideDisplayInitialSummary = (d, c) => { customSummaryShown++; };

model.OverrideDisplayInitialSummary = (d, c) =>
{
customSummaryShown++;
progress.IncrementProgress();
};
model.GetOverriddenPreArchivingMessages = d => throw new AssertionException(
$"{nameof(ArchivingDlgViewModel.GetOverriddenPreArchivingMessages)} should not have been invoked");
model.OverrideGetFileGroupDisplayMessage = s => throw new AssertionException(
$"{nameof(ArchivingDlgViewModel.OverrideGetFileGroupDisplayMessage)} should not have been invoked");

await model.Initialize(new TestProgress("RAMP"), new CancellationToken());
try
{
await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false);
}
catch (Exception ex)
{
Assert.Fail($"Initialization threw an exception: {ex}");
}

Assert.True(filesToArchiveCalled);
Assert.That(customSummaryShown, Is.EqualTo(1));
Assert.False(File.Exists(model.PackagePath));
Assert.That(progress.Step, Is.EqualTo(1));
}
}

Expand Down Expand Up @@ -808,9 +823,15 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type)
model.InitialFileGroupDisplayMessageType = Success;
model.OverrideGetFileGroupDisplayMessage = s => (s == String.Empty) ? "Frogs" : $"Label: {s}";


var progress = new TestProgress("RAMP");
await model.Initialize(progress, new CancellationToken());
try
{
await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false);
}
catch (Exception ex)
{
Assert.Fail($"Initialization threw an exception: {ex}");
}

Assert.That(messagesDisplayed.Count, Is.EqualTo(8));
Assert.That(messagesDisplayed[0].Item1, Is.EqualTo("Test implementation message for SearchingForArchiveUploadingProgram"));
Expand All @@ -829,6 +850,7 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type)
Assert.That(messagesDisplayed[7].Item1, Is.EqualTo("blue.toad"));
Assert.That(messagesDisplayed[7].Item2, Is.EqualTo(Bullet));
Assert.False(File.Exists(model.PackagePath));
Assert.That(progress.Step, Is.EqualTo(1));
}
}
}
11 changes: 10 additions & 1 deletion SIL.Archiving/ArchivingDlgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,17 @@ private void DisplayInitialSummary(CancellationToken cancellationToken)

if (GetOverriddenPreArchivingMessages != null)
{
bool firstMsg = true;
foreach (var msg in GetOverriddenPreArchivingMessages(FileLists))
ReportProgress(msg.Item1, msg.Item2, cancellationToken);
{
if (firstMsg)
{
ReportProgress(msg.Item1, msg.Item2, cancellationToken);
firstMsg = false;
}
else
DisplayMessage(msg.Item1, msg.Item2);
}
}
else
ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), MessageType.Normal,
Expand Down

0 comments on commit 29b08b2

Please sign in to comment.