예제 #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 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);
        }
예제 #3
0
        public void ConvertToEOption_Success()
        {
            var EFailable = EFailable <string> .Success("hubba");

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

            Assert.That(EOption.IsSome, Is.True);
        }
예제 #4
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"));
        }
예제 #5
0
        public void Equals_SuccessInequal()
        {
            var x = EFailable <int> .Success(4);

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

            Assert.That(x.Equals(y), Is.False);
        }
예제 #6
0
        public void ConvertToFailable_Success()
        {
            var EFailable = EFailable <string> .Success("hubba");

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

            Assert.That(failable.IsSuccess, Is.True);
        }
예제 #7
0
        public void TryGet_Result_Success()
        {
            var EFailable = EFailable <string> .Success("blub");

            EFailable.TryGetValue(out var s);

            Assert.That(s, Is.EqualTo("blub"));
        }
예제 #8
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));
        }
예제 #9
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"));
        }
예제 #10
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"));
        }
예제 #11
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"));
        }
예제 #12
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"));
        }
예제 #13
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));
        }
예제 #14
0
        public void OrWithParallelType_Success()
        {
            var mySubclass      = new MySubclass();
            var myOtherSubclass = new MyOtherSubclass();

            var underTest = EFailable <MyClass> .Success(mySubclass);

            var actualValue = underTest.Or(myOtherSubclass);

            Assert.That(actualValue, Is.SameAs(mySubclass));
        }
예제 #15
0
        public void Equals_FailedInequalToSuccess()
        {
            var x = EFailable <int> .Failure(new ArgumentException("how appaling!"));

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

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

            Assert.That(x.Equals(y), Is.False);
            Assert.That(x.Equals(z), Is.False);
        }
예제 #16
0
        public void Flatten_Some()
        {
            var a = EFailable <string> .Success("hallo");

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

            var c = EFailable <EFailable <string> > .Success(EFailable <string> .Failure(new Exception("")));

            Assert.That(b, Is.Not.EqualTo(a));
            Assert.That(b.Flatten(), Is.EqualTo(a));
            Assert.That(b.Flatten(), Is.Not.EqualTo(c));
        }
예제 #17
0
        public void Equals_SuccessEqual()
        {
            var t1 = new Tuple <string, int>("abc", 123);
            var t2 = new Tuple <string, int>("abc", 123);

            var x = EFailable <Tuple <string, int> > .Success(t1);

            var y = EFailable <Tuple <string, int> > .Success(t2);

            Assert.That(t1.Equals(t2), Is.True);
            Assert.That(x.Equals(y), Is.True);
        }
예제 #18
0
        public void Equals_DifferentTypeInequal()
        {
            var t1 = new Tuple <string, int>("abc", 123);
            var t2 = new Tuple <string, string>("abc", "123");

            var x = EFailable <Tuple <string, int> > .Success(t1);

            var y = EFailable <Tuple <string, string> > .Success(t2);

            Assert.That(t1.Equals(t2), Is.False);
            Assert.That(x.Equals(y), Is.False);
        }
예제 #19
0
        public void Flatten_Failure()
        {
            var a = EFailable <string> .Failure(new Exception( "" ));

            var b = EFailable <EFailable <string> > .Success(a); //use same instance so that Exception.Equals() returns true

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

            Assert.That(b, Is.Not.EqualTo(a));
            Assert.That(b.Flatten(), Is.EqualTo(a));
            Assert.That(b.Flatten(), Is.Not.EqualTo(c));
        }
예제 #20
0
        public void Map_NestingInFlatMap_FlattenToOption()
        {
            var flag1 = EFailable <int> .Success(1);

            var flag2 = Option <int, Exception> .Some(2);

         #pragma warning disable CS0618 // Type or member is obsolete
            var result = flag1.FlatMap(outerInt => flag2.Map(innerInt => outerInt + innerInt));
         #pragma warning restore CS0618

            Assert.True(result.IsSome);
            Assert.That(result.Or(-999), Is.EqualTo(3));
        }
예제 #21
0
        public void Equals_Failable_DifferentType()
        {
            var aEFail = EFailable <int> .Success(4);

            var aFail = Failable <int, string> .Success(4);

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

            var bFail = Failable <int, string> .Failure("whatever");

            Assert.That(aEFail, Is.Not.EqualTo(aFail));
            Assert.That(bEFail, Is.Not.EqualTo(bFail));
            Assert.That(aFail, Is.Not.EqualTo(aEFail));
            Assert.That(bFail, Is.Not.EqualTo(bEFail));
        }
예제 #22
0
        public void Nesting()
        {
            var successInnerSuccess = EFailable <EFailable <int> > .Success(EFailable <int> .Success(123));

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

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

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

            Assert.That(successInnerSuccess.IsSuccess, Is.True);
            Assert.That(successInnerFail.IsSuccess, Is.True);
            Assert.That(successInnerSuccess.OrThrow().IsSuccess, Is.True);
            Assert.That(successInnerFail.OrThrow().IsSuccess, Is.False);
            Assert.That(failureInnerSuccess.IsSuccess, Is.False);
            Assert.That(failureInnerFail.IsSuccess, Is.False);
        }
예제 #23
0
        public void Equals_Failable()
        {
            var aEFail = EFailable <int> .Success(4);

            var aFail = Failable <int, Exception> .Success(4);

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

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

            Assert.That(aEFail.GetHashCode(), Is.EqualTo(aFail.GetHashCode()), "HashCode not correct (Success-Case)");
            Assert.That(bEFail.GetHashCode(), Is.EqualTo(bFail.GetHashCode()), "HashCode not correct (Failure-Case)");

            Assert.That(aEFail, Is.EqualTo(aFail), "EFailable-Equals is buggy! (Success-Case)");
            Assert.That(bEFail, Is.EqualTo(bFail), "EFailable-Equals is buggy! (Failure-Case)");
            Assert.That(aFail, Is.EqualTo(aEFail), "Implementation of Failable is not accepting EFailable! (Success-Case)");
            Assert.That(bFail, Is.EqualTo(bEFail), "Implementation of Failable is not accepting EFailable! (Failure-Case)");

            Assert.That(aEFail, Is.Not.EqualTo(bFail));  //sanity-check
        }
예제 #24
0
 public void Or_Value()
 {
     Assert.That(EFailable <int> .Success(1).Or(2), Is.EqualTo(1));
 }
예제 #25
0
 public void Error_ThrowsIfSuccess()
 {
     Assert.Throws <FailableNoFailureException>(() => EFailable <string> .Success("HAPPY").FailureOrThrow());
 }
예제 #26
0
        public void TryGet_Value_Success()
        {
            var EFailable = EFailable <string> .Success("blub");

            Assert.IsTrue(EFailable.TryGetValue(out var s));
        }
예제 #27
0
        public void Is_PredicateNonMatchingDefined()
        {
            var EFailable = EFailable <string> .Success("hubba");

            Assert.That(EFailable.Holds(s => s.Equals("hubba-hub")), Is.EqualTo(false));
        }
예제 #28
0
        public void Is_DefinedFalse()
        {
            var f = EFailable <string> .Success("hubba");

            Assert.That(f.Is("whatever"), Is.EqualTo(false));
        }
예제 #29
0
        public void Is_DefinedTrue()
        {
            var f = EFailable <string> .Success("hubba");

            Assert.That(f.Is("hubba"), Is.EqualTo(true));
        }
예제 #30
0
 public void ConstructSuccess_Null()
 {
     Assert.That(() => EFailable <object> .Success(null), Throws.TypeOf <FailableSuccessConstructionException>());
 }