예제 #1
0
        public async Task VerifyCreateAndRunningTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                bool taskAddedEventRaised = false;
                manager.TaskAdded += (object sender, TaskEventArgs <SqlTask> e) =>
                {
                    taskAddedEventRaised = true;
                };
                DatabaseOperationStub operation = new DatabaseOperationStub();
                operation.TaskResult = new TaskResult
                {
                    TaskStatus = SqlTaskStatus.Succeeded
                };
                SqlTask sqlTask = manager.CreateTask(taskMetaData, operation.FunctionToRun);
                Assert.NotNull(sqlTask);
                Assert.True(taskAddedEventRaised);

                Assert.False(manager.HasCompletedTasks());
                Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
                {
                    Assert.True(manager.HasCompletedTasks());
                    manager.RemoveCompletedTask(sqlTask);
                });
                operation.Stop();
                await taskToVerify;
            }
        }
예제 #2
0
        public async Task VerifyScriptTask()
        {
            using (SqlTaskManager manager = new SqlTaskManager())
            {
                DatabaseOperationStub operation = new DatabaseOperationStub();
                operation.TaskResult = new TaskResult
                {
                    TaskStatus = SqlTaskStatus.Succeeded
                };
                SqlTask sqlTask = manager.CreateTask(taskMetaData, operation.FunctionToScript);

                bool   scriptAddedEventRaised = false;
                string script = null;
                sqlTask.ScriptAdded += (object sender, TaskEventArgs <TaskScript> e) =>
                {
                    scriptAddedEventRaised = true;
                    script = e.TaskData.Script;
                };

                Assert.NotNull(sqlTask);

                Task taskToVerify = sqlTask.RunAsync().ContinueWith(task =>
                {
                    Assert.True(scriptAddedEventRaised);
                    Assert.True(!string.IsNullOrEmpty(script));
                    Assert.True(manager.HasCompletedTasks());
                    manager.RemoveCompletedTask(sqlTask);
                });
                operation.Stop();
                await taskToVerify;
            }
        }