public void When_projecting_a_failure_result() { var input = new MockInput<int>(); var childParser = new MockFailureParser<int, double>(); var parser = new ProjectionParser<int, double, decimal>(childParser, d => (decimal) d + 3.0m); var actualResult = parser.Parse(input); ParseResultAssert.IsFailure(actualResult); Assert.AreEqual(input, actualResult.FirstInput); }
public void Cast_called_on_a_failed_result() { var firstInput = new MockInput<int>(); var remainingInput = new MockInput<int>(); var mockParser = new MockFailureParser<int, double>(); var originalResult = ParseResult.Failure<int, double>(firstInput, mockParser); var actualResult = originalResult.Cast<int, double, decimal>(); Assert.AreEqual(originalResult.FirstInput, actualResult.FirstInput); Assert.AreEqual(originalResult.RemainingInput, actualResult.RemainingInput); ParseResultAssert.IsFailure(actualResult); }
public void IfFailure_called_on_a_failed_result() { var firstInput = new MockInput<int>(); var remainingInput = new MockInput<int>(); var expectedResult = new MockParseResult<int, double>(); var mockParser = new MockFailureParser<int, double>(); var originalResult = ParseResult.Failure<int, double>(firstInput, mockParser); var actualResult = originalResult.IfFailure( successfulResult => { Assert.AreEqual(originalResult, successfulResult); return expectedResult; } ); Assert.AreEqual(expectedResult, actualResult); }
public void IfSuccess_called_on_a_failed_result() { var firstInput = new MockInput<int>(); var mockParser = new MockFailureParser<int, double>(); var originalResult = ParseResult.Failure<int, double>(firstInput, mockParser); var actualResult = originalResult.IfSuccess( successfulResult => { Assert.Fail("IfSuccess called the action, somehow"); return originalResult; } ); Assert.AreEqual(originalResult.FirstInput, actualResult.FirstInput); Assert.AreEqual(originalResult.RemainingInput, actualResult.RemainingInput); ParseResultAssert.IsFailure(actualResult); }