public void OkDoesNotEqualError() { var x = IntResult.Ok(1); var y = IntResult.Err("bar"); Assert.AreNotEqual(x, y); }
public void ErrorDoesNotEqualDifferentError() { var x = IntResult.Err("foo"); var y = IntResult.Err("bar"); Assert.AreNotEqual(x, y); }
public void ErrorEqualsError() { var x = IntResult.Err("boom"); var y = IntResult.Err("boom"); Assert.AreEqual(x, y); }
public void ComprehensionsWork() { var result = from x in IntResult.Ok(2) select x + 1; Assert.AreEqual(IntResult.Ok(3), result); var error = from x in IntResult.Err("boom") select x + 1; Assert.AreEqual(IntResult.Err("boom"), error); var error2 = from x in IntResult.Ok(3) from y in IntResult.Err("boom") select x + y; Assert.AreEqual(IntResult.Err("boom"), error2); var result2 = from x in IntResult.Ok(3) from y in IntResult.Ok(4) select x + y; Assert.AreEqual(result2, IntResult.Ok(7)); }
public void BindRailroadsErrors() { var result = IntResult.Ok(21); var actual = result .Bind(r => IntResult.Err("boom")) .Bind(r => IntResult.Ok(r + 1)); Assert.AreEqual("boom", actual.Error()); }
public void MapErrMapsToANewErrorType() { var expected = Result <int, SomeError> .Err(new SomeError("boom")); var actual = IntResult.Err("boom") .MapErr(e => new SomeError(e)); Assert.AreEqual(expected, actual); }
public void MapOrElseMapsErrors() { var expected = Result <int, SomeError> .Err(new SomeError("boom")); var actual = IntResult.Err("boom") .MapOrElse( x => x * 2, e => new SomeError(e) ); Assert.AreEqual(expected, actual); }