コード例 #1
0
        public void WrapAndRetrieveNone()
        {
            IOption <int> option = FakeService.GetOption(false);

            var some = (None <int>)option;

            Assert.IsType <None <int> >(option);
        }
コード例 #2
0
        public void WrapAndRetrieveSome()
        {
            IOption <int> option = FakeService.GetOption(true);

            var some = (Some <int>)option;

            Assert.IsType <Some <int> >(option);
            Assert.Equal(10, some);
        }
コード例 #3
0
        public void WrapAndRetrieveSomeWithPatternMatching()
        {
            IOption <int> option = FakeService.GetOption(true);

            int res = 0;

            switch (option)
            {
            case Some <int> some:
                res = some;
                break;

            case None <int> _:
                res = 0;
                break;
            }

            Assert.IsType <Some <int> >(option);
            Assert.Equal(10, res);
        }
コード例 #4
0
        public void WrapAndRetrieveNoneWithPatternMatching()
        {
            IOption <int> option = FakeService.GetOption(false);

            int res = 0;

            switch (option)
            {
            case Some <int> some:
                res = some;
                break;

            case None <int> _:
                // Set it to -1 for the assert to check something different to 0.
                res = -1;
                break;
            }

            Assert.IsType <None <int> >(option);
            Assert.Equal(-1, res);
        }