Exemplo n.º 1
0
        public async Task ShouldBeCompletedСonsequentiallyAsync()
        {
            var env = await TestEnvironment.CreateSimpleAsync();

            var man = new AsyncTaskManager(new MockConfigurationStorage());

            man.MaxNumberOfTasksRunning = 1;
            List <LockTask> tasks = new List <LockTask>();

            for (int i = 0; i < 10; i++)
            {
                var newTask = new LockTask(env.Account);
                tasks.Add(newTask);
                man.Add(newTask);
            }
            for (var i = 0; i < 10; i++)
            {
                var currentTask = tasks[i];
                currentTask.locker.Set();
                Assert.IsTrue(currentTask.CompleteWaitHandle.WaitOne());
                Assert.AreEqual(AsyncTaskState.Completed, currentTask.State);
                for (var k = i + 2; k < 10; k++)
                {
                    var task = tasks[k];
                    Assert.AreEqual(AsyncTaskState.Waiting, task.State);
                }
            }
        }
Exemplo n.º 2
0
 public void ShouldBeAsync()
 {
     var man = new AsyncTaskManager(new MockConfigurationStorage());
     // very long task
     var task = new LockTask(100000);
     man.Add(task);
     // wait short a time and check state
     Assert.IsFalse(task.CompleteWaitHandle.WaitOne(100));
     Assert.AreNotEqual(AsyncTaskState.Completed, task.State);
     Assert.IsFalse(task.ok);
 }
Exemplo n.º 3
0
        public async Task TestSyncronizeDriveFileTask(TestEnvironment env, SynchronizeDriveFileTask task)
        {
            var man = new AsyncTaskManager(new MockConfigurationStorage());

            man.Add(task);
            task.CompleteWaitHandle.WaitOne();
            var syncedFile = await env.GetFileByFullPathAsync("/photos2015/PHOTO2.jpg");

            Assert.AreEqual(2, syncedFile.DriveFiles.Count);
            Assert.AreEqual(((MockDriveFile)syncedFile.DriveFiles[0]).Name, ((MockDriveFile)syncedFile.DriveFiles[1]).Name);
            Assert.AreEqual(((MockDriveFile)syncedFile.DriveFiles[0]).content.ToString(), ((MockDriveFile)syncedFile.DriveFiles[1]).content.ToString());
        }
Exemplo n.º 4
0
        public void ShouldBeCompletedAtTime()
        {
            var man  = new AsyncTaskManager(new MockConfigurationStorage());
            var task = new LockTask();

            man.Add(task);
            Assert.IsFalse(task.ok);
            task.locker.Set();
            Assert.IsTrue(task.CompleteWaitHandle.WaitOne());
            Assert.IsTrue(task.ok);
            Assert.AreEqual(AsyncTaskState.Completed, task.State);
        }
Exemplo n.º 5
0
        public void ShouldBeAsync()
        {
            var man = new AsyncTaskManager(new MockConfigurationStorage());
            // very long task
            var task = new LockTask(100000);

            man.Add(task);
            // wait short a time and check state
            Assert.IsFalse(task.CompleteWaitHandle.WaitOne(100));
            Assert.AreNotEqual(AsyncTaskState.Completed, task.State);
            Assert.IsFalse(task.ok);
        }
Exemplo n.º 6
0
        public async Task TestDeleteFolderTask()
        {
            var man = new AsyncTaskManager(new MockConfigurationStorage());
            var env = await TestEnvironment.CreateSimpleAsync();

            var folder = await env.GetFolderByFullPathAsync("photos2015");

            var task = new DeleteFolderTask(env.Account, "", 0, new AsyncTask[0], folder);

            man.Add(task);
            // throws exception becouse directory isn't exists
            await env.GetFolderByFullPathAsync("photos2015");
        }
Exemplo n.º 7
0
        public async Task ShouldBeCompletedhHierarchically()
        {
            var env = await TestEnvironment.CreateSimpleAsync();

            var createFolder    = new LockTask(env.Account);
            var createSubfolder = new LockTask(env.Account, 10, new AsyncTask[] { createFolder });
            var uploadFile1     = new LockTask(env.Account, 10, new AsyncTask[] { createSubfolder });
            var uploadFile2     = new LockTask(env.Account, 10, new AsyncTask[] { createSubfolder });
            var deleteFile2     = new LockTask(env.Account, 10, new AsyncTask[] { uploadFile2 });

            var man = new AsyncTaskManager(new MockConfigurationStorage());

            man.Add(createFolder);
            man.Add(createSubfolder);
            man.Add(uploadFile1);
            man.Add(uploadFile2);
            man.Add(deleteFile2);

            createFolder.locker.Set();

            Assert.IsFalse(createSubfolder.ok);
            createSubfolder.locker.Set();

            Assert.IsFalse(uploadFile1.ok);
            uploadFile1.locker.Set();

            Assert.IsFalse(uploadFile2.ok);
            uploadFile2.locker.Set();

            Assert.IsFalse(deleteFile2.ok);
            deleteFile2.locker.Set();

            Assert.IsTrue(deleteFile2.CompleteWaitHandle.WaitOne());
            Assert.IsTrue(createFolder.ok);
            Assert.IsTrue(createSubfolder.ok);
            Assert.IsTrue(uploadFile1.ok);
            Assert.IsTrue(uploadFile2.ok);
            Assert.IsTrue(deleteFile2.ok);
        }
