public void ConstructFailure_ErrorNotNull()
        {
            var testValue = EOption <object> .Failure(new ArgumentException());

            Assert.That(testValue.IsSome, Is.False);
            Assert.That(testValue.IsNone, Is.False);
            Assert.That(testValue.IsFailure, Is.True);
        }
        public void TryGet_Value_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException());

            EOption.TryGetValue(out var s);

            Assert.IsNull(s);
        }
        public void Equals_FailedEqualObjects()
        {
            var x = EOption <int> .Failure(new ArgumentException());

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

            Assert.That(x.Equals(y), Is.False);
        }
        public void ConvertToMaybe_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException());

            var maybe = EOption.ToMaybe();

            Assert.That(maybe.IsNone, Is.True);
        }
        public void Equals_DifferentTypeInequalForFailure()
        {
            var x = EOption <int> .Failure(new ArgumentException());

            var y = EOption <object> .Failure(new ArgumentException());

            Assert.That(x.Equals(y), Is.False);
        }
        public void Map_NestingInMap()
        {
            var flag1 = EOption <bool> .Some(true);

            var result = flag1.Map(_ => EOption <bool> .Some(true));

            Assert.That(result.Or(EOption <bool> .Failure(new ArgumentException("disgusting"))).Or(false), Is.True);
        }
        public void ConvertToFailable_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException("msg"));

            var failable = EOption.ToFailable(new ArgumentException("notMsg")); //different exception text!

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
        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"));
        }
        public void OrConvertToFailable_Failure()
        {
            var eoption = EOption <int> .Failure(new ArgumentException( "msg" ));

            var failable = eoption.OrToFailable(456);

            Assert.That(failable.IsFailure, Is.True);
            Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
Beispiel #10
0
        public void Equals_FailedSameInstance()
        {
            var e = new ArgumentException();
            var x = EOption <int> .Failure(e);

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

            Assert.That(x.Equals(y), Is.True);
        }
Beispiel #11
0
        public void ConvertToOption_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException( "msg" ));

            Option <string, Exception> option = EOption.ToOption();

            Assert.That(option.IsFailure, Is.True);
            Assert.That(option.FailureOrThrow().Message, Is.EqualTo("msg"));
        }
Beispiel #12
0
        public void Map_Failure()
        {
            var argEx = new ArgumentException();

            var original = EOption <string> .Failure(argEx);

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

            Assert.That(result.FailureOrThrow, Is.EqualTo(argEx));
        }
Beispiel #13
0
        public void OrWithParallelSubtype_Failure()
        {
            var myOtherSubclass = new MyOtherSubclass();

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

            var actualValue = underTest.Or(myOtherSubclass);

            Assert.That(actualValue, Is.SameAs(myOtherSubclass));
        }
Beispiel #14
0
        public void Equals_None()
        {
            var some = EOption <string> .Some("something");

            var fail = EOption <string> .Failure(new ArgumentException( "inexcusable" ));

            Assert.That(EOption <string> .None.Equals(some), Is.False);
            Assert.That(EOption <string> .None.Equals(fail), Is.False);
            Assert.That(EOption <string> .None.Equals(EOption <string> .None), Is.True);
        }
Beispiel #15
0
        public void Flatten_None()
        {
            var a = EOption <string> .None;
            var b = EOption <EOption <string> > .Some(EOption <string> .None);

            var c = EOption <EOption <string> > .Some(EOption <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));
        }
Beispiel #16
0
        public void Equals_FailedInequalToSome()
        {
            var x = EOption <int> .Failure(new ArgumentException( "how appaling!" ));

            var y = EOption <int> .Some(0);

            var z = EOption <EOption <int> > .Some(y);

            Assert.That(x.Equals(y), Is.False);
            Assert.That(x.Equals(z), Is.False);
        }
Beispiel #17
0
        public void Flatten_Failure()
        {
            var a = EOption <string> .Failure(new Exception( "" ));

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

            var c = EOption <EOption <string> > .Some(EOption <string> .None);

            Assert.That(b, Is.Not.EqualTo(a));
            Assert.That(b.Flatten(), Is.EqualTo(a));
            Assert.That(b.Flatten(), Is.Not.EqualTo(c));
        }
Beispiel #18
0
        public void Nesting()
        {
            var someInnerSome = EOption <EOption <int> > .Some(EOption <int> .Some(123));

            var someInnerNone = EOption <EOption <int> > .Some(EOption <int> .None);

            var someInnerFail = EOption <EOption <int> > .Some(EOption <int> .Failure(new ArgumentException()));

            var failure = EOption <EOption <int> > .Failure(new ArgumentException());

            var none = EOption <EOption <int> > .None;

            Assert.That(someInnerSome.IsSome, Is.True);
            Assert.That(someInnerNone.IsSome, Is.True);
            Assert.That(someInnerFail.IsSome, Is.True);
            Assert.That(someInnerSome.OrThrow().IsSome, Is.True);
            Assert.That(someInnerNone.OrThrow().IsNone, Is.True);
            Assert.That(someInnerFail.OrThrow().IsFailure, Is.True);
            Assert.That(failure.IsFailure, Is.True);
            Assert.That(none.IsNone, Is.True);
        }
Beispiel #19
0
 public void Or_FailureOrNull()
 {
     Assert.That(EOption <object> .Failure(new ArgumentException()).Or(null), Is.Null);
 }
Beispiel #20
0
        public void Error_ReturnsFailure()
        {
            var argEx = new ArgumentException();

            Assert.That(EOption <string> .Failure(argEx).FailureOrThrow(), Is.EqualTo(argEx));
        }
Beispiel #21
0
 public void Or_FailureOrValue()
 {
     Assert.That(EOption <int> .Failure(new ArgumentException()).Or(1), Is.EqualTo(1));
 }
Beispiel #22
0
 public void OrThrowWithText_DoesThrowIfFailure()
 {
     Assert.Throws <OptionFailureException>(() => EOption <string> .Failure(new ArgumentException()).OrThrow("Test"));
 }
Beispiel #23
0
 public void OrThrow_ThrowsIfFailure()
 {
     Assert.Throws <OptionFailureException>(() => EOption <string> .Failure(new ArgumentException()).OrThrow());
 }
Beispiel #24
0
 public void ToString_Failure()
 {
     Assert.That(EOption <TestObj> .Failure(new ArgumentException("evil")).ToString(), Is.EqualTo("[EOption<TestObj>.Failure: System.ArgumentException: evil]"));
 }
Beispiel #25
0
        public void TryGet_Result_Failure()
        {
            var EOption = EOption <string> .Failure(new ArgumentException());

            Assert.IsFalse(EOption.TryGetValue(out var s));
        }
Beispiel #26
0
        public void Is_PredicateUndefined()
        {
            var EOption = EOption <string> .Failure(new ArgumentException());

            Assert.That(EOption.Holds(s => s.Equals("hubba-hub")), Is.EqualTo(false));
        }
Beispiel #27
0
 public void ConstructFailure_ErrorNull()
 {
     Assert.Throws <OptionFailureConstructionException>(() => EOption <object> .Failure(null));
 }
Beispiel #28
0
        public void IsNot_FalseWhenFailed()
        {
            var f = EOption <string> .Failure(new ArgumentException());

            Assert.That(f.IsNot("hubba"), Is.EqualTo(false));
        }