public void Should_Execute_All_Tasks()
        {
            string text;

            var path = Path.Combine(Environment.CurrentDirectory, "filetestSync.txt");

            var task = new TaskDto { Key = "list1", Task = new Task(() => WriteFileTest("Task list1 performed successfully", "filetestSync")) };
            var task2 = new TaskDto { Key = "list2", Task = new Task(() => WriteFileTest("list2", "filetestSync")) };

            var manager = new ManagerApplicationTest(new TasksStorage(), new Queue<TasksStorage>());
            manager.SaveTask(task);
            manager.SaveTask(task2);

            manager.StartTasks(false);

            using (var sr = new StreamReader(path))
            {
                text = sr.ReadToEnd();
            }

            File.Delete(path);

            var assert = new StringBuilder();
            assert.AppendLine("Task list1 performed successfully");
            assert.AppendLine("list2");

            Assert.AreEqual(assert.ToString().Trim(), text.Trim());
        }
        public void Should_Execute_Tasks_by_Key_asynchronously()
        {
            string text;

            var path = Path.Combine(Environment.CurrentDirectory, "filetestAsync.txt");
            var path2 = Path.Combine(Environment.CurrentDirectory, "filetestAsync2.txt");

            var task = new TaskDto { Key = "list1", Task = new Task(() => WriteFileTest("Task list1 performed successfully", "filetestAsync")) };
            var task2 = new TaskDto { Key = "list2", Task = new Task(() => WriteFileTest("list2", "filetestAsync2")) };

            var manager = new ManagerApplicationTest(new TasksStorage(), new Queue<TasksStorage>());
            manager.SaveTask(task);
            manager.SaveTask(task2);

            manager.StartTasks("list1", false);

            Thread.Sleep(2000);

            using (var sr = new StreamReader(path))
            {
                text = sr.ReadToEnd();
            }

            File.Delete(path);

            Assert.AreEqual("Task list1 performed successfully".Trim(), text.Trim());

            manager.StartTasks("list2", false);

            Thread.Sleep(2000);

            using (var sr = new StreamReader(path2))
            {
                text = sr.ReadToEnd();
            }

            File.Delete(path2);

            Assert.AreEqual("list2".Trim(), text.Trim());
        }
        public void Should_Save_And_Retrieve_All_Tasks()
        {
            var task = new TaskDto { Key = "list1", Task = new Task(() => Console.WriteLine("task1")) };
            var task2 = new TaskDto { Key = "list2", Task = new Task(() => Console.WriteLine("task2")) };

            var manager = new ManagerApplicationTest(new TasksStorage(), new Queue<TasksStorage>());
            manager.SaveTask(task);
            manager.SaveTask(task2);

            Assert.AreEqual(2, manager.RetrieveAllTasks().Count());

            Assert.IsNotNull(manager.RetrieveAllTasks().FirstOrDefault(x => x.Key == "list1"));
            Assert.IsNotNull(manager.RetrieveAllTasks().FirstOrDefault(x => x.Key == "list2"));

            Assert.AreEqual(1, manager.RetrieveAllTasks().FirstOrDefault(x => x.Key == "list1").Tasks.Count);
            Assert.AreEqual(1, manager.RetrieveAllTasks().FirstOrDefault(x => x.Key == "list2").Tasks.Count);

            manager.SaveTask(new TaskDto() {Key = "list1", Task = new Task(() => Console.WriteLine("task3"))});

            Assert.AreEqual(1, manager.RetrieveAllTasks().FirstOrDefault(x => x.Key == "list2").Tasks.Count);
            Assert.AreEqual(2, manager.RetrieveAllTasks().FirstOrDefault(x => x.Key == "list1").Tasks.Count);
        }
        public void Should_Save_Any_Tasks_With_The_Same_Key()
        {
            var task = new TaskDto { Key = "list1", Task = new Task(() => Console.WriteLine("task1")) };

            var manager = new ManagerApplicationTest(new TasksStorage(), new Queue<TasksStorage>());
            manager.SaveTask(task);
            manager.SaveTask(task);

            Assert.IsNotNull(manager.RetrieveSpecifiedTaskList("list1"));
            Assert.AreEqual(2, manager.RetrieveSpecifiedTaskList("list1").Tasks.Count);
        }
        public void Should_Retrieve_Task_Using_Method_Parameter()
        {
            var task = new TaskDto { Key = "list1", Task = new Task(() => Console.WriteLine("task1")) };

            var manager = new ManagerApplicationTest(new TasksStorage(), new Queue<TasksStorage>());
            manager.SaveTask(task);

            Assert.IsNotNull(manager.RetrieveSpecifiedTaskList("list1"));
            Assert.AreEqual("list1", manager.RetrieveSpecifiedTaskList("list1").Key);
        }