static void TestDeleteKnowledgebase(NoteDatabase db, List <KnowledgeBase> kbList) { foreach (var kb in kbList) { // Delete db.DeleteKnowledgeBase(kb.Name); // Try to fetch var result = db.FetchKnowledgeBase(kb.Name); // Check result if (result == KnowledgeBase.VoidKnowledgeBase) { Console.WriteLine($"Delete {kb.Name}"); } else { Console.WriteLine($"Delete failed: {kb.Name}"); Console.ReadKey(); } // Restore db.AddKnowledgeBase(kb); } }
static void TestFecthNote(NoteDatabase db, List <Note> noteList, List <KnowledgeBase> kbList) { #region FetchNote(directory, title) foreach (var note in noteList) { var actual = db.FetchNote(note.Directory, note.Title); if (actual != null && actual.Title == note.Title && actual.Directory == note.Directory ) { Console.WriteLine($"note {note.Title}: pass\n"); } else if (actual == null) { Console.WriteLine($"ERROR: note {note.Title} {note.Directory}, actual is null!\n"); } else { Console.WriteLine($"ERROR: note {note.Title} {note.Directory}, (actual) {actual.Title} {actual.Directory}!\n"); } } #endregion #region FetchNote(directory) foreach (var kb in kbList) { var actual = db.FetchNote(kb.Name); var expected = noteList.FindAll(note => note.Directory == kb.Name); if (actual.Count != expected.Count) { Console.WriteLine("Error: FetchNote(directory) differs"); } for (int i = 0; i < expected.Count; i++) { if (i < actual.Count && actual[i] == expected[i]) { Console.WriteLine($"note {expected[i].Title}: pass\n"); } else if (i >= actual.Count) { Console.WriteLine($"ERROR: note {expected[i].Title} {expected[i].Directory}, actual is null!\n"); } else if (actual[i] != expected[i]) { Console.WriteLine($"ERROR: note {expected[i].Title} {expected[i].Directory}, (actual) {actual[i].Title} {actual[i].Directory}!\n"); } } } #endregion #region non-exists var shouldBeNull = db.FetchNote(null); if (shouldBeNull == null) { Console.WriteLine("Note Should-be-null: pass"); } else { Console.WriteLine("Note Should-be-null: Error"); Console.ReadKey(); } // Non-exist KnowledgeBase var emptyKb = new KnowledgeBase() { Name = "Template" }; db.AddKnowledgeBase(emptyKb); var shouldBeEmpty0 = db.FetchNote(emptyKb.Name); var shouldBeEmpty1 = db.FetchNote("Java"); if (shouldBeEmpty0.Count == 0 && shouldBeEmpty1.Count == 0) { Console.WriteLine("Note Should-be-empty: pass"); } else { Console.WriteLine("Note Should-be-empty: Error"); Console.ReadKey(); } // Restore db.DeleteKnowledgeBase(emptyKb.Name); // Non-exist note var shouldBeVoid = db.FetchNote("Cpp", "tr1"); if (shouldBeVoid == Note.VoidNote) { Console.WriteLine("Note Should-be-void: pass"); } else { Console.WriteLine("Note Should-be-void: Error"); Console.ReadKey(); } #endregion }