From 9bd7b1d8256e89777f4ad21b92be2d4a88029ce6 Mon Sep 17 00:00:00 2001 From: tombogle Date: Fri, 4 Oct 2024 00:02:06 -0400 Subject: [PATCH 1/7] +semver:major Added properties to ArchivingDlgViewModel to facilitate customizing the initial summary Added unit tests and changed test app to illustrate intended usage of the new properties. Improved/added some comments in ArchivingDlgViewModel --- CHANGELOG.md | 2 + .../RampArchivingDlgViewModelTests.cs | 103 ++++++++++++++++++ SIL.Archiving/ArchivingDlgViewModel.cs | 102 +++++++++++++---- TestApps/ArchivingTestApp/MainForm.cs | 11 +- 4 files changed, 198 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafd5409a..ff9cb9f87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [SIL.Windows.Forms.Archiving] Added public extensions class LinkLabelExtensions with some methods that were formerly in Extensions class (now in SIL.Archiving). - [SIL.Archiving] Added public property isValid to IMDIPackage. - [SIL.Archiving] Added public event InitializationFailed to IMDIArchivingDlgViewModel. +- [SIL.Archiving] Added the following properties to ArchivingDlgViewModel as an alternative way to customize the initial summary displayed: GetOverriddenPreArchivingMessages, InitialFileGroupDisplayMessageType, OverrideGetFileGroupDisplayMessage ### Changed @@ -71,6 +72,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [SIL.Archiving] Changed IArchivingSession.Files (and Session.Files) into an IReadonlyList. - [SIL.Archiving] Made IMDIPackage.CreateIMDIPackage asynchronous, changing its signature to take a CancellationToken parameter and return Task. - [SIL.Archiving] Made MetaTranscript.WriteCorpusImdiFile asynchronous, changing its signature to return Task. +- [SIL.Archiving] Changed the name of the third parameter in ArchivingDlgViewModel.AddFileGroup from progressMessage to addingToArchiveProgressMessage. ### Fixed - [SIL.Archiving] Fixed typo in RampArchivingDlgViewModel for Ethnomusicology performance collection. diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index db5ad3f4f..240a89ffd 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -11,6 +11,7 @@ using SIL.IO; using SIL.Reporting; using SIL.TestUtilities; +using static SIL.Archiving.ArchivingDlgViewModel.MessageType; namespace SIL.Archiving.Tests { @@ -737,4 +738,106 @@ private void IgnoreTestIfRampIsNotInstalled() } #endregion } + + [TestFixture] + [Category("Archiving")] + public class RampArchivingDlgViewModelWithOverrideDisplayInitialSummarySetTests + { + /// ------------------------------------------------------------------------------------ + [Test] + public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted() + { + ErrorReport.IsOkToInteractWithUser = false; + + bool filesToArchiveCalled = false; + + var model = new RampArchivingDlgViewModel("Test App", "Test Title", "tst", + (a, b) => { filesToArchiveCalled = true; }, (k, f) => throw new NotImplementedException()); + var progress = new TestProgress("RAMP"); + bool customSummaryShown = false; + model.OverrideDisplayInitialSummary = (d, c) => { customSummaryShown = true; }; + bool otherDelegatesCalled = false; + model.GetOverriddenPreArchivingMessages = d => + { + otherDelegatesCalled = true; + return new List>(0); + }; + + model.OverrideGetFileGroupDisplayMessage = s => + { + otherDelegatesCalled = true; + return "frog lips"; + }; + await model.Initialize(progress, new CancellationToken()); + + Assert.True(filesToArchiveCalled); + Assert.True(customSummaryShown); + Assert.False(otherDelegatesCalled); + Assert.False(File.Exists(model.PackagePath)); + } + } + + [TestFixture] + [Category("Archiving")] + public class RampArchivingDlgViewModelWithFineGrainedOverridesForDisplayInitialSummarySetTests + { + /// ------------------------------------------------------------------------------------ + [Test] + public async Task DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides() + { + ErrorReport.IsOkToInteractWithUser = false; + + void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken) + { + model.AddFileGroup(String.Empty, new[] { "green.frog" }, "These messages should not be displayed"); + model.AddFileGroup("Toads", new[] { "red.toad", "blue.toad" }, "because in this test we do not create a package."); + } + + var model = new RampArchivingDlgViewModel("Test App", "Test Title", "tst", + SetFilesToArchive, (k, f) => throw new NotImplementedException()); + + var messagesDisplayed = new List>(); + + void ModelOnOnReportMessage(string msg, ArchivingDlgViewModel.MessageType type) + { + messagesDisplayed.Add(new Tuple(msg, type)); + } + + model.OnReportMessage += ModelOnOnReportMessage; + + IEnumerable> GetMessages(IDictionary, string>> arg) + { + yield return new Tuple( + "First pre-archiving message", Warning); + yield return new Tuple( + "Second pre-archiving message", Indented); + } + + model.GetOverriddenPreArchivingMessages = GetMessages; + model.InitialFileGroupDisplayMessageType = Success; + model.OverrideGetFileGroupDisplayMessage = s => (s == String.Empty) ? "Frogs" : $"Label: {s}"; + + + var progress = new TestProgress("RAMP"); + await model.Initialize(progress, new CancellationToken()); + + Assert.That(messagesDisplayed.Count, Is.EqualTo(8)); + Assert.That(messagesDisplayed[0].Item1, Is.EqualTo("Test implementation message for SearchingForArchiveUploadingProgram")); + Assert.That(messagesDisplayed[1].Item1, Is.EqualTo("First pre-archiving message")); + Assert.That(messagesDisplayed[1].Item2, Is.EqualTo(Warning)); + Assert.That(messagesDisplayed[2].Item1, Is.EqualTo("Second pre-archiving message")); + Assert.That(messagesDisplayed[2].Item2, Is.EqualTo(Indented)); + Assert.That(messagesDisplayed[3].Item1, Is.EqualTo("Frogs")); + Assert.That(messagesDisplayed[3].Item2, Is.EqualTo(Success)); + Assert.That(messagesDisplayed[4].Item1, Is.EqualTo("green.frog")); + Assert.That(messagesDisplayed[4].Item2, Is.EqualTo(Bullet)); + Assert.That(messagesDisplayed[5].Item1, Is.EqualTo("Label: Toads")); + Assert.That(messagesDisplayed[5].Item2, Is.EqualTo(Success)); + Assert.That(messagesDisplayed[6].Item1, Is.EqualTo("red.toad")); + Assert.That(messagesDisplayed[6].Item2, Is.EqualTo(Bullet)); + Assert.That(messagesDisplayed[7].Item1, Is.EqualTo("blue.toad")); + Assert.That(messagesDisplayed[7].Item2, Is.EqualTo(Bullet)); + Assert.False(File.Exists(model.PackagePath)); + } + } } diff --git a/SIL.Archiving/ArchivingDlgViewModel.cs b/SIL.Archiving/ArchivingDlgViewModel.cs index 29e9d52df..8a8afa825 100644 --- a/SIL.Archiving/ArchivingDlgViewModel.cs +++ b/SIL.Archiving/ArchivingDlgViewModel.cs @@ -99,7 +99,7 @@ public enum MessageType Error, /// Non-bold, indented with tab Detail, - /// New line + /// Like Normal, but with preceding new line Progress, /// Non-bold, indented 8 spaces, with bullet character (U+00B7) Bullet, @@ -210,11 +210,52 @@ public enum MessageType /// ------------------------------------------------------------------------------------ /// - /// Callback to allow application to handle display of initial summary in log box. If + /// Callback to allow application to handle display of initial summary (in log box). If /// the application implements this, then the default summary display will be suppressed. /// /// ------------------------------------------------------------------------------------ public Action, string>>, CancellationToken> OverrideDisplayInitialSummary { private get; set; } + + /// ------------------------------------------------------------------------------------ + /// + /// Delegate function that can be set to override the default pre-archiving message + /// shown in . By default, only a single message (as + /// determined by the ) is displayed, + /// so this override is particularly useful if an application needs to display more than + /// one message before the archival creation begins. + /// + /// This is used only in the normal default implementation of + /// , so if + /// is set, then there is no point in also + /// setting this delegate. + /// ------------------------------------------------------------------------------------ + public Func, string>>, IEnumerable>> GetOverriddenPreArchivingMessages { private get; set; } + + /// ------------------------------------------------------------------------------------ + /// + /// This can be set to override the default used for displaying + /// information about each file group in . The default + /// type is . + /// + /// This is used only in the normal default implementation of + /// , so if + /// is set, then there is no point in also + /// setting this property. + /// ------------------------------------------------------------------------------------ + public MessageType InitialFileGroupDisplayMessageType { private get; set; } = MessageType.Indented; + + /// ------------------------------------------------------------------------------------ + /// + /// Delegate function that can be set to override the default "message" displayed for + /// file groups in . The default is simply the file + /// groupId (as set in . + /// + /// This is used only in the normal default implementation of + /// , so if + /// is set, then there is no point in also + /// setting this delegate. + /// ------------------------------------------------------------------------------------ + public Func OverrideGetFileGroupDisplayMessage { private get; set; } #endregion #region construction and initialization @@ -225,8 +266,8 @@ public enum MessageType /// Identifier (used as filename) for the package being created /// Delegate to request client to call methods to set /// which files should be archived (this is deferred to allow display of progress - /// message). Clients will normally do this by calling AddFileGroup one or more times. - /// + /// message). Clients will normally do this by calling one or + /// more times. /// ------------------------------------------------------------------------------------ protected ArchivingDlgViewModel(string appName, string title, string id, Action setFilesToArchive) @@ -268,41 +309,64 @@ await Task.Run(() => public abstract int CalculateMaxProgressBarValue(); /// ------------------------------------------------------------------------------------ - public virtual void AddFileGroup(string groupId, IEnumerable files, string progressMessage) + /// + /// Adds a group of related files to be included when creating the archive package. + /// + /// A string that uniquely identifies the group of files. + /// The collection fo files (paths) + /// A progress message that would be + /// appropriate to display (if relevant to the type of archive package) when the file is + /// actually being added. + /// Thrown if a duplicate file group ID is specified + /// + /// ------------------------------------------------------------------------------------ + public virtual void AddFileGroup(string groupId, IEnumerable files, + string addingToArchiveProgressMessage) { Guard.AgainstNull(groupId, nameof(groupId)); if (FileLists.ContainsKey(groupId)) throw new ArgumentException("Duplicate file group ID: " + groupId, nameof(groupId)); - FileLists[groupId] = Tuple.Create(files, progressMessage); + FileLists[groupId] = Tuple.Create(files, addingToArchiveProgressMessage); } /// ------------------------------------------------------------------------------------ private void DisplayInitialSummary(CancellationToken cancellationToken) { if (OverrideDisplayInitialSummary != null) + { OverrideDisplayInitialSummary(FileLists, cancellationToken); + return; + } + + foreach (var message in AdditionalMessages) + DisplayMessage(message.Key + "\n", message.Value); + + if (GetOverriddenPreArchivingMessages != null) + { + foreach (var msg in GetOverriddenPreArchivingMessages(FileLists)) + ReportProgress(msg.Item1, msg.Item2, cancellationToken); + } else + ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), MessageType.Normal, + cancellationToken); + + foreach (var kvp in FileLists) { - ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), MessageType.Normal, cancellationToken); + if (cancellationToken.IsCancellationRequested) + throw new OperationCanceledException(); - if (OnReportMessage != null) - { - foreach (var kvp in FileLists) - { - string msg = FileGroupDisplayMessage(kvp.Key); - if (msg != Empty) - OnReportMessage(msg, MessageType.Indented); + string msg = FileGroupDisplayMessage(kvp.Key); + if (msg != Empty) + DisplayMessage(msg, InitialFileGroupDisplayMessageType); - foreach (var file in kvp.Value.Item1) - OnReportMessage(Path.GetFileName(file), MessageType.Bullet); - } - } + foreach (var file in kvp.Value.Item1) + DisplayMessage(Path.GetFileName(file), MessageType.Bullet); } } protected virtual string FileGroupDisplayMessage(string groupKey) { - return groupKey; + return OverrideGetFileGroupDisplayMessage == null ? groupKey : OverrideGetFileGroupDisplayMessage(groupKey); } #endregion diff --git a/TestApps/ArchivingTestApp/MainForm.cs b/TestApps/ArchivingTestApp/MainForm.cs index b0767f7e4..f66b09e85 100644 --- a/TestApps/ArchivingTestApp/MainForm.cs +++ b/TestApps/ArchivingTestApp/MainForm.cs @@ -32,8 +32,17 @@ private void m_btnRamp_Click(object sender, EventArgs e) var title = GetTitle(); var model = new RampArchivingDlgViewModel(kAppName, title, title.ToLatinOnly("~", "_", ""), SetFilesToArchive, GetFileDescription); + if (ModifierKeys == Keys.Shift) + { + model.OverrideGetFileGroupDisplayMessage = s => $"override: {s}"; + model.GetOverriddenPreArchivingMessages = d => + new[] {new Tuple($"Count: {d.Count}", ArchivingDlgViewModel.MessageType.Error) }; + model.InitialFileGroupDisplayMessageType = + ArchivingDlgViewModel.MessageType.Warning; + } + using (var rampArchiveDlg = new ArchivingDlg(model, LocalizationManager.GetString( - "ArchivingTestApp.MainForm.AdditionalArchiveProcessInfo", "This is just a test."))) + "ArchivingTestApp.MainForm.AdditionalArchiveProcessInfo", "This is just a test."))) { rampArchiveDlg.ShowDialog(this); } From 75536937a9b63388cc5d4d8c546a0683bba2b532 Mon Sep 17 00:00:00 2001 From: tombogle Date: Fri, 4 Oct 2024 10:32:59 -0400 Subject: [PATCH 2/7] Improved/added unit tests for archiving view models --- .../IMDIArchivingDlgViewModelTests.cs | 102 +++++++++++++++++- .../RampArchivingDlgViewModelTests.cs | 29 ++--- 2 files changed, 109 insertions(+), 22 deletions(-) diff --git a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs index f14166905..bee0f9df0 100644 --- a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -6,6 +7,8 @@ using SIL.Archiving.IMDI; using SIL.Reporting; using SIL.TestUtilities; +using static SIL.Archiving.ArchivingDlgViewModel.MessageType; +using CancellationToken = System.Threading.CancellationToken; namespace SIL.Archiving.Tests { @@ -100,7 +103,7 @@ public void PathIsAccessible_NonexistentPath_False() Assert.False(writable); Assert.AreEqual(1, m_messages.Count); Assert.AreEqual("Test implementation message for PathNotWritable", m_messages[0].MsgText); - Assert.AreEqual(ArchivingDlgViewModel.MessageType.Warning, m_messages[0].MsgType); + Assert.AreEqual(Warning, m_messages[0].MsgType); } [Test] @@ -112,7 +115,7 @@ public void IsPathWritable_WindowsInvalidPath_False() Assert.False(writable); Assert.AreEqual(1, m_messages.Count); Assert.IsTrue(m_messages[0].MsgText.Contains("path"), "Error should mention the path in its explanation."); - Assert.AreEqual(ArchivingDlgViewModel.MessageType.Warning, m_messages[0].MsgType); + Assert.AreEqual(Warning, m_messages[0].MsgType); } [Test] @@ -123,7 +126,7 @@ public void IsPathWritable_IllegalCharacterInPath_False() Assert.False(writable); Assert.AreEqual(1, m_messages.Count); Assert.IsTrue(m_messages[0].MsgText.Contains("path"), "Error should mention the path in its explanation."); - Assert.AreEqual(ArchivingDlgViewModel.MessageType.Warning, m_messages[0].MsgType); + Assert.AreEqual(Warning, m_messages[0].MsgType); } #endregion @@ -263,4 +266,97 @@ public void SetAbstract_MultipleLanguages_AddsDescriptionToCorpusImdiFile() #endregion } + + [TestFixture] + [Category("Archiving")] + public class IMDIArchivingDlgViewModelWithOverrideDisplayInitialSummarySetTests + { + /// ------------------------------------------------------------------------------------ + [Test] + public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted() + { + ErrorReport.IsOkToInteractWithUser = false; + + bool filesToArchiveCalled = false; + + 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.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()); + + Assert.True(filesToArchiveCalled); + Assert.That(customSummaryShown, Is.EqualTo(1)); + } + } + + [TestFixture] + [Category("Archiving")] + public class IMDIArchivingDlgViewModelWithFineGrainedOverridesForDisplayInitialSummarySetTests + { + /// ------------------------------------------------------------------------------------ + [Test] + public async Task DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides() + { + ErrorReport.IsOkToInteractWithUser = false; + + void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken) + { + model.AddFileGroup(String.Empty, new[] { "green.frog" }, "These messages should not be displayed"); + model.AddFileGroup("Toads", new[] { "red.toad", "blue.toad" }, "because in this test we do not create a package."); + } + + var model = new IMDIArchivingDlgViewModel("Test App", "Test Title", "tst", true, + SetFilesToArchive, "unused"); + + var messagesDisplayed = new List>(); + + void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) + { + messagesDisplayed.Add(new Tuple(msg, type)); + } + + model.OnReportMessage += ReportMessage; + + IEnumerable> GetMessages(IDictionary, string>> arg) + { + yield return new Tuple( + "First pre-archiving message", Warning); + yield return new Tuple( + "Second pre-archiving message", Indented); + } + + model.GetOverriddenPreArchivingMessages = GetMessages; + model.InitialFileGroupDisplayMessageType = Success; + model.OverrideGetFileGroupDisplayMessage = s => (s == String.Empty) ? "Frogs" : $"Label: {s}"; + + + var progress = new TestProgress("RAMP"); + await model.Initialize(progress, new CancellationToken()); + + Assert.That(messagesDisplayed.Count, Is.EqualTo(7)); + Assert.That(messagesDisplayed[0].Item1, Is.EqualTo("First pre-archiving message")); + Assert.That(messagesDisplayed[0].Item2, Is.EqualTo(Warning)); + Assert.That(messagesDisplayed[1].Item1, Is.EqualTo("Second pre-archiving message")); + Assert.That(messagesDisplayed[1].Item2, Is.EqualTo(Indented)); + Assert.That(messagesDisplayed[2].Item1, Is.EqualTo("Frogs")); + Assert.That(messagesDisplayed[2].Item2, Is.EqualTo(Success)); + Assert.That(messagesDisplayed[3].Item1, Is.EqualTo("green.frog")); + Assert.That(messagesDisplayed[3].Item2, Is.EqualTo(Bullet)); + Assert.That(messagesDisplayed[4].Item1, Is.EqualTo("Label: Toads")); + Assert.That(messagesDisplayed[4].Item2, Is.EqualTo(Success)); + Assert.That(messagesDisplayed[5].Item1, Is.EqualTo("red.toad")); + 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)); + } + } } diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index 240a89ffd..f63f37d59 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -753,26 +753,17 @@ 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"); - bool customSummaryShown = false; - model.OverrideDisplayInitialSummary = (d, c) => { customSummaryShown = true; }; - bool otherDelegatesCalled = false; - model.GetOverriddenPreArchivingMessages = d => - { - otherDelegatesCalled = true; - return new List>(0); - }; + var customSummaryShown = 0; + model.OverrideDisplayInitialSummary = (d, c) => { customSummaryShown++; }; + 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.OverrideGetFileGroupDisplayMessage = s => - { - otherDelegatesCalled = true; - return "frog lips"; - }; - await model.Initialize(progress, new CancellationToken()); + await model.Initialize(new TestProgress("RAMP"), new CancellationToken()); Assert.True(filesToArchiveCalled); - Assert.True(customSummaryShown); - Assert.False(otherDelegatesCalled); + Assert.That(customSummaryShown, Is.EqualTo(1)); Assert.False(File.Exists(model.PackagePath)); } } @@ -798,12 +789,12 @@ void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellati var messagesDisplayed = new List>(); - void ModelOnOnReportMessage(string msg, ArchivingDlgViewModel.MessageType type) + void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) { messagesDisplayed.Add(new Tuple(msg, type)); } - model.OnReportMessage += ModelOnOnReportMessage; + model.OnReportMessage += ReportMessage; IEnumerable> GetMessages(IDictionary, string>> arg) { From fe59bbf22fa27735fcb47b293eb874d63808c0e2 Mon Sep 17 00:00:00 2001 From: tombogle Date: Fri, 4 Oct 2024 11:31:18 -0400 Subject: [PATCH 3/7] Further unit test improvements. Prevented incrementing progress for each of multiple multiple pre-archiving messages --- .../IMDIArchivingDlgViewModelTests.cs | 32 ++++++++++++++++--- .../RampArchivingDlgViewModelTests.cs | 30 ++++++++++++++--- SIL.Archiving/ArchivingDlgViewModel.cs | 11 ++++++- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs index bee0f9df0..dc83a73c5 100644 --- a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs @@ -281,9 +281,15 @@ 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( @@ -291,10 +297,18 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau 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)); } } @@ -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")); @@ -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)); } } } diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index f63f37d59..82dd45346 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -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)); } } @@ -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")); @@ -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)); } } } diff --git a/SIL.Archiving/ArchivingDlgViewModel.cs b/SIL.Archiving/ArchivingDlgViewModel.cs index 8a8afa825..e8d5eee58 100644 --- a/SIL.Archiving/ArchivingDlgViewModel.cs +++ b/SIL.Archiving/ArchivingDlgViewModel.cs @@ -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, From 92ba8860f2b7799c633519ab4b2bc57d759cdfe6 Mon Sep 17 00:00:00 2001 From: tombogle Date: Fri, 4 Oct 2024 13:45:31 -0400 Subject: [PATCH 4/7] Made IMDIArchivingDlgViewModelTests public. TEMP: Added some console.log statements to try to see what's happening with TC tests --- .../IMDIArchivingDlgViewModelTests.cs | 8 ++++++-- .../RampArchivingDlgViewModelTests.cs | 8 ++++++++ SIL.Archiving/ArchivingDlgViewModel.cs | 18 ++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs index dc83a73c5..d1e7e036d 100644 --- a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; using System.Xml; using NUnit.Framework; @@ -15,7 +14,7 @@ namespace SIL.Archiving.Tests [TestFixture] [OfflineSldr] [Category("Archiving")] - internal class IMDIArchivingDlgViewModelTests + public class IMDIArchivingDlgViewModelTests { private class MessageData { @@ -70,6 +69,7 @@ public void TearDown() [Test] public void NormalizeFilename_FileName_NormalizedFileName() { + Console.WriteLine($"IMDI Tests TEMP: {nameof(NormalizeFilename_FileName_NormalizedFileName)}"); const string fileName = "My# \nFile %\t Name&^%.mp3"; var normalized = _model.NormalizeFilename("", fileName); Assert.AreEqual("My+File+Name_.mp3", normalized); @@ -275,6 +275,8 @@ public class IMDIArchivingDlgViewModelWithOverrideDisplayInitialSummarySetTests [Test] public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted() { + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)}"); + ErrorReport.IsOkToInteractWithUser = false; bool filesToArchiveCalled = false; @@ -320,6 +322,8 @@ public class IMDIArchivingDlgViewModelWithFineGrainedOverridesForDisplayInitialS [Test] public async Task DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides() { + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)}"); + ErrorReport.IsOkToInteractWithUser = false; void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken) diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index 82dd45346..44c79ef6d 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -759,6 +759,7 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau model.OverrideDisplayInitialSummary = (d, c) => { + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)} overriding initial display"); customSummaryShown++; progress.IncrementProgress(); }; @@ -769,7 +770,9 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau try { + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)} before SUT"); await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false); + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)} after SUT"); } catch (Exception ex) { @@ -806,6 +809,7 @@ void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellati void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) { + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} reporting {msg}"); messagesDisplayed.Add(new Tuple(msg, type)); } @@ -813,6 +817,8 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) IEnumerable> GetMessages(IDictionary, string>> arg) { + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} getting pre-archiving messages"); + yield return new Tuple( "First pre-archiving message", Warning); yield return new Tuple( @@ -826,7 +832,9 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) var progress = new TestProgress("RAMP"); try { + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} before SUT"); await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false); + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} after SUT"); } catch (Exception ex) { diff --git a/SIL.Archiving/ArchivingDlgViewModel.cs b/SIL.Archiving/ArchivingDlgViewModel.cs index e8d5eee58..e6a3abcaa 100644 --- a/SIL.Archiving/ArchivingDlgViewModel.cs +++ b/SIL.Archiving/ArchivingDlgViewModel.cs @@ -332,15 +332,21 @@ public virtual void AddFileGroup(string groupId, IEnumerable files, /// ------------------------------------------------------------------------------------ private void DisplayInitialSummary(CancellationToken cancellationToken) { + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} start"); + if (OverrideDisplayInitialSummary != null) { OverrideDisplayInitialSummary(FileLists, cancellationToken); return; } + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after override"); + foreach (var message in AdditionalMessages) DisplayMessage(message.Key + "\n", message.Value); + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after additional"); + if (GetOverriddenPreArchivingMessages != null) { bool firstMsg = true; @@ -354,10 +360,16 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) else DisplayMessage(msg.Item1, msg.Item2); } + + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after overridden Pre-Archiving messages"); } else - ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), MessageType.Normal, - cancellationToken); + { + ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), + MessageType.Normal, cancellationToken); + + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after normal Pre-Archiving message"); + } foreach (var kvp in FileLists) { @@ -371,6 +383,8 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) foreach (var file in kvp.Value.Item1) DisplayMessage(Path.GetFileName(file), MessageType.Bullet); } + + Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} end"); } protected virtual string FileGroupDisplayMessage(string groupKey) From e0829d9b115b4c938a32351a02eaf6921ee444bd Mon Sep 17 00:00:00 2001 From: tombogle Date: Fri, 4 Oct 2024 16:02:49 -0400 Subject: [PATCH 5/7] TEMP: Additional diagnostic console messages --- .../IMDIArchivingDlgViewModelTests.cs | 1 - .../RampArchivingDlgViewModelTests.cs | 4 +++ SIL.Archiving/ArchivingDlgViewModel.cs | 28 ++++++++++++++----- SIL.Archiving/RampArchivingDlgViewModel.cs | 5 ++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs index d1e7e036d..6bc5dde18 100644 --- a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs @@ -69,7 +69,6 @@ public void TearDown() [Test] public void NormalizeFilename_FileName_NormalizedFileName() { - Console.WriteLine($"IMDI Tests TEMP: {nameof(NormalizeFilename_FileName_NormalizedFileName)}"); const string fileName = "My# \nFile %\t Name&^%.mp3"; var normalized = _model.NormalizeFilename("", fileName); Assert.AreEqual("My+File+Name_.mp3", normalized); diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index 44c79ef6d..6141e3ef5 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -798,8 +798,12 @@ public async Task DisplayInitialSummary_OverridenPropertiesForDisplayInitialSumm void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken) { + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} starting to set files to archive"); + model.AddFileGroup(String.Empty, new[] { "green.frog" }, "These messages should not be displayed"); model.AddFileGroup("Toads", new[] { "red.toad", "blue.toad" }, "because in this test we do not create a package."); + + Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} done setting files to archive"); } var model = new RampArchivingDlgViewModel("Test App", "Test Title", "tst", diff --git a/SIL.Archiving/ArchivingDlgViewModel.cs b/SIL.Archiving/ArchivingDlgViewModel.cs index e6a3abcaa..15ded1ad4 100644 --- a/SIL.Archiving/ArchivingDlgViewModel.cs +++ b/SIL.Archiving/ArchivingDlgViewModel.cs @@ -284,22 +284,36 @@ protected ArchivingDlgViewModel(string appName, string title, string id, public async Task Initialize(IArchivingProgressDisplay progress, CancellationToken cancellationToken) { Progress = progress ?? throw new ArgumentNullException(nameof(progress)); - + + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} start"); + if (!DoArchiveSpecificInitialization()) return false; + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} archive-specific initialization complete"); + await SetFilesToArchive(cancellationToken); + + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} {nameof(SetFilesToArchive)} complete"); + DisplayInitialSummary(cancellationToken); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} end"); + return true; } protected virtual async Task SetFilesToArchive(CancellationToken cancellationToken) { + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(SetFilesToArchive)} start"); + await Task.Run(() => { _setFilesToArchive(this, cancellationToken); + Console.WriteLine($"{ArchiveType} Tests TEMP: calling _setFilesToArchive finished"); }, cancellationToken); + + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(SetFilesToArchive)} end"); } /// ------------------------------------------------------------------------------------ @@ -332,7 +346,7 @@ public virtual void AddFileGroup(string groupId, IEnumerable files, /// ------------------------------------------------------------------------------------ private void DisplayInitialSummary(CancellationToken cancellationToken) { - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} start"); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} start"); if (OverrideDisplayInitialSummary != null) { @@ -340,12 +354,12 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) return; } - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after override"); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after override"); foreach (var message in AdditionalMessages) DisplayMessage(message.Key + "\n", message.Value); - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after additional"); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after additional"); if (GetOverriddenPreArchivingMessages != null) { @@ -361,14 +375,14 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) DisplayMessage(msg.Item1, msg.Item2); } - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after overridden Pre-Archiving messages"); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after overridden Pre-Archiving messages"); } else { ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), MessageType.Normal, cancellationToken); - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} after normal Pre-Archiving message"); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after normal Pre-Archiving message"); } foreach (var kvp in FileLists) @@ -384,7 +398,7 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) DisplayMessage(Path.GetFileName(file), MessageType.Bullet); } - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary)} end"); + Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} end"); } protected virtual string FileGroupDisplayMessage(string groupKey) diff --git a/SIL.Archiving/RampArchivingDlgViewModel.cs b/SIL.Archiving/RampArchivingDlgViewModel.cs index cd5780a83..e01e94456 100644 --- a/SIL.Archiving/RampArchivingDlgViewModel.cs +++ b/SIL.Archiving/RampArchivingDlgViewModel.cs @@ -335,8 +335,12 @@ public RampArchivingDlgViewModel(string appName, string title, string id, protected override async Task SetFilesToArchive(CancellationToken cancellationToken) { + Console.WriteLine($"{ArchiveType} Tests TEMP: {GetType().Name}.{nameof(SetFilesToArchive)} start"); + await base.SetFilesToArchive(cancellationToken); + Console.WriteLine($"{ArchiveType} Tests TEMP: {GetType().Name}.{nameof(SetFilesToArchive)} done calling base"); + if (cancellationToken.IsCancellationRequested) throw new OperationCanceledException(); @@ -346,6 +350,7 @@ protected override async Task SetFilesToArchive(CancellationToken cancellationTo Path.GetFileName(fileList.Value.Item1.First())); _progressMessages[normalizedName] = fileList.Value.Item2; } + Console.WriteLine($"{ArchiveType} Tests TEMP: {GetType().Name}.{nameof(SetFilesToArchive)} end"); } /// ------------------------------------------------------------------------------------ From 680d7835c4112bcbdeb8888363e493d4a5bb3212 Mon Sep 17 00:00:00 2001 From: tombogle Date: Mon, 7 Oct 2024 10:17:44 -0400 Subject: [PATCH 6/7] Made improvements to code based on review --- .../IMDIArchivingDlgViewModelTests.cs | 25 +++++++---------- .../RampArchivingDlgViewModelTests.cs | 28 ++++++++----------- SIL.Archiving/ArchivingDlgViewModel.cs | 2 +- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs index 6bc5dde18..4580bf341 100644 --- a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs @@ -366,21 +366,16 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) 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")); - Assert.That(messagesDisplayed[0].Item2, Is.EqualTo(Warning)); - Assert.That(messagesDisplayed[1].Item1, Is.EqualTo("Second pre-archiving message")); - Assert.That(messagesDisplayed[1].Item2, Is.EqualTo(Indented)); - Assert.That(messagesDisplayed[2].Item1, Is.EqualTo("Frogs")); - Assert.That(messagesDisplayed[2].Item2, Is.EqualTo(Success)); - Assert.That(messagesDisplayed[3].Item1, Is.EqualTo("green.frog")); - Assert.That(messagesDisplayed[3].Item2, Is.EqualTo(Bullet)); - Assert.That(messagesDisplayed[4].Item1, Is.EqualTo("Label: Toads")); - Assert.That(messagesDisplayed[4].Item2, Is.EqualTo(Success)); - Assert.That(messagesDisplayed[5].Item1, Is.EqualTo("red.toad")); - 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(messagesDisplayed, Is.EqualTo(new[] + { + ("First pre-archiving message", Warning).ToTuple(), + ("Second pre-archiving message", Indented).ToTuple(), + ("Frogs", Success).ToTuple(), + ("green.frog", Bullet).ToTuple(), + ("Label: Toads", Success).ToTuple(), + ("red.toad", Bullet).ToTuple(), + ("blue.toad", Bullet).ToTuple() + })); Assert.That(progress.Step, Is.EqualTo(1)); } } diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index 6141e3ef5..6b9f85e8a 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -845,22 +845,18 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) 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")); - Assert.That(messagesDisplayed[1].Item1, Is.EqualTo("First pre-archiving message")); - Assert.That(messagesDisplayed[1].Item2, Is.EqualTo(Warning)); - Assert.That(messagesDisplayed[2].Item1, Is.EqualTo("Second pre-archiving message")); - Assert.That(messagesDisplayed[2].Item2, Is.EqualTo(Indented)); - Assert.That(messagesDisplayed[3].Item1, Is.EqualTo("Frogs")); - Assert.That(messagesDisplayed[3].Item2, Is.EqualTo(Success)); - Assert.That(messagesDisplayed[4].Item1, Is.EqualTo("green.frog")); - Assert.That(messagesDisplayed[4].Item2, Is.EqualTo(Bullet)); - Assert.That(messagesDisplayed[5].Item1, Is.EqualTo("Label: Toads")); - Assert.That(messagesDisplayed[5].Item2, Is.EqualTo(Success)); - Assert.That(messagesDisplayed[6].Item1, Is.EqualTo("red.toad")); - Assert.That(messagesDisplayed[6].Item2, Is.EqualTo(Bullet)); - Assert.That(messagesDisplayed[7].Item1, Is.EqualTo("blue.toad")); - Assert.That(messagesDisplayed[7].Item2, Is.EqualTo(Bullet)); + Assert.That(messagesDisplayed, Is.EqualTo(new[] + { + ("Test implementation message for SearchingForArchiveUploadingProgram", ArchivingDlgViewModel.MessageType.Volatile).ToTuple(), + ("First pre-archiving message", Warning).ToTuple(), + ("Second pre-archiving message", Indented).ToTuple(), + ("Frogs", Success).ToTuple(), + ("green.frog", Bullet).ToTuple(), + ("Label: Toads", Success).ToTuple(), + ("red.toad", Bullet).ToTuple(), + ("blue.toad", Bullet).ToTuple() + })); + Assert.False(File.Exists(model.PackagePath)); Assert.That(progress.Step, Is.EqualTo(1)); } diff --git a/SIL.Archiving/ArchivingDlgViewModel.cs b/SIL.Archiving/ArchivingDlgViewModel.cs index 15ded1ad4..a477d7f45 100644 --- a/SIL.Archiving/ArchivingDlgViewModel.cs +++ b/SIL.Archiving/ArchivingDlgViewModel.cs @@ -403,7 +403,7 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) protected virtual string FileGroupDisplayMessage(string groupKey) { - return OverrideGetFileGroupDisplayMessage == null ? groupKey : OverrideGetFileGroupDisplayMessage(groupKey); + return OverrideGetFileGroupDisplayMessage?.Invoke(groupKey) ?? groupKey; } #endregion From 599884c0a69f8553c5c07cb36edf9d0c064ffdb4 Mon Sep 17 00:00:00 2001 From: tombogle Date: Mon, 7 Oct 2024 10:39:15 -0400 Subject: [PATCH 7/7] Fixed problem with RampArchivingDlgViewModelTests. Removed TEMP code --- .../IMDIArchivingDlgViewModelTests.cs | 4 --- .../RampArchivingDlgViewModelTests.cs | 35 ++++++++++--------- SIL.Archiving/ArchivingDlgViewModel.cs | 24 ------------- SIL.Archiving/RampArchivingDlgViewModel.cs | 5 --- 4 files changed, 19 insertions(+), 49 deletions(-) diff --git a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs index 4580bf341..6731cb1e2 100644 --- a/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/IMDIArchivingDlgViewModelTests.cs @@ -274,8 +274,6 @@ public class IMDIArchivingDlgViewModelWithOverrideDisplayInitialSummarySetTests [Test] public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted() { - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)}"); - ErrorReport.IsOkToInteractWithUser = false; bool filesToArchiveCalled = false; @@ -321,8 +319,6 @@ public class IMDIArchivingDlgViewModelWithFineGrainedOverridesForDisplayInitialS [Test] public async Task DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides() { - Console.WriteLine($"IMDI Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)}"); - ErrorReport.IsOkToInteractWithUser = false; void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken) diff --git a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs index 6b9f85e8a..7783b3340 100644 --- a/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs +++ b/SIL.Archiving.Tests/RampArchivingDlgViewModelTests.cs @@ -739,6 +739,22 @@ private void IgnoreTestIfRampIsNotInstalled() #endregion } + internal class TestRampArchivingDlgViewModel : RampArchivingDlgViewModel + { + public TestRampArchivingDlgViewModel( + Action setFilesToArchive) : + base("Test App", "Test Title", "tst", setFilesToArchive, + (k, f) => throw new NotImplementedException()) + { + } + + protected override bool DoArchiveSpecificInitialization() + { + DisplayMessage("Base implementation overridden", MessageType.Volatile); + return true; + } + } + [TestFixture] [Category("Archiving")] public class RampArchivingDlgViewModelWithOverrideDisplayInitialSummarySetTests @@ -751,15 +767,13 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau bool filesToArchiveCalled = false; - var model = new RampArchivingDlgViewModel("Test App", "Test Title", "tst", - (a, b) => { filesToArchiveCalled = true; }, (k, f) => throw new NotImplementedException()); + var model = new TestRampArchivingDlgViewModel((a, b) => { filesToArchiveCalled = true; }); var progress = new TestProgress("RAMP"); var customSummaryShown = 0; model.OverrideDisplayInitialSummary = (d, c) => { - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)} overriding initial display"); customSummaryShown++; progress.IncrementProgress(); }; @@ -770,9 +784,7 @@ public async Task DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_Defau try { - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)} before SUT"); await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false); - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverrideDisplayInitialSummaryIsSet_DefaultBehaviorOmitted)} after SUT"); } catch (Exception ex) { @@ -798,22 +810,17 @@ public async Task DisplayInitialSummary_OverridenPropertiesForDisplayInitialSumm void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken) { - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} starting to set files to archive"); - model.AddFileGroup(String.Empty, new[] { "green.frog" }, "These messages should not be displayed"); model.AddFileGroup("Toads", new[] { "red.toad", "blue.toad" }, "because in this test we do not create a package."); - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} done setting files to archive"); } - var model = new RampArchivingDlgViewModel("Test App", "Test Title", "tst", - SetFilesToArchive, (k, f) => throw new NotImplementedException()); + var model = new TestRampArchivingDlgViewModel(SetFilesToArchive); var messagesDisplayed = new List>(); void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) { - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} reporting {msg}"); messagesDisplayed.Add(new Tuple(msg, type)); } @@ -821,8 +828,6 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) IEnumerable> GetMessages(IDictionary, string>> arg) { - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} getting pre-archiving messages"); - yield return new Tuple( "First pre-archiving message", Warning); yield return new Tuple( @@ -836,9 +841,7 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) var progress = new TestProgress("RAMP"); try { - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} before SUT"); await model.Initialize(progress, new CancellationToken()).ConfigureAwait(false); - Console.WriteLine($"RAMP Tests TEMP: {nameof(DisplayInitialSummary_OverridenPropertiesForDisplayInitialSummaryAreSet_MessagesReflectOverrides)} after SUT"); } catch (Exception ex) { @@ -847,7 +850,7 @@ void ReportMessage(string msg, ArchivingDlgViewModel.MessageType type) Assert.That(messagesDisplayed, Is.EqualTo(new[] { - ("Test implementation message for SearchingForArchiveUploadingProgram", ArchivingDlgViewModel.MessageType.Volatile).ToTuple(), + ("Base implementation overridden", ArchivingDlgViewModel.MessageType.Volatile).ToTuple(), ("First pre-archiving message", Warning).ToTuple(), ("Second pre-archiving message", Indented).ToTuple(), ("Frogs", Success).ToTuple(), diff --git a/SIL.Archiving/ArchivingDlgViewModel.cs b/SIL.Archiving/ArchivingDlgViewModel.cs index a477d7f45..09e0a5a8c 100644 --- a/SIL.Archiving/ArchivingDlgViewModel.cs +++ b/SIL.Archiving/ArchivingDlgViewModel.cs @@ -285,35 +285,23 @@ public async Task Initialize(IArchivingProgressDisplay progress, Cancellat { Progress = progress ?? throw new ArgumentNullException(nameof(progress)); - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} start"); - if (!DoArchiveSpecificInitialization()) return false; - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} archive-specific initialization complete"); - await SetFilesToArchive(cancellationToken); - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} {nameof(SetFilesToArchive)} complete"); - DisplayInitialSummary(cancellationToken); - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(Initialize)} end"); - return true; } protected virtual async Task SetFilesToArchive(CancellationToken cancellationToken) { - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(SetFilesToArchive)} start"); - await Task.Run(() => { _setFilesToArchive(this, cancellationToken); - Console.WriteLine($"{ArchiveType} Tests TEMP: calling _setFilesToArchive finished"); }, cancellationToken); - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(SetFilesToArchive)} end"); } /// ------------------------------------------------------------------------------------ @@ -346,21 +334,15 @@ public virtual void AddFileGroup(string groupId, IEnumerable files, /// ------------------------------------------------------------------------------------ private void DisplayInitialSummary(CancellationToken cancellationToken) { - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} start"); - if (OverrideDisplayInitialSummary != null) { OverrideDisplayInitialSummary(FileLists, cancellationToken); return; } - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after override"); - foreach (var message in AdditionalMessages) DisplayMessage(message.Key + "\n", message.Value); - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after additional"); - if (GetOverriddenPreArchivingMessages != null) { bool firstMsg = true; @@ -374,15 +356,11 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) else DisplayMessage(msg.Item1, msg.Item2); } - - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after overridden Pre-Archiving messages"); } else { ReportProgress(Progress.GetMessage(StringId.PreArchivingStatus), MessageType.Normal, cancellationToken); - - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} after normal Pre-Archiving message"); } foreach (var kvp in FileLists) @@ -397,8 +375,6 @@ private void DisplayInitialSummary(CancellationToken cancellationToken) foreach (var file in kvp.Value.Item1) DisplayMessage(Path.GetFileName(file), MessageType.Bullet); } - - Console.WriteLine($"{ArchiveType} Tests TEMP: {nameof(DisplayInitialSummary)} end"); } protected virtual string FileGroupDisplayMessage(string groupKey) diff --git a/SIL.Archiving/RampArchivingDlgViewModel.cs b/SIL.Archiving/RampArchivingDlgViewModel.cs index e01e94456..cd5780a83 100644 --- a/SIL.Archiving/RampArchivingDlgViewModel.cs +++ b/SIL.Archiving/RampArchivingDlgViewModel.cs @@ -335,12 +335,8 @@ public RampArchivingDlgViewModel(string appName, string title, string id, protected override async Task SetFilesToArchive(CancellationToken cancellationToken) { - Console.WriteLine($"{ArchiveType} Tests TEMP: {GetType().Name}.{nameof(SetFilesToArchive)} start"); - await base.SetFilesToArchive(cancellationToken); - Console.WriteLine($"{ArchiveType} Tests TEMP: {GetType().Name}.{nameof(SetFilesToArchive)} done calling base"); - if (cancellationToken.IsCancellationRequested) throw new OperationCanceledException(); @@ -350,7 +346,6 @@ protected override async Task SetFilesToArchive(CancellationToken cancellationTo Path.GetFileName(fileList.Value.Item1.First())); _progressMessages[normalizedName] = fileList.Value.Item2; } - Console.WriteLine($"{ArchiveType} Tests TEMP: {GetType().Name}.{nameof(SetFilesToArchive)} end"); } /// ------------------------------------------------------------------------------------