示例#1
0
        public void OrThrow_DoesNotThrowIfSuccess()
        {
            var testValue = ""; //to be overwritten by "happy"

            Assert.DoesNotThrow(() => testValue = EFailable <string> .Success("HAPPY").OrThrow());
            Assert.That(testValue, Is.EqualTo("HAPPY"));
        }
示例#2
0
        public void ConstructFailure_ErrorNotNull()
        {
            var testValue = EFailable <object> .Failure(new ArgumentException());

            Assert.That(testValue.IsSuccess, Is.False);
            Assert.That(testValue.IsFailure, Is.True);
        }
示例#3
0
        public void ConstructFailure_WrappingErrorGiven()
        {
            var testValue = EFailable <object> .Wrapping(() => new ArgumentException());

            Assert.That(testValue.IsSuccess, Is.True);
            Assert.That(testValue.IsFailure, Is.False);
        }
示例#4
0
        public void Equals_Option()
        {
            var aEOption = EOption <int> .Some(4);

            var aOption = Option <int, Exception> .Some(4);

            var bEOption = EOption <int> .None;
            var bOption  = Option <int, Exception> .None;

            var exception = new ArgumentException();
            var cEOption  = EFailable <int> .Failure(exception);

            var cOption = Failable <int, Exception> .Failure(exception);

            Assert.That(aEOption.GetHashCode(), Is.EqualTo(aOption.GetHashCode()), "HashCode not correct (Success-Case)");
            Assert.That(bEOption.GetHashCode(), Is.EqualTo(bOption.GetHashCode()), "HashCode not correct (None-Case)");
            Assert.That(cEOption.GetHashCode(), Is.EqualTo(cOption.GetHashCode()), "HashCode not correct (Failure-Case)");

            Assert.That(aEOption, Is.EqualTo(aOption), "EOption-Equals is buggy! (Some-Case)");
            Assert.That(bEOption, Is.EqualTo(bOption), "EOption-Equals is buggy! (None-Case)");
            Assert.That(cEOption, Is.EqualTo(cOption), "EOption-Equals is buggy! (Failure-Case)");
            Assert.That(aOption, Is.EqualTo(aEOption), "Implementation of Option is not accepting EOption! (Some-Case)");
            Assert.That(bOption, Is.EqualTo(bEOption), "Implementation of Option is not accepting EOption! (None-Case)");
            Assert.That(cOption, Is.EqualTo(cEOption), "Implementation of Option is not accepting EOption! (Failure-Case)");

            Assert.That(aEOption, Is.Not.EqualTo(bOption));  //sanity-checks
            Assert.That(cOption, Is.Not.EqualTo(bEOption));
        }
示例#5
0
        public void Equals_DifferentTypeInequalForFailure()
        {
            var x = EFailable <int> .Failure(new ArgumentException("horrible"));

            var y = EFailable <object> .Failure(new ArgumentException("horrible"));

            Assert.That(x.Equals(y), Is.False);
        }
示例#6
0
        public void Equals_FailedInequal()
        {
            var x = EFailable <object> .Failure(new ArgumentException("what a disappointment"));

            var y = EFailable <object> .Failure(new ArgumentException("yet another disappointment"));

            Assert.That(x.Equals(y), Is.False);
        }
示例#7
0
        public void Equals_FailedEqualObjects()
        {
            var x = EFailable <int> .Failure(new ArgumentException());

            var y = EFailable <int> .Failure(new ArgumentException());

            Assert.That(x.Equals(y), Is.False);
        }
示例#8
0
        public void Equals_SuccessInequal()
        {
            var x = EFailable <int> .Success(4);

            var y = EFailable <int> .Success(5);

            Assert.That(x.Equals(y), Is.False);
        }
