public void TestSaveContexts_New()
        {
            DefinedContexts dc    = null;
            DefinedContexts dcNew = null;

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dc = sqlite.LoadContexts();
            }

            dc.Add(new Context("b19bce30-96fe-46dc-b408-891a12a3a933", "Weekly Team Meeting"));

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                sqlite.SaveContexts(dc);
            }

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dcNew = sqlite.LoadContexts();
                Assert.AreEqual(7, dcNew.Count);
                Assert.AreEqual("2ad57821-dad5-4e0a-abb4-47d99b314f21", dcNew.FindIdByDescr("Home").ID);
                Assert.AreEqual("be17f3e2-764b-43b5-b943-63faf6223863", dcNew.FindIdByDescr("Office").ID);
                Assert.AreEqual("f89d513b-c24d-468e-99f3-b841e5ceca6f", dcNew.FindIdByDescr("Computer").ID);
                Assert.AreEqual("ae7491da-4a83-4cc6-ad26-cd090e81417b", dcNew.FindIdByDescr("Errands").ID);
                Assert.AreEqual("c50d02de-d22c-475b-9fef-6e24c05f966b", dcNew.FindIdByDescr("Phone").ID);
                Assert.AreEqual("1b9c460b-0287-4011-87fc-0ae0c5f7b81c", dcNew.FindIdByDescr("Manager").ID);
                Assert.AreEqual("b19bce30-96fe-46dc-b408-891a12a3a933", dcNew.FindIdByDescr("Weekly Team Meeting").ID);
            }
            Assert.IsFalse(DefinedContexts.AreDifferences(dc, dcNew));
        }
        public void TestSaveProject_AddProject_WithTasks()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var removedProjectID = prjList[0].UniqueID;
                var newProject       = new Project("New Test Project");
                var newTask          = new Task("New Task")
                {
                    ContextID = dc.FindIdByDescr("Home").ID
                };
                newProject.AddTask(newTask);
                prjList.Add(newProject);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.IsTrue(prjListNew[10].TaskList.Select(t => t.UniqueID == newTask.UniqueID).First());
            }
        }
 public void TestLoadContexts()
 {
     using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
     {
         DefinedContexts dc = sqlite.LoadContexts();
         Assert.AreEqual(6, dc.Count);
         Assert.AreEqual("2ad57821-dad5-4e0a-abb4-47d99b314f21", dc.FindIdByDescr("Home").ID);
         Assert.AreEqual("be17f3e2-764b-43b5-b943-63faf6223863", dc.FindIdByDescr("Office").ID);
         Assert.AreEqual("f89d513b-c24d-468e-99f3-b841e5ceca6f", dc.FindIdByDescr("Computer").ID);
         Assert.AreEqual("ae7491da-4a83-4cc6-ad26-cd090e81417b", dc.FindIdByDescr("Errands").ID);
         Assert.AreEqual("c50d02de-d22c-475b-9fef-6e24c05f966b", dc.FindIdByDescr("Phone").ID);
         Assert.AreEqual("1b9c460b-0287-4011-87fc-0ae0c5f7b81c", dc.FindIdByDescr("Manager").ID);
     }
 }
        public void TestSaveProject_DeleteExistingTask()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var deletedTask = prjList[3].TaskList[1].UniqueID;
                prjList[3].TaskList.RemoveAt(1);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.AreEqual(0, prjListNew[3].TaskList.Where(t => t.UniqueID == deletedTask).Count());
            }
        }
        public void TestSaveProject_ChangeExistingTask()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var changedTask = prjList[2].TaskList[4].UniqueID;
                prjList[2].TaskList[4].Details = "New details";

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.AreEqual("New details", prjListNew[2].TaskList.Where(t => t.UniqueID == changedTask).First().Details);
            }
        }
        public void TestSaveContexts_NoChanges()
        {
            DefinedContexts dc    = null;
            DefinedContexts dcNew = null;

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dc = sqlite.LoadContexts();
            }

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                sqlite.SaveContexts(dc);
            }

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dcNew = sqlite.LoadContexts();
            }

            Assert.IsFalse(DefinedContexts.AreDifferences(dc, dcNew));
        }
        public void TestSaveProject_AddTaskToExistingProject()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var prjIDWithNewTask = prjList[0].UniqueID;
                var newTask          = new Task("New Task")
                {
                    ContextID = dc.FindIdByDescr("Home").ID
                };
                prjList[0].AddTask(newTask);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.IsNotNull(prjListNew[0].TaskList.Where(t => t.UniqueID == newTask.UniqueID).First());
            }
        }