public void RemoveMemoTest() { string defaultMemo = "Description for memo test reminder"; string removedMemo = ""; List <TrackedFile> files = FileManagerDAL.GetFiles(); if (files != null) { TrackedFile file = files[0]; // Store the current file memo string currentMemo = file.FileMemo ?? ""; // Update the file to default text file.UpdateMemo(defaultMemo); // Verify file has the default memo text Assert.AreEqual(defaultMemo, file.FileMemo); // Remove the file memo file.RemoveMemo(); // Verify the file memo has been removed Assert.AreEqual(removedMemo, file.FileMemo); // Update the file memo to the original memo text file.UpdateMemo(currentMemo); // Verify the file memo has the original memo text Assert.AreEqual(currentMemo, file.FileMemo); } }
private void btnUpdate_Click(object sender, EventArgs e) { string prompt = "Check a single file to update its memo."; bool isSelected = ForceSingleSelection(prompt); if (!isSelected) { return; } try { // Get selected item / row var selected = MainListView.CheckedItems; if (selected.Count != 1) { return; } ListViewItem row = selected[0]; // Retrieve Tracked File for selected row int fileID = (int)row.Tag; TrackedFile tf = FileManager.GetFile(fileID); if (tf == null) { return; } // Compare memo field with existing memo string newMemo = txtMemo.Text.Trim(); string originalMemo = tf.FileMemo ?? ""; bool isSameMemo = (newMemo == originalMemo); if (isSameMemo) { return; } // Remove memo if new is empty. Update otherwise. bool wantsRemoved = (string.IsNullOrEmpty(newMemo)); if (wantsRemoved) { bool wasRemoved = tf.RemoveMemo(); if (wasRemoved) { LogMemoRemoval(tf.FileID, originalMemo); string removedPrompt = $"Memo removed for\n\n{tf.Filename}.{tf.FileExtension}"; Messenger.Show(removedPrompt, caption); } } else { bool wasUpdated = tf.UpdateMemo(newMemo); if (wasUpdated) { LogMemoChanged(tf.FileID, originalMemo, newMemo); string updatedPrompt = $"Memo updated for\n\n{tf.Filename}.{tf.FileExtension}"; Messenger.Show(updatedPrompt, caption); } } } catch (SqlException) { Messenger.ShowDbMsg(); } }