示例#9
0
        public void ConvertToEFailable_None()
        {
            var maybe = Maybe <string> .None;
            EFailable <string> failable = maybe.ToEFailable(new ArgumentException("msg"));

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
示例#10
0
        public void ConstructSuccess_NotNull()
        {
            var testValue = EFailable <object> .Success(new object());

            Assert.That(testValue.IsSuccess, Is.True);
            Assert.That(testValue.IsFailure, Is.False);
            Assert.That(testValue.Enum, Is.EqualTo(FlbType.Success));
        }
示例#11
0
        public void ConvertToEOption_Success()
        {
            var EFailable = EFailable <string> .Success("hubba");

            EOption <string> EOption = EFailable.ToEOption();

            Assert.That(EOption.IsSome, Is.True);
        }
示例#12
0
        public void ConvertToMaybe_Failure()
        {
            var EFailable = EFailable <string> .Failure(new ArgumentException());

            var maybe = EFailable.ToMaybe();

            Assert.That(maybe.IsNone, Is.True);
        }
示例#13
0
        public void TryGet_Result_Success()
        {
            var EFailable = EFailable <string> .Success("blub");

            EFailable.TryGetValue(out var s);

            Assert.That(s, Is.EqualTo("blub"));
        }
示例#14
0
        public void ConvertFailable_Failure()
        {
            var EFailable = EFailable <string> .Failure(new ArgumentException( "abc" ));

            Failable <string, Exception> failable = EFailable.ToFailable();

            Assert.That(failable.IsFailure, Is.True);
        }
示例#15
0
        public void TryGet_Value_Failure()
        {
            var EFailable = EFailable <string> .Failure(new ArgumentException());

            EFailable.TryGetValue(out var s);

            Assert.IsNull(s);
        }
示例#16
0
        public void Map_NestingInMap()
        {
            var flag = EFailable <bool> .Success(true);

            var result = flag.Map(_ => EFailable <bool> .Success(true));

            Assert.That(result.Or(EFailable <bool> .Failure(new ArgumentException())).Or(false), Is.True);
        }
示例#17
0
        public void ConvertToFailable_Success()
        {
            var EFailable = EFailable <string> .Success("hubba");

            Failable <string, Exception> failable = EFailable.ToFailable();

            Assert.That(failable.IsSuccess, Is.True);
        }
示例#18
0
        public void ConvertToEOption_Failure()
        {
            var EFailable = EFailable <string> .Failure(new ArgumentException( "abc" ));

            EOption <string> EOption = EFailable.ToEOption();

            Assert.That(EOption.IsFailure, Is.True);
        }
示例#19
0
        public void Map_Success()
        {
            var original = EFailable <string> .Success("hallo");

            var result = original.Map(s => s += " welt");

            Assert.That(result.OrThrow, Is.EqualTo("hallo welt"));
        }
示例#20
0
        public void FlatMapToDifferentType()
        {
            var one = EFailable <int> .Success(1);

            EFailable <string> onePlusOne = one.FlatMap(i => EFailable <string> .Success($"{i}+1=2"));

            Assert.That(onePlusOne.OrThrow(), Is.EqualTo("1+1=2"));
        }
示例#21
0
        public void ConvertToMaybe_Success()
        {
            var EFailable = EFailable <string> .Success("hallo");

            var maybe = EFailable.ToMaybe();

            Assert.That(maybe.IsSome, Is.True);
            Assert.That(maybe.OrThrow, Is.EqualTo("hallo"));
        }
示例#22
0
        public void OrConvertToEFailable_Failure()
        {
            var option = Option <int, string> .Failure("notMsg");

            EFailable <int> failable = option.OrToEFailable(456, new ArgumentException("msg"));

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
示例#23
0
        public void ConvertToEFailable_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException( "msg" ));

            EFailable <string> failable = EOption.ToEFailable(new ArgumentException("to-be-used-on-none!"));

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
示例#24
0
        public void ConvertToEFailable_Failure()
        {
            var failable = Failable <string, bool> .Failure(true);

            EFailable <string> EFailable = failable.ToEFailable(new ArgumentException("msg"));

            Assert.That(EFailable.IsFailure, Is.True);
            Assert.That(EFailable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
示例#25
0
        public void ConvertToOption_Success()
        {
            var EFailable = EFailable <string> .Success("hubba");

            var option = EFailable.ToOption();

            Assert.That(option.IsSome, Is.True);
            Assert.That(option.OrThrow, Is.EqualTo("hubba"));
        }
示例#26
0
        public void Map_Failure()
        {
            var e        = new ArgumentException();
            var original = EFailable <string> .Failure(e);

            var result = original.Map(s => s += " welt");

            Assert.That(result.FailureOrThrow, Is.EqualTo(e));
        }
示例#27
0
        public void Equals_FailedSameInstance()
        {
            var e = new ArgumentException();
            var x = EFailable <int> .Failure(e);

            var y = EFailable <int> .Failure(e);

            Assert.That(x.Equals(y), Is.True);
        }
示例#28
0
        public void ValuePropagationInFlatMap()
        {
            var hallo = EFailable <string> .Success("hallo");

            var sp = EFailable <string> .Success(" ");

            var result = hallo.FlatMap(h => sp.Map(space => h + space + "welt"));

            Assert.That(result.Or("nix da"), Is.EqualTo("hallo welt"));
        }
示例#29
0
        public void Map_NestingInFlatMap()
        {
            var flag1 = EFailable <int> .Success(1);

            var flag2 = EFailable <int> .Success(2);

            var result = flag1.FlatMap(outerInt => flag2.Map(innerInt => outerInt + innerInt));

            Assert.That(result.Or(-999), Is.EqualTo(3));
        }
示例#30
0
        public void OrWithParallelType_Failure()
        {
            var myOtherSubclass = new MyOtherSubclass();

            var underTest = EFailable <MyClass> .Failure(new ArgumentException( "irrelevant" ));

            var actualValue = underTest.Or(myOtherSubclass);

            Assert.That(actualValue, Is.SameAs(myOtherSubclass));
        }