Exemple #1
0
        public void Cast_Exception()
        {
            object a = "hello";

            FSharpResult.Cast <int>(a)
            .Match(i => Assert.Fail("should not have succeeded with value {0}", i),
                   e => {});
        }
Exemple #2
0
        public void Cast_OK()
        {
            object a = 40;

            FSharpResult.Cast <int>(a)
            .Match(i => Assert.AreEqual(40, i),
                   e => Assert.Fail(e.Message));
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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));
        }