public void ConstructFailure_ErrorNotNull() { var testValue = Failable <object, object> .Failure(new object()); Assert.That(testValue.IsSuccess, Is.False); Assert.That(testValue.IsFailure, Is.True); }
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)); }
public void Equals_DifferentTypeInequalForFailure() { var x = Failable <int, string> .Failure("horrible"); var y = Failable <object, string> .Failure("horrible"); Assert.That(x.Equals(y), Is.False); }
public void Equals_FailedInequal() { var x = Failable <object, string> .Failure("what a disappointment"); var y = Failable <object, string> .Failure("yet another disappointment"); Assert.That(x.Equals(y), Is.False); }
public void Equals_FailedEqual() { var x = Failable <object, int> .Failure(123); var y = Failable <object, int> .Failure(123); Assert.That(x.Equals(y), Is.True); }
public void OrThrowWithText_DoesThrowIfFailure() { var f = Failable <string, int> .Failure(-1); var excp = Assert.Throws <FailableFailureException>(() => f.OrThrow("test")); Assert.That(excp.Message, Is.EqualTo("test")); }
public void MapFailureToDifferentType() { var one = Failable <bool, int> .Failure(1); Failable <bool, string> onePlusOne = one.MapFailure(i => $"{i}+1=2"); Assert.That(onePlusOne.FailureOrThrow(), Is.EqualTo("1+1=2")); }
public void TryGet_Value_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); failable.TryGetValue(out var s); Assert.IsNull(s); }
public void ConvertToMaybe_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); var maybe = failable.ToMaybe(); Assert.That(maybe.IsNone, Is.True); }
public void MapFailure_Failure() { var original = Failable <bool, string> .Failure("hallo"); var result = original.MapFailure(s => s += " welt"); Assert.That(result.FailureOrThrow(), Is.EqualTo("hallo welt")); }
public void ConvertToOption_None() { var failable = Failable <string, int> .Failure(42); var option = failable.ToOption(); Assert.That(option.IsFailure, Is.True); }
public void ConvertToOption_SwitchValueType_None() { var failable = Failable <string, int> .Failure(42); var option = failable.ToOptionWith((s) => true); Assert.That(option.IsFailure, Is.True); }
public void Map_Failure() { var original = Failable <string, bool> .Failure(false); var result = original.Map(s => s += " welt"); Assert.That(result.FailureOrThrow, Is.EqualTo(false)); }
public void Map_NestingInMap() { var flag = Failable <bool, string> .Success(true); var result = flag.Map(_ => Failable <bool, string> .Success(true)); Assert.That(result.Or(Failable <bool, string> .Failure("disgusting")).Or(false), Is.True); }
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")); }
public void ConvertToEFailable_WithConverter_Failure() { var failable = Failable <int, string> .Failure("will-be-overwritten"); var eFailable = failable.ToEFailableWith(i => $"1{i}", new Exception("new")); Assert.That(eFailable.IsFailure, Is.True); Assert.That(eFailable.FailureOrThrow().Message, Is.EqualTo("new")); }
public void Map_Failure_SideEffect() { var myInt = 0; var original = Failable <string, bool> .Failure(false); var result = original.Map(s => ++ myInt); Assert.That(myInt, Is.EqualTo(0)); }
public void TryGet_ErrorResult_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException("msg")); failable.TryGetFailure(out var e); Assert.That(e, Is.TypeOf <ArgumentException>()); Assert.That(e.Message, Is.EqualTo("msg")); }
public void OrWithParallelType_Failure() { var myOtherSubclass = new MyOtherSubclass(); var underTest = Failable <MyClass, Exception> .Failure(new ArgumentException( "irrelevant" )); var actualValue = underTest.Or(myOtherSubclass); Assert.That(actualValue, Is.SameAs(myOtherSubclass)); }
public void Equals_FailedInequalToSuccess() { var x = Failable <int, string> .Failure("how appaling!"); var y = Failable <int, string> .Success(0); var z = Failable <Failable <int, string>, string> .Success(y); Assert.That(x.Equals(y), Is.False); Assert.That(x.Equals(z), Is.False); }
public void Flatten_Failure() { var a = Failable <string, int> .Failure(42); var b = Failable <Failable <string, int>, int> .Success(Failable <string, int> .Failure(42)); var c = Failable <Failable <string, int>, int> .Success(Failable <string, int> .Success("whatever")); Assert.That(b, Is.Not.EqualTo(a)); Assert.That(b.Flatten(), Is.EqualTo(a)); Assert.That(b.Flatten(), Is.Not.EqualTo(c)); }
public void Flatten_DifferentFailType_Failure() { var a = Failable <string, int> .Failure(42); var b = Failable <Failable <string, string>, int> .Success(Failable <string, string> .Failure("error")); var c = Failable <Failable <string, string>, int> .Success(Failable <string, string> .Success("whatever")); Assert.That(b, Is.Not.EqualTo(a)); Assert.That(b.Flatten((s) => 42), Is.EqualTo(a)); Assert.That(b.Flatten((s) => 42), Is.Not.EqualTo(c)); }
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)); }
public void Nesting() { var successInnerSuccess = Failable <Failable <int, string>, string> .Success(Failable <int, string> .Success(123)); var successInnerFail = Failable <Failable <int, string>, string> .Success(Failable <int, string> .Failure("hallo")); var failureInnerSuccess = Failable <int, Failable <int, string> > .Failure(Failable <int, string> .Success(123)); var failureInnerFail = Failable <int, Failable <int, string> > .Failure(Failable <int, string> .Failure("hallo")); 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); Assert.That(failureInnerSuccess.FailureOrThrow().IsSuccess, Is.True); Assert.That(failureInnerFail.FailureOrThrow().IsSuccess, Is.False); }
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 }
public void Equals_Option_DifferentType() { var aEOption = EOption <int> .Some(4); var aOption = Option <int, string> .Some(4); var bEOption = EOption <int> .None; var bOption = Option <int, string> .None; var exception = new ArgumentException(); var cEOption = EFailable <int> .Failure(exception); var cOption = Failable <int, string> .Failure("whatever"); Assert.That(aEOption, Is.Not.EqualTo(aOption)); Assert.That(bEOption, Is.Not.EqualTo(bOption)); Assert.That(cEOption, Is.Not.EqualTo(cOption)); Assert.That(aOption, Is.Not.EqualTo(aEOption)); Assert.That(bOption, Is.Not.EqualTo(bEOption)); Assert.That(cOption, Is.Not.EqualTo(cEOption)); }
public void TryGet_Result_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); Assert.IsFalse(failable.TryGetValue(out var s)); }
public void ContainsFalseWhenNone() { var f = Failable <string, Exception> .Failure(new ArgumentException()); Assert.That(f.Is("hubba"), Is.EqualTo(false)); }
public void Is_PredicateUndefined() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); Assert.That(failable.Holds(s => s.Equals("hubba-hub")), Is.EqualTo(false)); }
public void TryGet_Error_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); Assert.IsTrue(failable.TryGetFailure(out var s)); }