public void Cast_Exception() { object a = "hello"; FSharpResult.Cast <int>(a) .Match(i => Assert.Fail("should not have succeeded with value {0}", i), e => {}); }
public void Cast_OK() { object a = 40; FSharpResult.Cast <int>(a) .Match(i => Assert.AreEqual(40, i), e => Assert.Fail(e.Message)); }
public void ChoiceToOption() { object a = 40; const string b = "60"; var r = from i in FSharpOption.ParseInt(b) from j in FSharpResult.Cast <int>(a).ToFSharpOption() select i + j; Assert.AreEqual(100.Some(), r); }
public void SelectSecond_Error() { object a = 40; const string b = "xx"; var r = from i in FSharpOption.ParseInt(b).ToFSharpResult("Invalid value b") from j in FSharpResult.Cast <int>(a).SelectError(_ => "Invalid value a") select i + j; r.Match(i => Assert.Fail("should not have succeeded with value {0}", i), e => Assert.AreEqual("Invalid value b", e)); }
public void SelectSecond_OK() { object a = 40; const string b = "60"; var r = from i in FSharpOption.ParseInt(b).ToFSharpResult("Invalid value b") from j in FSharpResult.Cast <int>(a).SelectError(_ => "Invalid value a") select i + j; r.Match(i => Assert.AreEqual(100, i), Assert.Fail); }
public void OptionToChoice() { object a = 40; const string b = "60"; var r = from i in FSharpOption.ParseInt(b).ToFSharpResult(new Exception()) from j in FSharpResult.Cast <int>(a) select i + j; r.Match(i => Assert.AreEqual(100, i), e => Assert.Fail(e.Message)); }