Ejemplo n.º 1
0
        static void TestUpdateKnowledgebase(NoteDatabase db, List <KnowledgeBase> kbList)
        {
            // New name
            List <string> updated = new List <string>()
            {
                "Mathmatics",
                "Foreign Language",
                "C++"
            };

            // Test body
            var toUpdate = db.FetchKnowledgeBase();

            for (int i = 0; i < toUpdate.Count; i++)
            {
                // Update
                toUpdate[i].Name = updated[i];
                toUpdate[i]      = db.UpdateKnowledgeBase(toUpdate[i]);

                // Comparison
                if (toUpdate[i].Name == updated[i])
                {
                    Console.WriteLine($"Update {kbList[i].Name} to {toUpdate[i].Name}");
                }
                else
                {
                    Console.WriteLine($"Update error: {kbList[i].Name} should be {toUpdate[i].Name}");
                }

                // Restore
                db.UpdateKnowledgeBase(kbList[i]);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        static void TestFetchKnowledgebase(NoteDatabase db, List <KnowledgeBase> kbList)
        {
            #region KnowledgeBase FetchKnowledgeBase(string name)
            foreach (var kb in kbList)
            {
                var actual = db.FetchKnowledgeBase(kb.Name);
                if (actual != null && actual.Name == kb.Name)
                {
                    Console.WriteLine($"kbase {kb.Name}: pass\n");
                }
                else if (actual == null)
                {
                    Console.WriteLine($"ERROR: kbase {kb.Name}, actual is null!\n");
                }
                else
                {
                    Console.WriteLine($"ERROR: kbase {kb.Name}, actual is {actual.Name}!\n");
                }
            }
            #endregion

            #region List<KnowledgeBase> FetchKnowledge()
            var allkb = db.FetchKnowledgeBase();
            if (kbList.Count != allkb.Count)
            {
                Console.WriteLine("different count!");
            }
            for (int i = 0; i < kbList.Count; i++)
            {
                var kb     = kbList[i];
                var actual = i < allkb.Count
                    ? allkb[i]
                    : null;
                if (actual != null && actual.Name == kb.Name)
                {
                    Console.WriteLine($"kbase {kb.Name}: pass\n");
                }
                else if (actual == null)
                {
                    Console.WriteLine($"ERROR: kbase {kb.Name}, actual is null!\n");
                }
                else
                {
                    Console.WriteLine($"ERROR: kbase {kb.Name}, actual is {actual.Name}!\n");
                }
            }
            #endregion

            #region Fetch non-exist KnowledgeBase
            var shouldBeNull0 = db.FetchKnowledgeBase("");
            var shouldBeNull1 = db.FetchKnowledgeBase(null);
            if (shouldBeNull0 == null && shouldBeNull1 == null)
            {
                Console.WriteLine("Should-be-null: pass");
            }
            else
            {
                Console.WriteLine("Should-be-null: Error");
                Console.ReadKey();
            }


            var shouldBeVoid = db.FetchKnowledgeBase("Java");
            if (shouldBeVoid == KnowledgeBase.VoidKnowledgeBase)
            {
                Console.WriteLine("Should-be-void: pass");
            }
            else
            {
                Console.WriteLine("Should-be-void: Error");
                Console.ReadKey();
            }

            #endregion
        }