示例#1
0
        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));
        }
示例#2
0
        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));
        }