public void OrThrowWithText_DoesNotThrowIfSome() { var testValue = 0; Assert.DoesNotThrow(() => testValue = EOption <int> .Some(1).OrThrow("Test")); Assert.That(testValue, Is.EqualTo(1)); }
public void ConvertToEOption_None() { var maybe = Maybe <string> .None; EOption <string> EOption = maybe.ToEOption(); Assert.That(EOption.IsNone, 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 OrThrow_DoesNotThrowIfSome() { var testValue = ""; //to be overwritten by "happy" Assert.DoesNotThrow(() => testValue = EOption <string> .Some("HAPPY").OrThrow()); Assert.That(testValue, Is.EqualTo("HAPPY")); }
public async Task <AppResult <Rate_vw> > SelectOptionAsync(EOption option) { switch (option) { case EOption.USD_EUR: return(await _service.GetRateAsync(ECurrency.USD, ECurrency.EUR)); case EOption.USD_GBP: return(await _service.GetRateAsync(ECurrency.USD, ECurrency.GBP)); case EOption.EUR_USD: return(await _service.GetRateAsync(ECurrency.EUR, ECurrency.USD)); case EOption.EUR_GBP: return(await _service.GetRateAsync(ECurrency.EUR, ECurrency.GBP)); case EOption.GPB_USD: return(await _service.GetRateAsync(ECurrency.GBP, ECurrency.USD)); case EOption.GPB_EUR: return(await _service.GetRateAsync(ECurrency.GBP, ECurrency.EUR)); default: throw new InvalidOptionException(); } }
public void TryGet_Result_Some() { var EOption = EOption <string> .Some("blub"); EOption.TryGetValue(out var s); Assert.That(s, Is.EqualTo("blub")); }
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 FlatMapToDifferentType() { var one = EOption <int> .Some(1); EOption <string> onePlusOne = one.FlatMap(i => EOption <string> .Some($"{i}+1=2")); Assert.That(onePlusOne.OrThrow(), Is.EqualTo("1+1=2")); }
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 Map_Success() { var original = EOption <string> .Some("hallo"); var result = original.Map(s => s += " welt"); Assert.That(result.OrThrow, Is.EqualTo("hallo welt")); }
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 ConstructNone_ViaNullableWithoutValue() { var testValue = EOption <int> .From(new int?()); Assert.That(testValue.IsNone, Is.True); Assert.That(testValue.IsSome, Is.False); Assert.That(testValue.IsFailure, Is.False); }
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 Equals_SomeInequal() { var x = EOption <int> .Some(4); var y = EOption <int> .Some(5); Assert.That(x.Equals(y), Is.False); }
public void ConstructSome_ViaActualValue() { var testValue = EOption <object> .Some(new object()); Assert.That(testValue.IsSome, Is.True); Assert.That(testValue.IsNone, Is.False); Assert.That(testValue.IsFailure, 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 ConvertToEOption_Success() { var EFailable = EFailable <string> .Success("hubba"); EOption <string> EOption = EFailable.ToEOption(); Assert.That(EOption.IsSome, Is.True); }
public void ConstructNone_ViaSomeIsNull() { var testValue = EOption <object> .From(null); Assert.That(testValue.IsSome, Is.False); Assert.That(testValue.IsNone, Is.True); Assert.That(testValue.IsFailure, Is.False); }
public FileWriter(string fileName, EOption typeOfFile, string ftpLogin = "", string ftpPassword = "") { _typeOfFile = typeOfFile.ToString(); _login = ftpLogin; _password = ftpPassword; _fileNameWithoutExtension = fileName; _content = "Message here"; }
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 ConvertToEOption_Some() { var maybe = Maybe <string> .Some("hubba"); EOption <string> EOption = maybe.ToEOption(); Assert.That(EOption.IsSome, 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 AddOption(EOption aOption, byte[] aValue) { List <byte> option = new List <byte>(); option.Add((byte)aOption); option.Add((byte)aValue.Length); option.AddRange(aValue); iOptions.AddRange(option); }
public void ConvertToEFailable_Some() { var EOption = EOption <string> .Some("hallo"); var failable = EOption.ToEFailable(new ArgumentException()); Assert.That(failable.IsSuccess, Is.True); Assert.That(failable.OrThrow, Is.EqualTo("hallo")); }
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")); }
public void ConvertToOption_Some() { var EOption = EOption <string> .Some("hallo"); var option = EOption.ToOption(); Assert.That(option.IsSome, Is.True); Assert.That(option.OrThrow, Is.EqualTo("hallo")); }
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")); }
public void OrConvertToFailable_Some() { var eoption = EOption <int> .Some(123); var failable = eoption.OrToFailable(456); Assert.That(failable.IsSuccess, Is.True); Assert.That(failable.OrThrow, Is.EqualTo(123)); }
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")); }