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")); }
public void ConstructFailure_ErrorNotNull() { var testValue = EFailable <object> .Failure(new ArgumentException()); Assert.That(testValue.IsSuccess, Is.False); Assert.That(testValue.IsFailure, Is.True); }
public void ConstructFailure_WrappingErrorGiven() { var testValue = EFailable <object> .Wrapping(() => new ArgumentException()); Assert.That(testValue.IsSuccess, Is.True); Assert.That(testValue.IsFailure, Is.False); }
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 = EFailable <int> .Failure(new ArgumentException("horrible")); var y = EFailable <object> .Failure(new ArgumentException("horrible")); Assert.That(x.Equals(y), Is.False); }
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); }
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); }
public void Equals_SuccessInequal() { var x = EFailable <int> .Success(4); var y = EFailable <int> .Success(5); Assert.That(x.Equals(y), Is.False); }
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")); }
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)); }
public void ConvertToEOption_Success() { var EFailable = EFailable <string> .Success("hubba"); EOption <string> EOption = EFailable.ToEOption(); Assert.That(EOption.IsSome, Is.True); }
public void ConvertToMaybe_Failure() { var EFailable = EFailable <string> .Failure(new ArgumentException()); var maybe = EFailable.ToMaybe(); Assert.That(maybe.IsNone, Is.True); }
public void TryGet_Result_Success() { var EFailable = EFailable <string> .Success("blub"); EFailable.TryGetValue(out var s); Assert.That(s, Is.EqualTo("blub")); }
public void ConvertFailable_Failure() { var EFailable = EFailable <string> .Failure(new ArgumentException( "abc" )); Failable <string, Exception> failable = EFailable.ToFailable(); Assert.That(failable.IsFailure, Is.True); }
public void TryGet_Value_Failure() { var EFailable = EFailable <string> .Failure(new ArgumentException()); EFailable.TryGetValue(out var s); Assert.IsNull(s); }
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); }
public void ConvertToFailable_Success() { var EFailable = EFailable <string> .Success("hubba"); Failable <string, Exception> failable = EFailable.ToFailable(); Assert.That(failable.IsSuccess, Is.True); }
public void ConvertToEOption_Failure() { var EFailable = EFailable <string> .Failure(new ArgumentException( "abc" )); EOption <string> EOption = EFailable.ToEOption(); Assert.That(EOption.IsFailure, Is.True); }
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")); }
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")); }
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")); }
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")); }
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 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 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")); }
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)); }
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); }
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")); }
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)); }
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)); }