#pragma warning disable CA1031 // warning CA1031: Modify '***' to catch a more specific exception type, or rethrow the exception. #pragma warning disable CA1303 // warning CA1303: Method '***' passes a literal string as parameter 'value' internal static Outcome <bool, string> Validate(this CommandLine commandLine) { Contract.Requires(null != commandLine); // we must have staging folder if (string.IsNullOrWhiteSpace(commandLine.StagingFolder)) { return(new Outcome <bool, string>(false).AddErrors("Staging folder is not specified, you may want to set TEMP or HOME environment variable")); } if (!commandLine.StagingFolder.EndsWith(Path.DirectorySeparatorChar)) { commandLine.StagingFolder += Path.DirectorySeparatorChar; } // validate var outcome = new Outcome <bool, string>(true); foreach (var a in commandLine.Arguments) { try { // this one throws... thank you, Amazon var uri = new Uri(a); if (!AmazonS3Uri.TryParseAmazonS3Uri(uri, out var s3uri)) { outcome.AddErrors($"Invalid AWS S3 Uri: {a}"); } } catch (Exception x) { outcome.AddErrors($"{x.GetType().Name} {x.Message}: {a}"); } } return(outcome); }
public void Outcome() { Assert.IsTrue(new Outcome <bool, string>(true).Succeeded); Assert.IsFalse(new Outcome <bool, string>(true).Failed); Assert.IsTrue(new Outcome <bool, string>(true).AddErrors("err").Failed); Assert.IsTrue(new Outcome <bool, string>(false).Succeeded); Assert.IsTrue(new Outcome <bool, string>(false).AddErrors("err").Failed); Assert.IsTrue(new Outcome <int, string>(1).Succeeded); Assert.IsTrue(new Outcome <int, string>(1).AddErrors("error!").Failed); var failed1 = new Outcome <string, string>("Ok").AddErrors("no", "could", "not", "do"); Assert.IsTrue(failed1.Failed); var failed2 = new Outcome <string, string>("RESULT").AddErrors(new List <string> { "could", "not", "do" }).AddErrors("one", "two").AddErrors(); Assert.That(failed2.Errors.Count, Is.EqualTo(5)); Assert.IsTrue(failed2.Failed); failed2.ResetErrors(); failed2.Result = "success!!!"; Assert.IsFalse(failed2.Failed); failed2.AddErrors("again"); Assert.IsFalse(failed2.Succeeded); Assert.IsTrue(failed2.Failed); }