public static void CreateTask(ProjectWrapper projectWrapper, PackageWrapper packageWrapper, ContainerWrapper containerWrapper, IonStructure.Task task, List <ScriptProject> globalScriptProjects, ScriptProject referencedGlobalScriptProject = null) { try { ExecutableWrapper executableWrapper = null; switch (task) { case DataFlow dataFlow: DataFlowTask dataFlowTask = new DataFlowTask(dataFlow, projectWrapper, packageWrapper, containerWrapper); executableWrapper = dataFlowTask.DataFlowTaskWrapper; break; case ExecuteSql executeSql: ExecuteSqlTask executeSqlTask = new ExecuteSqlTask(executeSql, containerWrapper); executableWrapper = executeSqlTask.ExecuteSqlTaskWrapper; break; case ExecuteProcess executeProcess: executableWrapper = ExecuteProcessTask.CreateTask(executeProcess, containerWrapper); break; case Expression expression: executableWrapper = ExpressionTask.CreateTask(expression, containerWrapper); break; case Script script: ScriptTask scriptTask = new ScriptTask(script, projectWrapper, packageWrapper, containerWrapper, referencedGlobalScriptProject); executableWrapper = scriptTask.ScriptTaskWrapper; break; case ForLoopContainer forLoopContainer: executableWrapper = ContainerExecutable.CreateForLoopContainer(forLoopContainer, projectWrapper, packageWrapper, containerWrapper, globalScriptProjects); break; case ForEachFromVariableLoopContainer forEachFromVarLoopContainer: executableWrapper = ContainerExecutable.CreateForEachFromVariableLoopContainer(forEachFromVarLoopContainer, projectWrapper, packageWrapper, containerWrapper, globalScriptProjects); break; case SequenceContainer sequenceContainer: executableWrapper = ContainerExecutable.CreateSequenceContainer(sequenceContainer, projectWrapper, packageWrapper, containerWrapper, globalScriptProjects); break; } AddPrecedenceConstraints(containerWrapper, executableWrapper, task.PrecedenceConstraints); } catch (Exception e) { if (e.Data[Constants.ExceptionTaskKey] == null) { e.Data[Constants.ExceptionTaskKey] = task.Name; } else { e.Data[Constants.ExceptionTaskKey] = task.Name + "/" + e.Data[Constants.ExceptionTaskKey]; // If task is not null then the task being created is a container, and an exception has been thrown in one of its underlying tasks. } throw; } }
public void ThrowsWhenValidatingInvalidConnection() { var invalidConnectionFactory = Substitute.For <IDbConnectionFactory>(); invalidConnectionFactory .When(x => x.Validate()) .Do(x => { throw new InvalidOperationException("Test exception"); }); var task = new ExecuteSqlTask(invalidConnectionFactory, "select top 1 * from sys.objects"); Assert.Throws <AggregateException>(() => task.VerifyAsync(this.Context).Wait()); }
public void ExecutePassesCorrectQueryToDatabase() { var command = Substitute.For<IDbCommand>(); var connection = Substitute.For<IDbConnection>(); connection.CreateCommand().Returns(command); var factory = Substitute.For<IDbConnectionFactory>(); factory.CreateConnection().Returns(connection); var query = "select top 1 * from sys.objects"; var task = new ExecuteSqlTask(factory, query); task.Execute(this.Context); command.Received().CommandText = query; command.Received().ExecuteNonQuery(); }
public void ExecutePassesCorrectQueryToDatabase() { var command = Substitute.For <IDbCommand>(); var connection = Substitute.For <IDbConnection>(); connection.CreateCommand().Returns(command); var factory = Substitute.For <IDbConnectionFactory>(); factory.CreateConnection().Returns(connection); var query = "select top 1 * from sys.objects"; var task = new ExecuteSqlTask(factory, query); task.Execute(this.Context); command.Received().CommandText = query; command.Received().ExecuteNonQuery(); }
public void ThrowsWhenValidatingInvalidConnection() { var invalidConnectionFactory = Substitute.For<IDbConnectionFactory>(); invalidConnectionFactory .When(x => x.Validate()) .Do(x => { throw new InvalidOperationException("Test exception"); }); var task = new ExecuteSqlTask(invalidConnectionFactory, "select top 1 * from sys.objects"); Assert.Throws<AggregateException>(() => task.VerifyAsync(this.Context).Wait()); }