Beispiel #1
0
        public void Ok_Success()
        {
            Result <int, string> wrappedResult = new Success <int, string>(10);
            var guard = new ResultGuard <int, string, int>(wrappedResult);

            guard.Where(i => i == 5, i => 0);
            guard.Where(i => i == 10, i => i * 2);
            var result = guard.Do();

            Assert.AreEqual(result, 20);
        }
Beispiel #2
0
        public void Ok_Failure_MultipleMatches()
        {
            Result <int, string> wrappedResult = new Failure <int, string>("Error");
            var guard = new ResultGuard <int, string, string>(wrappedResult);

            guard.Where(i => i == "Error", i => "first match");
            guard.Where(i => i == "Error", i => "second match");
            var result = guard.Do();

            Assert.AreEqual(result, "first match");
        }
Beispiel #3
0
        public void Ok_Success_MultipleMatches()
        {
            Result <int, string> wrappedResult = new Success <int, string>(10);
            var guard = new ResultGuard <int, string, string>(wrappedResult);

            guard.Where(i => i == 10, i => "first match");
            guard.Where(i => i == 10, i => "second match");
            var result = guard.Do();

            Assert.AreEqual(result, "first match");
        }
Beispiel #4
0
        public void Ok_Failure()
        {
            Result <int, string> wrappedResult = new Failure <int, string>("Error");
            var guard = new ResultGuard <int, string, string>(wrappedResult);

            guard.Where(i => i == "something", i => string.Empty);
            guard.Where(i => i == "Error", i => i + i);
            var result = guard.Do();

            Assert.AreEqual(result, "ErrorError");
        }
Beispiel #5
0
        public void Ok_Failure_FallsThroughToDefault()
        {
            Result <int, string> wrappedResult = new Failure <int, string>("Error");
            var guard = new ResultGuard <int, string, string>(wrappedResult);

            guard.Where(i => i == string.Empty, i => "no match");
            guard.Where(i => i == string.Empty, i => "no match");
            guard.Default((string i) => "match");
            var result = guard.Do();

            Assert.AreEqual(result, "match");
        }
Beispiel #6
0
        public void Ok_Success_FallsThroughToDefault()
        {
            Result <int, string> wrappedResult = new Success <int, string>(10);
            var guard = new ResultGuard <int, string, string>(wrappedResult);

            guard.Where(i => i == 11, i => "no match");
            guard.Where(i => i == 11, i => "no match");
            guard.Default((int i) => "match");
            var result = guard.Do();

            Assert.AreEqual(result, "match");
        }