public void ArgumentTooSmallTest() { this.cakeArgs.Setup( m => m.HasArgument(optionalArgName) ).Returns(true); this.cakeArgs.Setup( m => m.GetArgument(optionalArgName) ).Returns((minValue - 1).ToString()); AggregateException e = Assert.Throws <AggregateException>( () => ArgumentBinder.FromArguments <OptionalArgument>(this.cakeContext.Object) ); Assert.AreEqual(1, e.InnerExceptions.Count); Assert.IsTrue(e.InnerExceptions[0] is ArgumentTooSmallException); }
public void FormatExceptionTest() { this.cakeArgs.Setup( m => m.HasArgument(optionalArgName) ).Returns(true); this.cakeArgs.Setup( m => m.GetArgument(optionalArgName) ).Returns("lolImNotAnInt"); AggregateException e = Assert.Throws <AggregateException>( () => ArgumentBinder.FromArguments <OptionalArgument>(this.cakeContext.Object) ); Assert.AreEqual(1, e.InnerExceptions.Count); Assert.IsTrue(e.InnerExceptions[0] is ArgumentFormatException); }
// ---------------- Functions ---------------- /// <summary> /// Runs git on the local repository and returns /// the name of the current branch. /// </summary> /// <param name="config"> /// Configuration. If null, it grabs the configuration /// from the passed in command-line arguments. /// </param> public string Run(GitQueryCurrentBranchConfig config = null) { if (config == null) { config = ArgumentBinder.FromArguments <GitQueryCurrentBranchConfig>(this.context); } string branch = null; string onStdOut(string line) { if (string.IsNullOrWhiteSpace(line) == false) { branch = line; } return(line); }; ProcessSettings processSettings = new ProcessSettings { Arguments = ProcessArgumentBuilder.FromString("rev-parse --abbrev-ref HEAD"), RedirectStandardOutput = true, RedirectedStandardOutputHandler = onStdOut }; this.Run(this.toolSettings, processSettings.Arguments, processSettings, null); if (branch == null) { throw new InvalidOperationException( "Could not get the current branch from Git" ); } if (config.NoPrint == false) { context.Information($"Current Branch: {branch}"); } return(branch); }
// ----------------- Functions ----------------- public override void Run(ICakeContext context) { DeleteHelpersConfig config = ArgumentBinder.FromArguments <DeleteHelpersConfig>(context); context.DeleteDirectories(config); }
// ---------------- Functions ---------------- /// <summary> /// Runs git on the local repository and returns /// the <see cref="DateTime"/> of the last commit. /// </summary> /// <param name="config"> /// Configuration. If null, it grabs the configuration /// from the passed in command-line arguments. /// </param> public DateTime Run(GitQueryLastCommitDateConfig config = null) { if (config == null) { config = ArgumentBinder.FromArguments <GitQueryLastCommitDateConfig>(this.context); } DateTime?timeStamp = null; string onStdOut(string line) { if (string.IsNullOrWhiteSpace(line) == false) { if (DateTime.TryParse(line, out DateTime foundTimeStamp)) { timeStamp = foundTimeStamp; } } return(line); }; ProcessSettings processSettings = new ProcessSettings { Arguments = ProcessArgumentBuilder.FromString("show -s --format=%cI"), RedirectStandardOutput = true, RedirectedStandardOutputHandler = onStdOut }; this.Run(this.toolSettings, processSettings.Arguments, processSettings, null); if (timeStamp == null) { throw new InvalidOperationException( "Could not get timestamp from git" ); } string timeStampStr; if (string.IsNullOrEmpty(config.DateTimeFormat)) { timeStampStr = timeStamp.Value.ToString(); } else { timeStampStr = timeStamp.Value.ToString(config.DateTimeFormat); } if (config.NoPrint == false) { context.Information($"Last commit was at: {timeStampStr}"); } if (string.IsNullOrWhiteSpace(config.OutputFile) == false) { System.IO.File.WriteAllText(config.OutputFile, timeStampStr); } return(timeStamp.Value); }