コード例 #1
0
        public void ReturnFalse_WhenNone()
        {
            var callResult = TestFunctions.CallWithNone();

            Assert.False(callResult.HasSome(out var result));

            Assert.Equal(default, result);
コード例 #2
0
        public void ReturnDefaultValue_WhenNone()
        {
            int defaultIntValue = default;
            var callResult      = TestFunctions.CallWithNone();

            Assert.Equal(defaultIntValue, callResult.UnwrapOrDefault());
        }
コード例 #3
0
ファイル: Option_Should.cs プロジェクト: nmangue/NOption
        public void BeWrapped_AsSome_FromValue()
        {
            var callResult = TestFunctions.CallWithSomeValue();

            Assert.True(callResult.HasSome(out var value));
            Assert.Equal(42, value);
        }
コード例 #4
0
        public void ReturnNone_WhenNone()
        {
            var callResult = TestFunctions.CallWithNone();

            var mapResult = callResult.FlatMap(ToOptionString);

            Assert.Equal(Option.None <string>(), mapResult);
        }
コード例 #5
0
        public void ReturnNone_WhenNone()
        {
            var callResult = TestFunctions.CallWithNone();

            var mapResult = callResult.Map(x => x.ToString());

            Assert.Equal(Option.None <string>(), mapResult);
        }
コード例 #6
0
        public void ReturnValue_WhenSome()
        {
            var callResult = TestFunctions.CallWithSomeValue();

            Assert.True(callResult.HasSome(out var result));

            Assert.Equal(TestFunctions.CallValue, result);
        }
コード例 #7
0
        public void ReturnFunctionResult_WhenSome()
        {
            var callResult = TestFunctions.CallWithSomeValue();

            var mapResult = callResult.FlatMap(ToOptionString);

            Assert.True(mapResult.HasSome(out var value));
            Assert.Equal(TestFunctions.CallValue.ToString(), value);
        }
コード例 #8
0
        public void ReturnOrFunctionResult_WhenNone()
        {
            ResetOrFunctionCalls();

            var callResult = TestFunctions.CallWithNone();

            Assert.Equal(OrValue, callResult.UnwrapOr(OrFunction));
            // Assert that OrFunction is called only once
            CustomAssert.EqualOne(orFunctionCalls);
        }
コード例 #9
0
        public void NotCallOrFunction_WhenSome()
        {
            ResetOrFunctionCalls();

            var callResult = TestFunctions.CallWithSomeValue();

            Assert.Equal(TestFunctions.CallValue, callResult.UnwrapOr(OrFunction));
            // Assert that OrFunction is never called
            CustomAssert.EqualZero(orFunctionCalls);
        }
コード例 #10
0
        public void BeCompatible_WithIOption()
        {
            Option <int> Twice(int other)
            {
                return(Option.Some(other * 2));
            }

            var result = TestFunctions.CallWithSomeValue().FlatMap(Twice);

            Assert.True(result.HasSome(out var value));
            Assert.Equal(84, value);
        }
コード例 #11
0
        public void CallFunctionWithContent_WhenSome()
        {
            var callResult        = TestFunctions.CallWithSomeValue();
            int mapParameterValue = default;
            var mapResult         = callResult.Map((x) =>
            {
                mapParameterValue = x;
                return(x.ToString());
            });

            Assert.Equal(TestFunctions.CallValue, mapParameterValue);
        }
コード例 #12
0
        public void CallActionForSome_WhenSome()
        {
            var someActionCalls = 0;
            var callResult      = TestFunctions.CallWithSomeValue();

            callResult.Match(
                Some: (x) => { Assert.Equal(TestFunctions.CallValue, x); someActionCalls++; },
                None: () => CustomAssert.Fail()
                );

            // Check that the some action is called only once
            CustomAssert.EqualOne(someActionCalls);
        }
コード例 #13
0
        public void CallActionForNone_WhenNone()
        {
            var noneActionCalls = 0;
            var callResult      = TestFunctions.CallWithNone();

            callResult.Match(
                Some: (x) => CustomAssert.Fail(),
                None: () => noneActionCalls++
                );

            // Check that the none action is called only once
            CustomAssert.EqualOne(noneActionCalls);
        }
コード例 #14
0
        public void ReturnContent_WhenSome()
        {
            var callResult = TestFunctions.CallWithSomeValue();

            Assert.Equal(TestFunctions.CallValue, callResult.UnwrapOrFailure());
        }
コード例 #15
0
        public void ThrowInvalidOperationException_WhenNone()
        {
            var callResult = TestFunctions.CallWithNone();

            Assert.Throws <InvalidOperationException>(() => callResult.UnwrapOrFailure());
        }
コード例 #16
0
        public void ReturnOrValue_WhenNone()
        {
            var callResult = TestFunctions.CallWithNone();

            Assert.Equal(OrValue, callResult.UnwrapOr(OrValue));
        }
コード例 #17
0
ファイル: Option_Should.cs プロジェクト: nmangue/NOption
        public void BeWrapped_AsNone_FromGenericNone()
        {
            var callResult = TestFunctions.CallWithNone();

            Assert.False(callResult.HasSome(out var value));
        }