public void IComparable_Err_Transitive_Ok(bool useGenerics) { var a = SimpleResult.Err("test"); var b = SimpleResult.Err("test"); var c = SimpleResult.Err("test"); var a_obj = (object)a; var b_obj = (object)b; var c_obj = (object)c; // act var abResult = useGenerics ? a.CompareTo(b) : a.CompareTo(b_obj); var baResult = useGenerics ? b.CompareTo(a) : b.CompareTo(a_obj); var acResult = useGenerics ? a.CompareTo(c) : a.CompareTo(c_obj); // assert Assert.Equal(0, abResult); Assert.Equal(0, baResult); Assert.Equal(0, acResult); }
public void Implicit_Error_OK() { // act var result = SimpleResult.Err("message"); // assert Assert.True(result.IsErr); Assert.False(result.IsOk); }
public void Explicit_NullError_Ok() { // act var result = SimpleResult.Err(null); // assert Assert.True(result.IsErr); Assert.False(result.IsOk); Assert.Null(result.UnsafelyUnwrapErr()); }
public static IEnumerable <object[]> GetUnequalPairs() { yield return(new[] { SimpleResult.Ok(7), SimpleResult.Ok(8) }); yield return(new[] { SimpleResult.Ok(1), SimpleResult.Err("error") }); yield return(new[] { SimpleResult.Err("err1"), SimpleResult.Ok(2) }); yield return(new[] { SimpleResult.Err("err1"), SimpleResult.Err("err2") }); }
public void Explicit_Error_Ok() { // act var result = SimpleResult.Err("message"); // assert Assert.True(result.IsErr); Assert.False(result.IsOk); Assert.Equal("message", (string)result); }
public void UnwrapOrElse_Err_Ok() { // arrange var r1 = SimpleResult.Err("error"); // act var r = r1.UnwrapOrElse(err => 0); // assert Assert.Equal(0, r); }
public void UnwrapError_AsValue_Throws() { // arrange var result = SimpleResult.Err("something bad happened"); // act // assert Assert.True(result.IsErr); Assert.False(result.IsOk); Assert.Throws <InvalidOperationException>(() => result.UnsafelyUnwrap()); }
public void Or_ErrReturnsThat_Ok() { // arrange var r1 = SimpleResult.Err("error"); var r2 = SimpleResult.Ok(0); // act var r = r1.Or(r2); // assert Assert.Equal(r2, r); }
public void MapReturn_Err_Ok() { // arrange var r1 = SimpleResult.Err("error"); // act var r = r1.MapReturn(i => i.ToString(), "default"); // assert Assert.NotNull(r); Assert.Equal("default", r); }
public void OrElse_Err() { // arrange var r1 = SimpleResult.Err("error"); var r2 = SimpleResult.Ok(0); // act var r = r1.OrElse(() => r2); // assert Assert.Equal <SimpleResult>(r2, r); }
public void And_ErrReturnsThis_Ok() { // arrange var result = SimpleResult.Err("error"); var andResult = SimpleResult.Ok(0); // act var r = result.And(andResult); // assert Assert.Equal(result, r); }
public void Bind_Err_Ok() { // arrange var r1 = SimpleResult.Err("error"); // act var r = r1.AndThen(i => Result <float, string> .Ok(3.7f)); // assert Assert.NotNull(r); Assert.True(r.IsErr); Assert.Equal("error", r.UnsafelyUnwrapErr()); }
public void SelectErr_Ok() { // arrange var r1 = SimpleResult.Err("error"); // act var r = r1.SelectErr(error => error.ToUpperInvariant()); // assert Assert.NotNull(r); Assert.True(r.IsErr); Assert.Equal("ERROR", r.UnsafelyUnwrapErr()); }
public void IComparable_Err_AtoA_Zero(bool useGenerics) { // arrange var a = SimpleResult.Err("test"); var a_obj = (object)a; // act var result = useGenerics ? a.CompareTo(a) : a.CompareTo(a_obj); // assert Assert.Equal(0, result); }
public void IComparable_Err_Inverse_Ok(bool useGenerics) { var a = SimpleResult.Err("test"); var b = SimpleResult.Err("xyz"); var a_obj = (object)a; var b_obj = (object)b; // act var abResult = useGenerics ? a.CompareTo(b) : a.CompareTo(b_obj); var baResult = useGenerics ? b.CompareTo(a) : b.CompareTo(a_obj); // assert Assert.Equal(-1, abResult); Assert.Equal(1, baResult); }
public void IComparable_Err_Symmetry_Ok(bool useGenerics) { // arrange var a = SimpleResult.Err("test"); var a_obj = (object)a; var b = SimpleResult.Err("test"); var b_obj = (object)b; // act var abResult = useGenerics ? a.CompareTo(b) : a.CompareTo(b_obj); var baResult = useGenerics ? b.CompareTo(a) : b.CompareTo(a_obj); // assert Assert.Equal(0, abResult); Assert.Equal(0, baResult); }
public static IEnumerable <object[]> GetResultTheoryData1() { yield return(new object[] { SimpleResult.Ok(7) }); yield return(new object[] { SimpleResult.Err("test") }); }
public static IEnumerable <object[]> GetToStringTests() { yield return(new object[] { SimpleResult.Ok(7), $"Ok<{7.GetType().Name}>[7]" }); yield return(new object[] { SimpleResult.Err("error"), $"Err<{"error".GetType().Name}>[error]" }); }