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 Should_Not_Select_Square_Of_Ten_Given_Failed_State() { Failable <int> input = default; // From value input .Pipe( Where <int>(x => x % 2 == 1) ) .Select(_ => _ * _) .Match( success: (_) => throw new Exception("Test has failed"), failure: (_) => Assert.Equal(WHERE_EXCEPTION_MESSAGE, _.Message) ); // From exception Failable .From <object>(new Exception("It could not create the value")) .Pipe( Where <object>(x => x is not Exception) ) .Match( success: (_) => throw new Exception("Test has failed"), failure: (_) => Assert.Equal("It could not create the value", _.Message) ); }
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)); }
private void onRegisterRejected(object sender, Failable e) { switch (e.ErrorCode) { case 3: DisplayAlert("Fehler", Strings.Error_MailAlreadyInUse, "OK"); break; case 4: DisplayAlert("Fehler", Strings.Error_UsernameAlreadyInUse, "OK"); break; case 5: DisplayAlert("Fehler", Strings.Error_InvalidMail, "OK"); break; case 12: DisplayAlert("Fehler", Strings.Error_InvalidUsername, "OK"); break; case 13: DisplayAlert("Fehler", Strings.Error_InvalidPassword, "OK"); break; default: OnError(sender, e); break; } }
public void OrThrow_DoesNotThrowIfSuccess() { var testValue = ""; //to be overwritten by "happy" Assert.DoesNotThrow(() => testValue = Failable <string, int> .Success("HAPPY").OrThrow()); Assert.That(testValue, Is.EqualTo("HAPPY")); }
public void OrThrowWithText_DoesNotThrowIfSuccess() { var testValue = 0; Assert.DoesNotThrow(() => testValue = Failable <int, int> .Success(1).OrThrow("Test")); Assert.That(testValue, Is.EqualTo(1)); }
public void MapFailure_Success() { var original = Failable <bool, string> .Success(false); var result = original.MapFailure(s => s += " welt"); Assert.That(result.OrThrow(), Is.EqualTo(false)); }
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 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 Equals_SuccessInequal() { var x = Failable <int, string> .Success(4); var y = Failable <int, string> .Success(5); Assert.That(x.Equals(y), Is.False); }
public void TryGet_Result_Success() { var failable = Failable <string, Exception> .Success("blub"); failable.TryGetValue(out var s); Assert.That(s, Is.EqualTo("blub")); }
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 ConstructSuccess_NotNull() { var testValue = Failable <object, 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 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 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 ConvertToMaybe_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); var maybe = failable.ToMaybe(); Assert.That(maybe.IsNone, Is.True); }
public void TryGet_Value_Failure() { var failable = Failable <string, Exception> .Failure(new ArgumentException()); failable.TryGetValue(out var s); Assert.IsNull(s); }
public void ConvertToOption_Some() { var failable = Failable <string, int> .Success("hubba"); var option = failable.ToOption(); Assert.That(option.IsSome, Is.True); }
public void TryGet_ErrorResult_Success() { var failable = Failable <string, Exception> .Success("blah"); failable.TryGetFailure(out var s); Assert.IsNull(s); }
public void ConvertToFailable_None() { var maybe = Maybe <string> .None; Failable <string, ArgumentException> failable = maybe.ToFailable(new ArgumentException("msg")); Assert.That(failable.IsFailure, Is.True); Assert.That(failable.FailureOrThrow().Message, Is.EqualTo("msg")); }
public void ConvertToOption_None() { var failable = Failable <string, int> .Failure(42); var option = failable.ToOption(); Assert.That(option.IsFailure, Is.True); }
public void Map_Success() { var original = Failable <string, bool> .Success("hallo"); var result = original.Map(s => s += " welt"); Assert.That(result.OrThrow, Is.EqualTo("hallo welt")); }
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 ConvertToFailable_Success() { var EFailable = EFailable <string> .Success("hubba"); Failable <string, Exception> failable = EFailable.ToFailable(); Assert.That(failable.IsSuccess, Is.True); }
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 FlatMapToDifferentType() { var one = Failable <int, bool> .Success(1); Failable <string, bool> onePlusOne = one.FlatMap(i => Failable <string, bool> .Success($"{i}+1=2")); Assert.That(onePlusOne.OrThrow(), Is.EqualTo("1+1=2")); }
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")); }