From 07960ffd112a0259abcdaff12016d18db0e005af Mon Sep 17 00:00:00 2001 From: Ody Mbegbu Date: Fri, 12 Jan 2018 16:32:41 +0100 Subject: [PATCH] Consolidates UnWrap and Fixes Bug #10 --- ReadMe.md | 5 ++++- src/Operation/UnWrap.cs | 15 --------------- test/Tests/UnwrapTests.cs | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 94a6c95..0c2980e 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -9,7 +9,7 @@ that tells the calling method that it will not throw an exception rather, any ex Using `Operation` helps ensure that your applications can fail gracefully even in unforeseen circumstances. It's typically used at the boundries between domains/layers in your application.eg. Between Calls from WebApi to Business Layer or between calls from your Business Layer to your DataAccess Layer -## Operation and Operation<T> +## The Operation Class At the Heart of the library are two types. They are `Operation` and `Operation`. An Operation represents the output of a piece of computation. It has two states: Succeeded or Failed. @@ -244,3 +244,6 @@ Task t = op.AsTask(); ``` Note that this is not the same as `Operation.Run` Execution will still block the running Thread + +Documentation available here +[Github Readme](https://github.com/odytrice/Operation/blob/master/ReadMe.md) \ No newline at end of file diff --git a/src/Operation/UnWrap.cs b/src/Operation/UnWrap.cs index 85c3414..961ae3f 100644 --- a/src/Operation/UnWrap.cs +++ b/src/Operation/UnWrap.cs @@ -11,20 +11,6 @@ public static partial class OperationExtensions /// /// Unwraps the Operation if Successful and Throws an Exception if an Operation Fails /// - /// - /// - [DebuggerHidden] - public static void Unwrap(this Operation operation, string message = null) - { - message = message ?? operation.Message; - if (operation.Succeeded == false) - throw (message == null) - ? operation.GetException() - : new Exception(message); - } - /// - /// Unwraps the Operation if Successful and Throws an Exception if an Operation Fails - /// /// /// /// Optional Message to Mask Original Error @@ -32,7 +18,6 @@ public static void Unwrap(this Operation operation, string message = null) [DebuggerHidden] public static T Unwrap(this Operation operation, string message = null) { - message = message ?? operation.Message; if (operation.Succeeded == false) throw (message == null) ? operation.GetException() diff --git a/test/Tests/UnwrapTests.cs b/test/Tests/UnwrapTests.cs index c5a6df1..b514cc3 100644 --- a/test/Tests/UnwrapTests.cs +++ b/test/Tests/UnwrapTests.cs @@ -31,5 +31,28 @@ public void TestOperationResultUnwrap() Assert.IsFalse(operation.Succeeded); Assert.AreEqual(operation.Message, "The Error"); } + + [TestMethod] + public void TestOperationReturnsOriginalException() + { + var operation = Operation.Create(() => throw new ArgumentNullException("Argument Error")); + try + { + operation.Unwrap(); + } + catch(Exception ex) + { + Assert.AreEqual(typeof(ArgumentNullException), ex.GetType()); + } + } + + [TestMethod] + public void TestOperationReturnsSuccessResult() + { + var value = 10; + var operation = Operation.Success(value); + var result = operation.Unwrap(); + Assert.AreEqual(value, result); + } } }