public void If_PredicateAbility_Unit_ShouldReturnCorrectValue() => TestIf((IAction <Unit> a, Func <Ability, bool> p, Unit v) => ActionExtensions.If(a, p));
public async Task <ExitStatus> StartKnime(string workDir = null, TextWriter output = null, TextWriter error = null) { var exitStatus = new ExitStatus(); var filename = _knimeDir + _knimeApp; var arguments = Arguments.ToString(); using (var process = new Process() { StartInfo = new ProcessStartInfo() { CreateNoWindow = true, Arguments = arguments, FileName = filename, RedirectStandardOutput = output != null, RedirectStandardError = error != null, UseShellExecute = false, } }) { if (workDir != null) { process.StartInfo.WorkingDirectory = workDir; } _executionCancellationTokenSource = Timeout.HasValue ? new CancellationTokenSource(Timeout.Value * 1000) : new CancellationTokenSource(); try { process.Start(); #pragma warning disable AsyncFixer04 // A disposable object used in a fire & forget async call var tasks = new List <Task>(3) { process.WaitForExitAsync(_executionCancellationTokenSource.Token) }; #pragma warning restore AsyncFixer04 // A disposable object used in a fire & forget async call if (output != null) { tasks.Add(ActionExtensions.ReadAsync(drh => { process.OutputDataReceived += drh; process.BeginOutputReadLine(); }, drh => process.OutputDataReceived -= drh, output, _executionCancellationTokenSource.Token)); } if (error != null) { tasks.Add(ActionExtensions.ReadAsync(drh => { process.ErrorDataReceived += drh; process.BeginErrorReadLine(); }, drh => process.ErrorDataReceived -= drh, error, _executionCancellationTokenSource.Token)); } if (process.HasExited || process.Id == 0) { throw new NullReferenceException("KNIME either exited too fast or could not get started at all."); } await Task.WhenAll(tasks); exitStatus.ExitCode = process.ExitCode; } catch (NullReferenceException ex) { exitStatus.LastErrorMessage = ex.Message; } /* This method timeouted, not knime loader */ catch (TaskCanceledException) { exitStatus.LastErrorMessage = "KNIME process was cancelled."; } /* should not appear */ catch (ObjectDisposedException) { exitStatus.LastErrorMessage = "KNIME process ended preliminary."; } finally { if (!string.IsNullOrEmpty(exitStatus.LastErrorMessage) && KillOnError) { try { process.Kill(); exitStatus.KilledProcess = true; exitStatus.ExitCode = -1; // successful cancellation otherwise sets exit code 0 } catch { // ignored } } } return(exitStatus); } }
public void If_PredicateAbility_ShouldReturnCorrectValue() => TestIf((IAction <object> a, Func <Ability, bool> p, object v) => ActionExtensions.If(a, p, v));
public void If_Unit_ShouldReturnCorrectValue() => TestIf((IAction <Unit> a, Func <bool> p, Unit v) => ActionExtensions.If(a, p));
public void If_ShouldReturnCorrectValue() => TestIf((IAction <object> a, Func <bool> p, object v) => ActionExtensions.If(a, p, v));
/// <summary> /// Records a skipped assertion of an expected outcome for this specification. /// </summary> /// <param name="message">A message describing the assertion.</param> /// <param name="assert">The action which would have performed the assertion.</param> /// <returns>An instance of <see cref="IThen"/>.</returns> /// <remarks> /// This is the equivalent of <see cref="Xunit.FactAttribute.Skip"/>. /// E.g. <code>[Fact(Skip = "Work in progress.")]</code>. /// </remarks> public static IThen ThenSkip(this string message, Action <dynamic> assert) { return(new Then(ThreadContext.Scenario.ThenSkip(message, ActionExtensions.ToDefaultFunc <IDisposable>(() => assert(ThreadContext.Scenario.Context))))); }
/// <summary> /// Records the act to be performed on the arrangment for this specification. /// </summary> /// <param name="message">A message describing the act.</param> /// <param name="act">The action that will perform the act.</param> /// <returns>An instance of <see cref="IWhen"/>.</returns> public static IWhen When(this string message, Action <dynamic> act) { return(new When(ThreadContext.Scenario.When(message, ActionExtensions.ToDefaultFunc <IDisposable>(() => act(ThreadContext.Scenario.Context))))); }