public void ReturnFalse_WhenNone() { var callResult = TestFunctions.CallWithNone(); Assert.False(callResult.HasSome(out var result)); Assert.Equal(default, result);
public void ReturnDefaultValue_WhenNone() { int defaultIntValue = default; var callResult = TestFunctions.CallWithNone(); Assert.Equal(defaultIntValue, callResult.UnwrapOrDefault()); }
public void BeWrapped_AsSome_FromValue() { var callResult = TestFunctions.CallWithSomeValue(); Assert.True(callResult.HasSome(out var value)); Assert.Equal(42, value); }
public void ReturnNone_WhenNone() { var callResult = TestFunctions.CallWithNone(); var mapResult = callResult.FlatMap(ToOptionString); Assert.Equal(Option.None <string>(), mapResult); }
public void ReturnNone_WhenNone() { var callResult = TestFunctions.CallWithNone(); var mapResult = callResult.Map(x => x.ToString()); Assert.Equal(Option.None <string>(), mapResult); }
public void ReturnValue_WhenSome() { var callResult = TestFunctions.CallWithSomeValue(); Assert.True(callResult.HasSome(out var result)); Assert.Equal(TestFunctions.CallValue, result); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void ReturnContent_WhenSome() { var callResult = TestFunctions.CallWithSomeValue(); Assert.Equal(TestFunctions.CallValue, callResult.UnwrapOrFailure()); }
public void ThrowInvalidOperationException_WhenNone() { var callResult = TestFunctions.CallWithNone(); Assert.Throws <InvalidOperationException>(() => callResult.UnwrapOrFailure()); }
public void ReturnOrValue_WhenNone() { var callResult = TestFunctions.CallWithNone(); Assert.Equal(OrValue, callResult.UnwrapOr(OrValue)); }
public void BeWrapped_AsNone_FromGenericNone() { var callResult = TestFunctions.CallWithNone(); Assert.False(callResult.HasSome(out var value)); }