Esempio n. 1
0
        public async Task VerifyCombinationRunAndCancelBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                IBackupOperation backupOperation = new BackupOperationStub();
                TaskMetadata     taskMetaData    = this.CreateTaskMetaData(backupOperation);
                SqlTask          sqlTask         = manager.CreateTask <SqlTask>(taskMetaData);

                var          mockBackupOperation = new Mock <IBackupOperation>();
                TaskMetadata taskMetaData2       = this.CreateTaskMetaData(mockBackupOperation.Object);
                SqlTask      sqlTask2            = manager.CreateTask <SqlTask>(taskMetaData);

                Assert.NotNull(sqlTask);
                Assert.NotNull(sqlTask2);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation).BackupSemaphore.Release();
                    manager.Reset();
                });

                Task taskToVerify2 = sqlTask2.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Succeeded, sqlTask2.TaskStatus);
                });

                manager.CancelTask(sqlTask.TaskId);
                await Task.WhenAll(taskToVerify, taskToVerify2);
            }
        }
Esempio n. 2
0
        public async Task VerifyCancelBackupTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                IBackupOperation backupOperation = new BackupOperationStub();
                TaskMetadata     taskMetaData    = this.CreateTaskMetaData(backupOperation);
                SqlTask          sqlTask         = manager.CreateTask <SqlTask>(taskMetaData);
                Assert.NotNull(sqlTask);
                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation).BackupSemaphore.Release();
                    manager.Reset();
                });

                manager.CancelTask(sqlTask.TaskId);
                await taskToVerify;
            }
        }
Esempio n. 3
0
        public async Task VerifyCancelMultipleBackupTasks()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                DisasterRecoveryService service          = new DisasterRecoveryService();
                IBackupOperation        backupOperation  = new BackupOperationStub();
                IBackupOperation        backupOperation2 = new BackupOperationStub();
                TaskMetadata            taskMetaData     = this.CreateTaskMetaData(backupOperation);
                TaskMetadata            taskMetaData2    = this.CreateTaskMetaData(backupOperation2);

                SqlTask sqlTask  = manager.CreateTask <SqlTask>(taskMetaData);
                SqlTask sqlTask2 = manager.CreateTask <SqlTask>(taskMetaData2);
                Assert.NotNull(sqlTask);
                Assert.NotNull(sqlTask2);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask.TaskStatus);
                    Assert.Equal(sqlTask.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation).BackupSemaphore.Release();
                    manager.Reset();
                });

                Task taskToVerify2 = sqlTask2.RunAsync().ContinueWith(Task =>
                {
                    Assert.Equal(SqlTaskStatus.Canceled, sqlTask2.TaskStatus);
                    Assert.Equal(sqlTask2.IsCancelRequested, true);
                    ((BackupOperationStub)backupOperation2).BackupSemaphore.Release();
                    manager.Reset();
                });

                manager.CancelTask(sqlTask.TaskId);
                manager.CancelTask(sqlTask2.TaskId);
                await Task.WhenAll(taskToVerify, taskToVerify2);
            }
        }