public async Task Task_edited_in_background()
        {
            // setup
            ITask task = new Core.Shared.Model.Impl.Task()
            {
                Added = DateTime.Now, Title = "t1", Folder = this.workbook.Folders[0]
            };

            this.persistence.Save();
            CreateWorkbook(out this.backgroundPersistence, out this.backgroundWorkbook);
            task = this.backgroundWorkbook.Tasks[0];

            task.Title           = "renamed";
            task.Priority        = TaskPriority.Medium;
            task.Action          = TaskAction.Call;
            task.ActionName      = "call";
            task.ActionValue     = "dad";
            task.Alarm           = DateTime.Now;
            task.Completed       = DateTime.Now;
            task.CustomFrequency = new EveryXPeriodFrequency {
                Scale = CustomFrequencyScale.Month, Rate = 2
            };
            task.Due          = DateTime.Now;
            task.Note         = "note";
            task.UseFixedDate = true;
            task.Tags         = "tag";
            task.Start        = DateTime.Now;
            task.Progress     = 0.5;
            task.SyncId       = "2";

            this.backgroundPersistence.Save();

            await SaveMetadataAsync(new SynchronizationMetadata { AfterSyncEditedTasks = new List <int> {
                                                                      task.Id
                                                                  } });

            // act
            await this.manager.TryUpdateWorkbookAsync();

            // check
            var newTask = this.workbook.Tasks[0];

            Assert.AreEqual(task.Title, newTask.Title);
            Assert.AreEqual(task.Priority, newTask.Priority);
            Assert.AreEqual(task.Action, newTask.Action);
            Assert.AreEqual(task.ActionName, newTask.ActionName);
            Assert.AreEqual(task.ActionValue, newTask.ActionValue);

            Assert.IsTrue(Math.Abs((task.Alarm.Value - newTask.Alarm.Value).TotalSeconds) < 1);
            Assert.IsTrue(Math.Abs((task.Completed.Value - newTask.Completed.Value).TotalSeconds) < 1);
            Assert.IsTrue(Math.Abs((task.Due.Value - newTask.Due.Value).TotalSeconds) < 1);
            Assert.IsTrue(Math.Abs((task.Start.Value - newTask.Start.Value).TotalSeconds) < 1);

            Assert.IsTrue(task.CustomFrequency.Equals(newTask.CustomFrequency));
            Assert.AreEqual(task.Note, newTask.Note);
            Assert.AreEqual(task.UseFixedDate, newTask.UseFixedDate);
            Assert.AreEqual(task.Tags, newTask.Tags);
            Assert.AreEqual(task.Progress, newTask.Progress);
            Assert.AreEqual(task.SyncId, newTask.SyncId);
        }
        public async Task Task_added_in_background()
        {
            // setup
            var task = new Core.Shared.Model.Impl.Task()
            {
                Added = DateTime.Now, Title = "t1", Folder = this.backgroundWorkbook.Folders[0]
            };

            this.backgroundPersistence.Save();
            await SaveMetadataAsync(new SynchronizationMetadata { AfterSyncEditedTasks = new List <int> {
                                                                      task.Id
                                                                  } });

            // act
            await this.manager.TryUpdateWorkbookAsync();

            // check
            this.Check(() => AssertEx.ContainsTasks(this.workbook, "t1"));
        }
        public async Task Task_and_folder_added_in_background()
        {
            // setup
            var oldFolder = this.workbook.Folders[0];
            var newFolder = this.backgroundWorkbook.AddFolder("f2");
            var task      = new Core.Shared.Model.Impl.Task()
            {
                Added = DateTime.Now, Title = "t1", Folder = this.backgroundWorkbook.Folders[1]
            };

            this.backgroundPersistence.Save();

            await SaveMetadataAsync(new SynchronizationMetadata
            {
                AfterSyncEditedFolders = new List <string> {
                    newFolder.Name
                },
                AfterSyncEditedTasks = new List <int> {
                    task.Id
                }
            });

            // act
            await this.manager.TryUpdateWorkbookAsync();

            // check
            Assert.AreEqual(oldFolder, this.workbook.Folders[0]);

            AssertEx.ContainsFolders(this.workbook, "f1", "f2");
            AssertEx.ContainsTasks(this.workbook, "t1");

            this.persistence.Save();
            this.persistence.CloseDatabase();
            CreateWorkbook(out this.persistence, out this.workbook);

            AssertEx.ContainsFolders(this.workbook, "f1", "f2");
            AssertEx.ContainsTasks(this.workbook, "t1");
        }