public void OptionalString_Case_FuncTUAndFuncU_WithValue_ReturnInt() { Optional <string> optional = "text"; Assert.True(optional.HasValue); Assert.Equal(10, optional.Case <int>(some => 10, () => 666)); }
public void OptionalString_Case_FuncTUAndFuncU_WithoutValue_ReturnInt() { Optional <string> optional = new Optional <string>(); Assert.False(optional.HasValue); Assert.Equal(666, optional.Case <int>(some => 10, () => 666)); }
public void OptionalString_Case_FuncTUAndU_WithValue_ReturnString() { Optional <string> optional = "text"; Assert.True(optional.HasValue); Assert.Equal("text changed", optional.Case <string>(some => some + " changed", "none")); }
public void OptionalString_Case_FuncTUAndU_WithoutValue_ReturnString() { Optional <string> optional = new Optional <string>(); Assert.False(optional.HasValue); Assert.Equal("none", optional.Case <string>(some => some + " changed", "none")); }
public void OptionalString_Case_FuncTUAndU_WithoutValue_ReturnBool() { Optional <string> optional = new Optional <string>(); Assert.False(optional.HasValue); Assert.False(optional.Case <bool>(some => true, false)); }
public void OptionalString_Case_FuncTUAndU_WithValue_ReturnBool() { Optional <string> optional = "text"; Assert.True(optional.HasValue); Assert.True(optional.Case <bool>(some => true, false)); }
public void OptionalString_Case_TwoActions_WithoutValue() { Optional <string> optional = new Optional <string>(); Assert.False(optional.HasValue); var testClass = new TestClass(); optional.Case(some => { testClass.TestMessage = "some"; }, () => { testClass.TestMessage = "none"; }); Assert.Equal("none", testClass.TestMessage); Assert.Equal(0, testClass.TestProperty); }
public void OptionalInt_Case_TwoActions_WithValue() { Optional <int> optional = 10; Assert.True(optional.HasValue); var testClass = new TestClass(); optional.Case(some => { testClass.TestProperty = some + 1; }, () => { testClass.TestMessage = "none"; }); Assert.Null(testClass.TestMessage); Assert.Equal(11, testClass.TestProperty); }
public void OptionalString_Case_TwoActions_WithValue() { Optional <string> optional = "text"; Assert.True(optional.HasValue); var testClass = new TestClass(); optional.Case(some => { testClass.TestMessage = some + " passed"; }, () => { testClass.TestMessage = "none"; }); Assert.Equal("text passed", testClass.TestMessage); Assert.Equal(0, testClass.TestProperty); }
public void OptionalString_Case_FuncTUAndFuncU_WithoutValue_ReturnInt2() { Optional <string> optional = new Optional <string>(); Assert.False(optional.HasValue); Assert.Equal(20, optional.Case <int>(some => 10, () => { var result = 10; for (int i = 0; i < 10; i++) { result++; } return(result); })); }