From 09bab1f470cbf4d7e4422bc932ac5330e892b8cf Mon Sep 17 00:00:00 2001 From: Martin Gondermann Date: Mon, 7 Sep 2015 21:19:41 +0200 Subject: [PATCH] Adds more Initializers for Result.Failure for convenience reasons --- Functional/Result.cs | 34 ++++++++++++++++++++++++++++++++++ Test/ResultTests.cs | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Functional/Result.cs b/Functional/Result.cs index be5d24a..422c25e 100644 --- a/Functional/Result.cs +++ b/Functional/Result.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using System.Collections.Generic; namespace Pagansoft.Functional { @@ -186,6 +187,39 @@ public static Result Failure(ExceptionWithContext failure) { return new FailureResult(failure); } + + /// + /// Creates a Failure Result value. + /// + /// The failure message. + /// The type of the success value. + public static Result Failure(string failureMessage) + { + return Result.Failure(new ExceptionWithContext(failureMessage, null)); + } + + /// + /// Creates a Failure Result value. + /// + /// The failure message. + /// The context values. + /// The type of the success value. + public static Result Failure(string failureMessage, Dictionary context) + { + return Result.Failure(new ExceptionWithContext(failureMessage, context)); + } + + /// + /// Creates a Failure Result value. + /// + /// The failure message. + /// The inner exception. + /// The context values. + /// The type of the success value. + public static Result Failure(string failureMessage, Exception innerException, Dictionary context) + { + return Result.Failure(new ExceptionWithContext(failureMessage, innerException, context)); + } } } diff --git a/Test/ResultTests.cs b/Test/ResultTests.cs index afef0dc..b1260d0 100644 --- a/Test/ResultTests.cs +++ b/Test/ResultTests.cs @@ -138,7 +138,7 @@ public void ToString_Returns_EmptyString_If_Success_Value_Is_Null() [Test] public void ToString_Returns_EmptyString_If_Failure_Value_Is_Null() { - Result.Failure(null).ToString().ShouldBeEmpty(); + Result.Failure((ExceptionWithContext)null).ToString().ShouldBeEmpty(); } [Test]