Exemplo n.º 8
0
        public async Task TestCreateFolderTask()
        {
            var man = new AsyncTaskManager(new MockConfigurationStorage());
            var env = await TestEnvironment.CreateSimpleAsync();

            var folder = await env.GetFolderByFullPathAsync("photos2015");

            var task = new CreateFolderTask(env.Account, "", 0, new AsyncTask[0], "new", folder);

            man.Add(task);
            task.CompleteWaitHandle.WaitOne();
            var newFolder = await env.GetFolderByFullPathAsync("photos2015/new");

            Assert.AreEqual("new", newFolder.Name);
        }
Exemplo n.º 9
0
        public async Task TestDeleteEmptyFolderTask()
        {
            var env = await TestEnvironment.CreateSimpleAsync();

            var folder = await env.GetFolderByFullPathAsync("/lenovo");

            var task = new DeleteEmptyFolderTask(env.Account, "", 10, new AsyncTask[0], folder);
            var man  = new AsyncTaskManager(new MockConfigurationStorage());

            man.Add(task);
            task.CompleteWaitHandle.WaitOne();
            try
            {
                await env.GetFolderByFullPathAsync("/lenovo");

                Assert.Fail();
            }
            catch (ArgumentException) { }
        }
Exemplo n.º 10
0
 public async Task ShouldBeCompletedСonsequentiallyAsync()
 {
     var env = await TestEnvironment.CreateSimpleAsync();
     var man = new AsyncTaskManager(new MockConfigurationStorage());
     man.MaxNumberOfTasksRunning = 1;
     List<LockTask> tasks = new List<LockTask>();
     for (int i = 0; i < 10; i++)
     {
         var newTask = new LockTask(env.Account);
         tasks.Add(newTask);
         man.Add(newTask);
     }
     for (var i = 0; i < 10; i++)
     {
         var currentTask = tasks[i];
         currentTask.locker.Set();
         Assert.IsTrue(currentTask.CompleteWaitHandle.WaitOne());
         Assert.AreEqual(AsyncTaskState.Completed, currentTask.State);
         for (var k = i + 2; k < 10; k++)
         {
             var task = tasks[k];
             Assert.AreEqual(AsyncTaskState.Waiting, task.State);
         }
     }
 }
Exemplo n.º 11
0
 public void ShouldBeCompletedAtTime()
 {
     var man = new AsyncTaskManager(new MockConfigurationStorage());
     var task = new LockTask();
     man.Add(task);
     Assert.IsFalse(task.ok);
     task.locker.Set();
     Assert.IsTrue(task.CompleteWaitHandle.WaitOne());
     Assert.IsTrue(task.ok);
     Assert.AreEqual(AsyncTaskState.Completed, task.State);
 }
Exemplo n.º 12
0
        public async Task ShouldBeCompletedhHierarchically()
        {
            var env = await TestEnvironment.CreateSimpleAsync();
            var createFolder = new LockTask(env.Account);
            var createSubfolder = new LockTask(env.Account, 10, new AsyncTask[] { createFolder });
            var uploadFile1 = new LockTask(env.Account, 10, new AsyncTask[] { createSubfolder });
            var uploadFile2 = new LockTask(env.Account, 10, new AsyncTask[] { createSubfolder });
            var deleteFile2 = new LockTask(env.Account, 10, new AsyncTask[] { uploadFile2 });

            var man = new AsyncTaskManager(new MockConfigurationStorage());

            man.Add(createFolder);
            man.Add(createSubfolder);
            man.Add(uploadFile1);
            man.Add(uploadFile2);
            man.Add(deleteFile2);

            createFolder.locker.Set();

            Assert.IsFalse(createSubfolder.ok);
            createSubfolder.locker.Set();

            Assert.IsFalse(uploadFile1.ok);
            uploadFile1.locker.Set();

            Assert.IsFalse(uploadFile2.ok);
            uploadFile2.locker.Set();

            Assert.IsFalse(deleteFile2.ok);
            deleteFile2.locker.Set();

            Assert.IsTrue(deleteFile2.CompleteWaitHandle.WaitOne());
            Assert.IsTrue(createFolder.ok);
            Assert.IsTrue(createSubfolder.ok);
            Assert.IsTrue(uploadFile1.ok);
            Assert.IsTrue(uploadFile2.ok);
            Assert.IsTrue(deleteFile2.ok);
        }