public void ResultActionSafeScope() { int counter = 0; Result result = ResultScope.SafeResult(() => ++ counter); Assert.AreEqual(1, counter); CheckResultOk(result); var thrownException = new Exception("My exception"); int testVar = 12; result = ResultScope.SafeResult( () => { ++counter; if (testVar > 0) { throw thrownException; } ++counter; }); Assert.AreEqual(2, counter); CheckResultFail(result, "My exception", thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeResult((Action)null)); }
public void ResultSafeScope() { Result result = ResultScope.SafeResult(Result.Ok); CheckResultOk(result); result = ResultScope.SafeResult(() => Result.Warn("My warning")); CheckResultWarn(result, "My warning"); result = ResultScope.SafeResult(() => Result.Fail("My failure")); CheckResultFail(result, "My failure"); var thrownException = new Exception("My exception"); result = ResultScope.SafeResult(() => throw thrownException); CheckResultFail(result, "My exception", thrownException); Assert.Throws <ArgumentNullException>(() => ResultScope.SafeResult(null)); }