From 67da7e772153f15b7a27ad1a5683b5981e071cf3 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Sun, 23 Sep 2018 19:46:16 +0200 Subject: [PATCH] Add either property (#50) * Add public either property --- src/Lemonad.ErrorHandling/AsyncResult.cs | 5 +- src/Lemonad.ErrorHandling/Either.cs | 70 +++++++ .../Internal/TaskResultFunctions.cs | 67 +++--- src/Lemonad.ErrorHandling/Maybe.cs | 4 +- src/Lemonad.ErrorHandling/Result.cs | 150 ++++++-------- src/Lemonad.ErrorHandling/ResultExtensions.cs | 10 +- .../Lemonad.ErrorHandling.Test/EitherTests.cs | 64 ++++++ .../Lemonad.ErrorHandling.Test.csproj | 2 +- .../Result.Tests/CastErrorTests.cs | 56 ++--- .../Result.Tests/CastTests.cs | 56 ++--- .../Result.Tests/DoTests.cs | 16 +- .../Result.Tests/DoWithErrorTests.cs | 16 +- .../Result.Tests/DoWithTests.cs | 16 +- .../Result.Tests/FilterTests.cs | 48 ++--- .../FlatMapSameTErrorAsyncTests.cs | 72 +++---- .../Result.Tests/FlatMapTests.cs | 72 +++---- .../Result.Tests/FlatMapTestsSameTError.cs | 72 +++---- .../Result.Tests/FlatmapAsyncTests.cs | 72 +++---- .../Result.Tests/FlattenAsyncTests.cs | 96 ++++----- .../Result.Tests/FlattenTests.cs | 98 ++++----- .../Result.Tests/FullCastTests.cs | 144 ++++++------- .../Result.Tests/FullFlatMapAsyncTests.cs | 72 +++---- .../Result.Tests/FullFlatMapTests.cs | 72 +++---- .../Result.Tests/FullMapTests.cs | 16 +- .../CastErrorTests.cs | 24 +-- .../CastTests.cs | 24 +-- .../DoTests.cs | 16 +- .../DoWithErrorTests.cs | 16 +- .../DoWithTests.cs | 16 +- .../FilterTests.cs | 24 +-- .../FlatMapTests.cs | 144 ++++++------- .../FlatmapTestsSameTerror.cs | 144 ++++++------- .../FlattenTests.cs | 192 +++++++++--------- .../FullFlatMapTests.cs | 144 ++++++------- .../FullMapTests.cs | 16 +- .../IsErrorWhenTests.cs | 24 +-- .../MapErrorTests.cs | 16 +- .../MapTests.cs | 16 +- .../Result.Tests/IsErrorWhenTests.cs | 24 +-- .../Result.Tests/JoinTests.cs | 20 +- .../Result.Tests/MapErrorTests.cs | 16 +- .../Result.Tests/MapTests.cs | 16 +- .../Result.Tests/MergeTests.cs | 16 +- .../Result.Tests/OfTypeTests.cs | 64 +++--- .../Result.Tests/ToErrorTests.cs | 24 +-- .../Result.Tests/ToOkTests.cs | 22 +- .../Result.Tests/ToResultTests.cs | 70 +++---- .../Result.Tests/ToStringTests.cs | 64 +++--- 48 files changed, 1315 insertions(+), 1203 deletions(-) create mode 100644 src/Lemonad.ErrorHandling/Either.cs create mode 100644 test/Lemonad.ErrorHandling.Test/EitherTests.cs diff --git a/src/Lemonad.ErrorHandling/AsyncResult.cs b/src/Lemonad.ErrorHandling/AsyncResult.cs index c751fec0..614f197d 100644 --- a/src/Lemonad.ErrorHandling/AsyncResult.cs +++ b/src/Lemonad.ErrorHandling/AsyncResult.cs @@ -62,11 +62,8 @@ public AsyncResult Filter(Func> predicate, Func public AsyncResult Filter(Func> predicate, Func, TError> errorSelector) => TaskResultFunctions.Filter(TaskResult, predicate, errorSelector); - /// - public Task HasError => TaskResultFunctions.HasError(TaskResult); - /// - public Task HasValue => TaskResultFunctions.HasValue(TaskResult); + public Task> Either => TaskResultFunctions.Either(TaskResult); /// public AsyncResult> Multiple( diff --git a/src/Lemonad.ErrorHandling/Either.cs b/src/Lemonad.ErrorHandling/Either.cs new file mode 100644 index 00000000..f0fe0a6f --- /dev/null +++ b/src/Lemonad.ErrorHandling/Either.cs @@ -0,0 +1,70 @@ +using System; + +namespace Lemonad.ErrorHandling { + /// + /// Contains either or . + /// + /// + /// The value type. + /// + /// + /// The error type. + /// + public readonly struct Either { + /// + /// Is true if there's a in the current state of the . + /// + public bool HasValue { get; } + + /// + /// Is true if there's a in the current state of the . + /// + public bool HasError { get; } + + /// + /// The potential . + /// + /// + /// Verify with before using this, unless your certain that the error exists. + /// + /// + /// + /// if (Either.HasError) + /// { + /// // Safe to use. + /// Console.WriteLine(Either.Error) + /// } + /// + /// + public TError Error { get; } + + /// + /// The potential . + /// + /// + /// Verify with before using this, unless your certain that the value exists. + /// + /// + /// + /// if (Either.HasValue) + /// { + /// // Safe to use. + /// Console.WriteLine(Either.Value) + /// } + /// + /// + public T Value { get; } + + public Either(in T value, in TError error, bool hasError, bool hasValue) { + if (hasError == hasValue) + throw new ArgumentException( + $"Can never have the same value {nameof(hasError)} ({hasError}) and {nameof(hasValue)} ({hasValue})." + ); + + HasValue = hasValue; + HasError = hasError; + Value = value; + Error = error; + } + } +} \ No newline at end of file diff --git a/src/Lemonad.ErrorHandling/Internal/TaskResultFunctions.cs b/src/Lemonad.ErrorHandling/Internal/TaskResultFunctions.cs index f90f7f29..d4adcf25 100644 --- a/src/Lemonad.ErrorHandling/Internal/TaskResultFunctions.cs +++ b/src/Lemonad.ErrorHandling/Internal/TaskResultFunctions.cs @@ -58,10 +58,10 @@ internal static async Task> Filter(Task> predicate, Func, TError> errorSelector) { var result = await source.ConfigureAwait(false); - if (result.HasError) return result.Error; - if (await predicate(result.Value)) return result.Value; + if (result.Either.HasError) return result.Either.Error; + if (await predicate(result.Either.Value)) return result.Either.Value; - return errorSelector(result.Value); + return errorSelector(result.Either.Value); } [Pure] @@ -119,9 +119,9 @@ await FlatMap(await source.ConfigureAwait(false), flatMapSelector, resultSelecto [Pure] internal static async Task> FlatMap(Result result, - Func>> flatSelector) => result.HasValue - ? await flatSelector(result.Value).ConfigureAwait(false) - : ResultExtensions.Error(result.Error); + Func>> flatSelector) => result.Either.HasValue + ? await flatSelector(result.Either.Value).ConfigureAwait(false) + : ResultExtensions.Error(result.Either.Error); [Pure] internal static Task> FlatMap(Result result, @@ -135,12 +135,12 @@ internal static Task> FlatMap> FlatMap( Result result, Func>> flatMapSelector, Func errorSelector) { - if (result.HasError) return ResultExtensions.Error(result.Error); + if (result.Either.HasError) return ResultExtensions.Error(result.Either.Error); if (flatMapSelector == null) throw new ArgumentNullException(nameof(flatMapSelector)); - var okSelector = await flatMapSelector(result.Value); + var okSelector = await flatMapSelector(result.Either.Value); - return okSelector.HasValue - ? ResultExtensions.Value(okSelector.Value) + return okSelector.Either.HasValue + ? ResultExtensions.Value(okSelector.Either.Value) : okSelector.MapError(errorSelector); } @@ -162,15 +162,15 @@ internal static Task> FlatMap> Flatten(Result result, Func>> selector) { - if (result.HasValue) { + if (result.Either.HasValue) { if (selector == null) throw new ArgumentNullException(nameof(selector)); - var okSelector = await selector(result.Value).ConfigureAwait(false); - if (okSelector.HasValue) - return result.Value; - return okSelector.Error; + var okSelector = await selector(result.Either.Value).ConfigureAwait(false); + if (okSelector.Either.HasValue) + return result.Either.Value; + return okSelector.Either.Error; } - return ResultExtensions.Error(result.Error); + return ResultExtensions.Error(result.Either.Error); } [Pure] @@ -201,16 +201,16 @@ internal static async Task> Flatten(Task> Flatten( Result result, Func>> selector, Func errorSelector) { - if (result.HasValue) { + if (result.Either.HasValue) { if (selector == null) throw new ArgumentNullException(nameof(selector)); - var okSelector = await selector(result.Value).ConfigureAwait(false); - if (okSelector.HasValue) - return ResultExtensions.Value(result.Value); + var okSelector = await selector(result.Either.Value).ConfigureAwait(false); + if (okSelector.Either.HasValue) + return ResultExtensions.Value(result.Either.Value); var tmpThis = result; - return okSelector.FullMap(x => tmpThis.Value, errorSelector); + return okSelector.FullMap(x => tmpThis.Either.Value, errorSelector); } - return ResultExtensions.Error(result.Error); + return ResultExtensions.Error(result.Either.Error); } [Pure] @@ -251,10 +251,10 @@ internal static async Task> FullFlatMap> FullFlatMap( Result result, Func>> flatMapSelector, Func errorSelector) { - if (result.HasValue) return await flatMapSelector(result.Value).ConfigureAwait(false); + if (result.Either.HasValue) return await flatMapSelector(result.Either.Value).ConfigureAwait(false); return errorSelector != null - ? errorSelector(result.Error) + ? errorSelector(result.Either.Error) : throw new ArgumentNullException(nameof(errorSelector)); } @@ -278,20 +278,17 @@ Func errorSelector ) => (await source.ConfigureAwait(false)).FullMap(selector, errorSelector); [Pure] - internal static async Task HasError(Task> result) => - (await result.ConfigureAwait(false)).HasError; + internal static async Task> Either(Task> result) => + (await result.ConfigureAwait(false)).Either; - [Pure] - internal static async Task HasValue(Task> result) => - (await result.ConfigureAwait(false)).HasValue; [Pure] internal static async Task> IsErrorWhen(Task> source, Func> predicate, Func, TError> errorSelector) { var result = await source.ConfigureAwait(false); - if (result.HasError) return result.Error; - return await predicate(result.Value) ? (Result) errorSelector(result.Value) : result.Value; + if (result.Either.HasError) return result.Either.Error; + return await predicate(result.Either.Value) ? (Result) errorSelector(result.Either.Value) : result.Either.Value; } [Pure] @@ -359,8 +356,8 @@ internal static async Task> Map(Task internal static async Task> Map(Task> source, Func> selector) { var result = await source.ConfigureAwait(false); - if (result.HasError) return result.Error; - if (selector != null) return await selector(result.Value); + if (result.Either.HasError) return result.Either.Error; + if (selector != null) return await selector(result.Either.Value); throw new ArgumentNullException(nameof(selector)); } @@ -368,9 +365,9 @@ internal static async Task> Map(Task internal static async Task> MapError(Task> source, Func> selector) { var result = await source.ConfigureAwait(false); - if (result.HasValue) return result.Value; + if (result.Either.HasValue) return result.Either.Value; - if (selector != null) return await selector(result.Error); + if (selector != null) return await selector(result.Either.Error); throw new ArgumentNullException(nameof(selector)); } diff --git a/src/Lemonad.ErrorHandling/Maybe.cs b/src/Lemonad.ErrorHandling/Maybe.cs index 8cb4acf5..005497bb 100644 --- a/src/Lemonad.ErrorHandling/Maybe.cs +++ b/src/Lemonad.ErrorHandling/Maybe.cs @@ -21,8 +21,8 @@ namespace Lemonad.ErrorHandling { internal T Value { get; } private Maybe(Result result) { - HasValue = result.HasValue; - Value = result.Value; + HasValue = result.Either.HasValue; + Value = result.Either.Value; _result = result; } diff --git a/src/Lemonad.ErrorHandling/Result.cs b/src/Lemonad.ErrorHandling/Result.cs index d3932a12..8b5db50e 100644 --- a/src/Lemonad.ErrorHandling/Result.cs +++ b/src/Lemonad.ErrorHandling/Result.cs @@ -17,38 +17,22 @@ namespace Lemonad.ErrorHandling { /// The type which is considered as failure. /// public readonly struct Result : IEquatable>, IComparable> { - internal TError Error { get; } - internal T Value { get; } - - private Result(in T value, in TError error, bool hasError, bool hasValue) { - HasValue = hasValue; - HasError = hasError; - Value = value; - Error = error; - } - - /// - /// Is true if there's a in the current state of the . - /// - public bool HasValue { get; } + public Either Either { get; } - /// - /// Is true if there's a in the current state of the . - /// - public bool HasError { get; } + private Result(in T value, in TError error, bool hasError, bool hasValue) => Either = new Either(value, error, hasError, hasValue); /// public bool Equals(Result other) { - if (!HasValue && !other.HasValue) return EqualityComparer.Default.Equals(Error, other.Error); + if (!Either.HasValue && !other.Either.HasValue) return EqualityComparer.Default.Equals(Either.Error, other.Either.Error); - if (HasValue && other.HasValue) return EqualityComparer.Default.Equals(Value, other.Value); + if (Either.HasValue && other.Either.HasValue) return EqualityComparer.Default.Equals(Either.Value, other.Either.Value); return false; } /// public override string ToString() => - $"{(HasValue ? "Ok" : "Error")} ==> {typeof(Result).ToHumanString()}{StringFunctions.PrettyTypeString(HasValue ? (object) Value : Error)}"; + $"{(Either.HasValue ? "Ok" : "Error")} ==> {typeof(Result).ToHumanString()}{StringFunctions.PrettyTypeString(Either.HasValue ? (object) Either.Value : Either.Error)}"; public static bool operator ==(Result left, Result right) => left.Equals(right); public static bool operator !=(Result left, Result right) => !left.Equals(right); @@ -80,16 +64,16 @@ public static implicit operator Result(T value) { /// public override int GetHashCode() => - HasValue ? (Value == null ? 1 : Value.GetHashCode()) : (Error == null ? 0 : Error.GetHashCode()); + Either.HasValue ? (Either.Value == null ? 1 : Either.Value.GetHashCode()) : (Either.Error == null ? 0 : Either.Error.GetHashCode()); /// public int CompareTo(Result other) { - if (HasValue && !other.HasValue) return 1; - if (!HasValue && other.HasValue) return -1; + if (Either.HasValue && !other.Either.HasValue) return 1; + if (!Either.HasValue && other.Either.HasValue) return -1; - return HasValue - ? Comparer.Default.Compare(Value, other.Value) - : Comparer.Default.Compare(Error, other.Error); + return Either.HasValue + ? Comparer.Default.Compare(Either.Value, other.Either.Value) + : Comparer.Default.Compare(Either.Error, other.Either.Error); } /// @@ -110,13 +94,13 @@ public int CompareTo(Result other) { [Pure] public TResult Match( Func selector, Func errorSelector) { - if (HasError) + if (Either.HasError) return errorSelector != null - ? errorSelector(Error) + ? errorSelector(Either.Error) : throw new ArgumentNullException(nameof(errorSelector)); return selector != null - ? selector(Value) + ? selector(Either.Value) : throw new ArgumentNullException(nameof(selector)); } @@ -133,13 +117,13 @@ public TResult Match( /// When either or and needs to be executed. /// public void Match(Action action, Action errorAction) { - if (HasError) + if (Either.HasError) if (errorAction != null) - errorAction(Error); + errorAction(Either.Error); else throw new ArgumentNullException(nameof(errorAction)); else if (action != null) - action(Value); + action(Either.Value); else throw new ArgumentNullException(nameof(action)); } @@ -156,9 +140,9 @@ public void Match(Action action, Action errorAction) { /// When is null and needs to be executed. /// public Result DoWith(Action action) { - if (HasError) return this; + if (Either.HasError) return this; if (action != null) - action.Invoke(Value); + action.Invoke(Either.Value); else throw new ArgumentNullException(nameof(action)); @@ -197,9 +181,9 @@ public Result Do(Action action) { /// public Result DoWithError( Action action) { - if (HasValue) return this; + if (Either.HasValue) return this; if (action != null) - action.Invoke(Error); + action.Invoke(Either.Error); else throw new ArgumentNullException(nameof(action)); @@ -231,13 +215,13 @@ public Result Filter(Func predicate, Func errorSelec /// [Pure] public Result Filter(Func predicate, Func, TError> errorSelector) { - if (HasError) return this; + if (Either.HasError) return this; if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - if (predicate(Value)) return this; + if (predicate(Either.Value)) return this; return errorSelector == null ? throw new ArgumentNullException(nameof(errorSelector)) - : errorSelector(Value); + : errorSelector(Either.Value); } /// @@ -308,12 +292,12 @@ public Result IsErrorWhenNull(Func, TError> errorSelector) = public Result FullMap( Func selector, Func errorSelector - ) => HasError + ) => Either.HasError ? ResultExtensions.Error(errorSelector != null - ? errorSelector(Error) + ? errorSelector(Either.Error) : throw new ArgumentNullException(nameof(errorSelector))) : ResultExtensions.Value(selector != null - ? selector(Value) + ? selector(Either.Value) : throw new ArgumentNullException(nameof(selector))); /// @@ -329,11 +313,11 @@ Func errorSelector /// A with its mapped. /// [Pure] - public Result Map(Func selector) => HasValue + public Result Map(Func selector) => Either.HasValue ? selector != null - ? ResultExtensions.Value(selector(Value)) + ? ResultExtensions.Value(selector(Either.Value)) : throw new ArgumentNullException(nameof(selector)) - : ResultExtensions.Error(Error); + : ResultExtensions.Error(Either.Error); /// /// Maps . @@ -348,11 +332,11 @@ public Result Map(Func selector) => HasVal /// A with its mapped. /// [Pure] - public Result MapError(Func selector) => HasError + public Result MapError(Func selector) => Either.HasError ? selector != null - ? ResultExtensions.Error(selector(Error)) + ? ResultExtensions.Error(selector(Either.Error)) : throw new ArgumentNullException(nameof(selector)) - : ResultExtensions.Value(Value); + : ResultExtensions.Value(Either.Value); /// /// Flatten another who shares the same . @@ -366,9 +350,9 @@ public Result MapError(Func /// [Pure] public Result FlatMap( - Func> flatSelector) => HasValue - ? flatSelector?.Invoke(Value) ?? throw new ArgumentNullException(nameof(flatSelector)) - : ResultExtensions.Error(Error); + Func> flatSelector) => Either.HasValue + ? flatSelector?.Invoke(Either.Value) ?? throw new ArgumentNullException(nameof(flatSelector)) + : ResultExtensions.Error(Either.Error); /// /// Flatten another who shares the same . @@ -418,12 +402,12 @@ public Result FlatMap( [Pure] public Result FlatMap( Func> flatMapSelector, Func errorSelector) { - if (HasError) return ResultExtensions.Error(Error); + if (Either.HasError) return ResultExtensions.Error(Either.Error); if (flatMapSelector == null) throw new ArgumentNullException(nameof(flatMapSelector)); - var okSelector = flatMapSelector(Value); + var okSelector = flatMapSelector(Either.Value); - return okSelector.HasValue - ? ResultExtensions.Value(okSelector.Value) + return okSelector.Either.HasValue + ? ResultExtensions.Value(okSelector.Either.Value) : okSelector.MapError(errorSelector); } @@ -488,13 +472,13 @@ public Result FlatMap( [Pure] public Result Flatten( Func> selector, Func errorSelector) { - if (HasError) return ResultExtensions.Error(Error); + if (Either.HasError) return ResultExtensions.Error(Either.Error); if (selector == null) throw new ArgumentNullException(nameof(selector)); - var okSelector = selector(Value); - if (okSelector.HasValue) - return ResultExtensions.Value(Value); + var okSelector = selector(Either.Value); + if (okSelector.Either.HasValue) + return ResultExtensions.Value(Either.Value); var tmpThis = this; - return okSelector.FullMap(x => tmpThis.Value, errorSelector); + return okSelector.FullMap(x => tmpThis.Either.Value, errorSelector); } /// @@ -509,12 +493,12 @@ public Result Flatten( /// [Pure] public Result Flatten(Func> selector) { - if (HasError) return ResultExtensions.Error(Error); + if (Either.HasError) return ResultExtensions.Error(Either.Error); if (selector == null) throw new ArgumentNullException(nameof(selector)); - var okSelector = selector(Value); - if (okSelector.HasValue) - return Value; - return okSelector.Error; + var okSelector = selector(Either.Value); + if (okSelector.Either.HasValue) + return Either.Value; + return okSelector.Either.Error; } /// @@ -530,7 +514,7 @@ public Result> Multiple( if (errors.Any()) return errors; - return Value; + return Either.Value; } /// @@ -554,11 +538,11 @@ public Result> Multiple( [Pure] public Result FullFlatMap( Func> flatMapSelector, Func errorSelector) { - if (HasValue) - return flatMapSelector?.Invoke(Value) ?? throw new ArgumentNullException(nameof(flatMapSelector)); + if (Either.HasValue) + return flatMapSelector?.Invoke(Either.Value) ?? throw new ArgumentNullException(nameof(flatMapSelector)); return errorSelector != null - ? errorSelector(Error) + ? errorSelector(Either.Error) : throw new ArgumentNullException(nameof(errorSelector)); } @@ -573,9 +557,9 @@ public Result FullFlatMap( /// . /// [Pure] - public Result CastError() => HasValue - ? (Result) Value - : (TResult) (object) Error; + public Result CastError() => Either.HasValue + ? (Result) Either.Value + : (TResult) (object) Either.Error; /// /// Casts both into and into @@ -588,9 +572,9 @@ public Result CastError() => HasValue /// The type to cast into. /// [Pure] - public Result FullCast() => HasValue - ? ResultExtensions.Value((TResult) (object) Value) - : ResultExtensions.Error((TErrorResult) (object) Error); + public Result FullCast() => Either.HasValue + ? ResultExtensions.Value((TResult) (object) Either.Value) + : ResultExtensions.Error((TErrorResult) (object) Either.Error); /// /// Casts both into and into @@ -614,9 +598,9 @@ public Result FullCast() => HasVal /// . /// [Pure] - public Result Cast() => HasError - ? (Result) Error - : (TResult) (object) Value; + public Result Cast() => Either.HasError + ? (Result) Either.Error + : (TResult) (object) Either.Value; /// /// Attempts to cast into . @@ -633,8 +617,8 @@ public Result Cast() => HasError /// [Pure] public Result SafeCast(Func errorSelector) { - if (HasError) return Error; - if (Value is TResult result) + if (Either.HasError) return Either.Error; + if (Either.Value is TResult result) return result; return errorSelector != null ? errorSelector() : throw new ArgumentNullException(nameof(errorSelector)); @@ -678,8 +662,8 @@ public Result Join( public Result Join( Result inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector, Func errorSelector, IEqualityComparer comparer) { - if (HasError) return Error; - if (inner.HasError) return inner.Error; + if (Either.HasError) return Either.Error; + if (inner.Either.HasError) return inner.Either.Error; foreach (var result in this.ToEnumerable().Join( inner.ToEnumerable(), diff --git a/src/Lemonad.ErrorHandling/ResultExtensions.cs b/src/Lemonad.ErrorHandling/ResultExtensions.cs index 30d41df0..968d1848 100644 --- a/src/Lemonad.ErrorHandling/ResultExtensions.cs +++ b/src/Lemonad.ErrorHandling/ResultExtensions.cs @@ -225,7 +225,7 @@ public static async Task> /// [Pure] public static Maybe ToMaybe(this Result source) => - source.HasValue ? source.Value : Maybe.None; + source.Either.HasValue ? source.Either.Value : Maybe.None; /// /// Converts an to an with the value @@ -322,13 +322,13 @@ public static IEnumerable Values( enumerable.SelectMany(x => x.ToEnumerable()); private static IEnumerable YieldErrors(Result result) { - if (result.HasError) - yield return result.Error; + if (result.Either.HasError) + yield return result.Either.Error; } private static IEnumerable YieldValues(Result result) { - if (result.HasValue) - yield return result.Value; + if (result.Either.HasValue) + yield return result.Either.Value; } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/EitherTests.cs b/test/Lemonad.ErrorHandling.Test/EitherTests.cs new file mode 100644 index 00000000..cc1ef661 --- /dev/null +++ b/test/Lemonad.ErrorHandling.Test/EitherTests.cs @@ -0,0 +1,64 @@ +using System; +using Xunit; + +namespace Lemonad.ErrorHandling.Test { + public class EitherTests { + [Fact] + public void String_Int_Either_With_Value() { + var value = "foo"; + var error = 2; + var either = new Either(value: in value, error: in error, hasError: false, hasValue: true); + Assert.Equal("foo", either.Value); + Assert.Equal(2, either.Error); + Assert.NotEqual(either.HasError, either.HasValue); + Assert.True(either.HasValue); + } + + [Fact] + public void String_Int_Either_With_Error() { + var value = "foo"; + var error = 2; + var either = new Either(value: in value, error: in error, hasError: true, hasValue: false); + Assert.Equal("foo", either.Value); + Assert.Equal(2, either.Error); + Assert.NotEqual(either.HasError, either.HasValue); + Assert.True(either.HasError); + } + + /// + /// Would be nice if this was not allowed. + /// + [Fact] + public void String_Int_Either_With_Null_Error() { + var value = "foo"; + int? error = null; + var either = new Either(value: in value, error: in error, hasError: true, hasValue: false); + Assert.Equal("foo", either.Value); + Assert.Null(either.Error); + Assert.NotEqual(either.HasError, either.HasValue); + Assert.True(either.HasError); + } + + /// + /// Would be nice if this was not allowed. + /// + [Fact] + public void String_Int_Either_With_Null_Value() { + string value = null; + var error = 2; + var either = new Either(value: in value, error: in error, hasError: true, hasValue: false); + Assert.Null(either.Value); + Assert.Equal(2, either.Error); + Assert.NotEqual(either.HasError, either.HasValue); + Assert.True(either.HasError); + } + + [Fact] + public void String_Int_Either_With_Error_And_Value_Throws() { + var value = "foo"; + var error = 2; + Assert.Throws(() => + new Either(value: in value, error: in error, hasError: true, hasValue: true)); + } + } +} \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Lemonad.ErrorHandling.Test.csproj b/test/Lemonad.ErrorHandling.Test/Lemonad.ErrorHandling.Test.csproj index 41d7ac16..4ceb51e8 100644 --- a/test/Lemonad.ErrorHandling.Test/Lemonad.ErrorHandling.Test.csproj +++ b/test/Lemonad.ErrorHandling.Test/Lemonad.ErrorHandling.Test.csproj @@ -2,7 +2,7 @@ netcoreapp2.1 false - 7.1 + 7.2 diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/CastErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/CastErrorTests.cs index 708b0f57..8c262273 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/CastErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/CastErrorTests.cs @@ -22,43 +22,43 @@ private static Result Program(int code) { [Fact] public void Result_With_Error__With_Invalid_Casting() { var programResult = Program(1); - Assert.False(programResult.HasValue, "Result should not have value"); - Assert.True(programResult.HasError, "Result should have error"); - Assert.Equal(default, programResult.Value); - Assert.Equal(ExitCodes.Fail, programResult.Error); + Assert.False(programResult.Either.HasValue, "Result should not have value"); + Assert.True(programResult.Either.HasError, "Resultction ReSharperGotoNextErrorInSolution should have error"); + Assert.Equal(default, programResult.Either.Value); + Assert.Equal(ExitCodes.Fail, programResult.Either.Error); Assert.Throws(() => programResult.CastError()); } [Fact] public void Result_With_Error__With_Valid_Casting() { var programResult = Program(1); - Assert.False(programResult.HasValue, "Result should not have value"); - Assert.True(programResult.HasError, "Result should have error"); - Assert.Equal(default, programResult.Value); - Assert.Equal(ExitCodes.Fail, programResult.Error); + Assert.False(programResult.Either.HasValue, "Result should not have value"); + Assert.True(programResult.Either.HasError, "Result should have error"); + Assert.Equal(default, programResult.Either.Value); + Assert.Equal(ExitCodes.Fail, programResult.Either.Error); var castResult = programResult.CastError(); - Assert.False(castResult.HasValue, "Casted Result not should have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal(1, castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result not should have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal(1, castResult.Either.Error); } [Fact] public void Result_With_Value__With_Invalid_Casting() { var programResult = Program(0); - Assert.True(programResult.HasValue, "Result should have value"); - Assert.False(programResult.HasError, "Result should not have error"); - Assert.Equal("Success", programResult.Value); - Assert.Equal(default, programResult.Error); + Assert.True(programResult.Either.HasValue, "Result should have value"); + Assert.False(programResult.Either.HasError, "Result should not have error"); + Assert.Equal("Success", programResult.Either.Value); + Assert.Equal(default, programResult.Either.Error); var exception = Record.Exception(() => { var castResult = programResult.CastError(); - Assert.True(castResult.HasValue, "Result should have value"); - Assert.False(castResult.HasError, "Result should not have error"); - Assert.Equal("Success", castResult.Value); - Assert.Equal(default, castResult.Error); + Assert.True(castResult.Either.HasValue, "Result should have value"); + Assert.False(castResult.Either.HasError, "Result should not have error"); + Assert.Equal("Success", castResult.Either.Value); + Assert.Equal(default, castResult.Either.Error); }); Assert.Null(exception); } @@ -66,17 +66,17 @@ public void Result_With_Value__With_Invalid_Casting() { [Fact] public void Result_With_Value__With_Valid_Casting() { var programResult = Program(0); - Assert.True(programResult.HasValue, "Result should have value"); - Assert.False(programResult.HasError, "Result should not have error"); - Assert.Equal("Success", programResult.Value); - Assert.Equal(default, programResult.Error); + Assert.True(programResult.Either.HasValue, "Result should have value"); + Assert.False(programResult.Either.HasError, "Result should not have error"); + Assert.Equal("Success", programResult.Either.Value); + Assert.Equal(default, programResult.Either.Error); var castResult = programResult.CastError(); - Assert.True(castResult.HasValue, "Casted Result should have value."); - Assert.False(castResult.HasError, "Casted Result should not have error."); - Assert.Equal(default, castResult.Error); - Assert.Equal("Success", castResult.Value); + Assert.True(castResult.Either.HasValue, "Casted Result should have value."); + Assert.False(castResult.Either.HasError, "Casted Result should not have error."); + Assert.Equal(default, castResult.Either.Error); + Assert.Equal("Success", castResult.Either.Value); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/CastTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/CastTests.cs index dbad7eb0..99a7c461 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/CastTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/CastTests.cs @@ -22,17 +22,17 @@ private static Result GetGender(int identity) { [Fact] public void Result_With_Error__With_Invalid_Casting() { var genderResult = GetGender(3); - Assert.False(genderResult.HasValue, "Result should not have value"); - Assert.True(genderResult.HasError, "Result should have error"); - Assert.Equal(default, genderResult.Value); - Assert.Equal("Could not determine gender", genderResult.Error); + Assert.False(genderResult.Either.HasValue, "Result should not have value"); + Assert.True(genderResult.Either.HasError, "Result should have error"); + Assert.Equal(default, genderResult.Either.Value); + Assert.Equal("Could not determine gender", genderResult.Either.Error); var exception = Record.Exception(() => { var castResult = genderResult.Cast(); - Assert.False(castResult.HasValue, "Casted Result not should have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not determine gender", castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result not should have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not determine gender", castResult.Either.Error); }); Assert.Null(exception); @@ -41,26 +41,26 @@ public void Result_With_Error__With_Invalid_Casting() { [Fact] public void Result_With_Error__With_Valid_Casting() { var genderResult = GetGender(3); - Assert.False(genderResult.HasValue, "Result should not have value"); - Assert.True(genderResult.HasError, "Result should have error"); - Assert.Equal(default, genderResult.Value); - Assert.Equal("Could not determine gender", genderResult.Error); + Assert.False(genderResult.Either.HasValue, "Result should not have value"); + Assert.True(genderResult.Either.HasError, "Result should have error"); + Assert.Equal(default, genderResult.Either.Value); + Assert.Equal("Could not determine gender", genderResult.Either.Error); var castResult = genderResult.Cast(); - Assert.False(castResult.HasValue, "Casted Result not should have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not determine gender", castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result not should have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not determine gender", castResult.Either.Error); } [Fact] public void Result_With_Value__With_Invalid_Casting() { var genderResult = GetGender(1); - Assert.True(genderResult.HasValue, "Result should have value"); - Assert.False(genderResult.HasError, "Result should not have error"); - Assert.Equal(Gender.Female, genderResult.Value); - Assert.Equal(default, genderResult.Error); + Assert.True(genderResult.Either.HasValue, "Result should have value"); + Assert.False(genderResult.Either.HasError, "Result should not have error"); + Assert.Equal(Gender.Female, genderResult.Either.Value); + Assert.Equal(default, genderResult.Either.Error); Assert.Throws(() => genderResult.Cast()); } @@ -68,17 +68,17 @@ public void Result_With_Value__With_Invalid_Casting() { [Fact] public void Result_With_Value__With_Valid_Casting() { var genderResult = GetGender(1); - Assert.True(genderResult.HasValue, "Result should have value"); - Assert.False(genderResult.HasError, "Result should not have error"); - Assert.Equal(Gender.Female, genderResult.Value); - Assert.Equal(default, genderResult.Error); + Assert.True(genderResult.Either.HasValue, "Result should have value"); + Assert.False(genderResult.Either.HasError, "Result should not have error"); + Assert.Equal(Gender.Female, genderResult.Either.Value); + Assert.Equal(default, genderResult.Either.Error); var castResult = genderResult.Cast(); - Assert.True(castResult.HasValue, "Casted Result should have value."); - Assert.False(castResult.HasError, "Casted Result should not have error."); - Assert.Equal(1, castResult.Value); - Assert.Equal(default, castResult.Error); + Assert.True(castResult.Either.HasValue, "Casted Result should have value."); + Assert.False(castResult.Either.HasError, "Casted Result should not have error."); + Assert.Equal(1, castResult.Either.Value); + Assert.Equal(default, castResult.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/DoTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/DoTests.cs index 829b92fb..66ab051a 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/DoTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/DoTests.cs @@ -10,10 +10,10 @@ public void var result = Division(10, 0).Do(() => actionExectued = true); Assert.True(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -22,10 +22,10 @@ public void Result_With_Value__Expects_Action_To_be_Invoked() { var result = Division(10, 2).Do(() => actionExectued = true); Assert.True(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithErrorTests.cs index c72afdb8..7a152b96 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithErrorTests.cs @@ -10,10 +10,10 @@ public void var result = Division(10, 0).DoWithError(d => actionExectued = true); Assert.True(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -23,10 +23,10 @@ public void var result = Division(10, 2).DoWithError(d => actionExectued = true); Assert.False(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithTests.cs index 3774b3aa..7f20617c 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/DoWithTests.cs @@ -10,10 +10,10 @@ public void var result = Division(10, 0).DoWith(d => actionExectued = true); Assert.False(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -23,10 +23,10 @@ public void var result = Division(10, 2).DoWith(d => actionExectued = true); Assert.True(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FilterTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FilterTests.cs index 15f6ec13..0811d703 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FilterTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FilterTests.cs @@ -20,10 +20,10 @@ public void "Should not get exectued since there's an error before the predicate was applied."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an error before the predicate was applied."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -43,10 +43,10 @@ public void "Should not get exectued since there's an error before the predicate was applied."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an error before the predicate was applied."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -64,10 +64,10 @@ public void Assert.True(predicateExectued, "Should get exectued since there's a value from the result."); Assert.True(errorSelectorExectued, "Should get exectued since the predicate was truthy."); - Assert.Equal(default, result.Value); - Assert.Equal("Bad", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Bad", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -86,10 +86,10 @@ public void Assert.True(predicateExectued, "Should get exectued since there's a value from the result."); Assert.True(errorSelectorExectued, "Should get exectued since the predicate was truthy."); - Assert.Equal(default, result.Value); - Assert.Equal("Good", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Good", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -109,10 +109,10 @@ public void "Should get exectued since there's a value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since the predicate was falsy."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } [Fact] @@ -132,10 +132,10 @@ public void "Should get exectued since there's a value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since the predicate was falsy."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapSameTErrorAsyncTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapSameTErrorAsyncTests.cs index e92a5e6d..35ad3166 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapSameTErrorAsyncTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapSameTErrorAsyncTests.cs @@ -15,10 +15,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -31,10 +31,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -53,10 +53,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -74,10 +74,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -93,10 +93,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -109,10 +109,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -131,14 +131,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -155,10 +155,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result Assert.True(flatSelectorExecuted, "Flatmapselecotr should get executed."); Assert.True(resultSelectorExectued, "ResultSelector should get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTests.cs index c800e513..5c1f18f2 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTests.cs @@ -19,10 +19,10 @@ public void Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_With_Er "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -41,10 +41,10 @@ public void Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_With_Er "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -69,10 +69,10 @@ public void Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result_With_ "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -97,10 +97,10 @@ public void Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result_With_ "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -122,10 +122,10 @@ public void Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_With_Va "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -141,10 +141,10 @@ public void Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_With_Va }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -169,14 +169,14 @@ public void Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result_With_ "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -199,10 +199,10 @@ public void Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result_With_ "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTestsSameTError.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTestsSameTError.cs index 661b44ab..7b7bf066 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTestsSameTError.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatMapTestsSameTError.cs @@ -13,10 +13,10 @@ public void Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_With_Va Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -29,10 +29,10 @@ public void Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_With_Va Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -51,10 +51,10 @@ public void Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result_With_ "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -72,10 +72,10 @@ public void Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result_With_ "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -91,10 +91,10 @@ public void Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_With_Va "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -107,10 +107,10 @@ public void Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_With_Va }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -129,14 +129,14 @@ public void Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result_With_ "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -153,10 +153,10 @@ public void Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result_With_ Assert.True(flatSelectorExecuted, "Flatmapselecotr should get executed."); Assert.True(resultSelectorExectued, "ResultSelector should get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatmapAsyncTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatmapAsyncTests.cs index 699acba6..36140da1 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatmapAsyncTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlatmapAsyncTests.cs @@ -21,10 +21,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -43,10 +43,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -71,10 +71,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -99,10 +99,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -124,10 +124,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -143,10 +143,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -171,14 +171,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -201,10 +201,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenAsyncTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenAsyncTests.cs index b435c981..ffac36d9 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenAsyncTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenAsyncTests.cs @@ -37,10 +37,10 @@ public async Task "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -55,10 +55,10 @@ public async Task Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -79,10 +79,10 @@ public async Task "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -98,10 +98,10 @@ public async Task Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -122,10 +122,10 @@ public async Task "Errorselector should not exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -140,10 +140,10 @@ public async Task Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -162,10 +162,10 @@ public async Task var result = await flattenAsync; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -178,10 +178,10 @@ public async Task }); var result = await flattenAsync; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -202,14 +202,14 @@ public async Task Assert.True(errorSelectorExecuted, "Errorselector should get exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -224,14 +224,14 @@ public async Task var result = await flattenAsync; Assert.True(flatSelectorExecuted); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenTests.cs index bf2b084e..2d7602e3 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FlattenTests.cs @@ -18,11 +18,11 @@ public void Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_With_Er Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, - "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + "The flatmap selector should not get exectued if the sourcegeiEither. Result contains error."); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -35,10 +35,10 @@ public void Result_With_Error_Flatmaps_Result_with_Error_Without_ErrorSelector__ Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -57,10 +57,10 @@ public void Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_With_Er "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -73,10 +73,10 @@ public void Result_With_Error_Flatmaps_Result_with_Value_Without_ErrorSelector__ Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -95,10 +95,10 @@ public void Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_With_Er "Errorselector should not exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -111,10 +111,10 @@ public void Result_With_Value_Flatmaps_Result_with_Error_Without_ErrorSelector__ Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -130,10 +130,10 @@ public void Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_With_Va }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -144,10 +144,10 @@ public void Result_With_Value_Flatmaps_Result_with_Value_Without_ErrorSelector__ return Division(x, 2); }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -166,14 +166,14 @@ public void Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result_With_ "Errorselector should get exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted, "The flatselector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -186,14 +186,14 @@ public void Result_With_Value_FlatmapsRS_Result_with_Error_Without_ErrorSelector Assert.True(flatSelectorExecuted, "The flatselector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullCastTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullCastTests.cs index 727060de..7d9da9b5 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullCastTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullCastTests.cs @@ -26,145 +26,145 @@ private static Result Program(int code) { [Fact] public void Result_With_Error__With_Invalid_Casting() { var programResult = Program(5); - Assert.False(programResult.HasValue, "ProgramResult should not have value"); - Assert.True(programResult.HasError, "ProgramResult should have error"); - Assert.Equal(Error.Fail, programResult.Error); - Assert.Equal(default, programResult.Value); + Assert.False(programResult.Either.HasValue, "ProgramResult should not have value"); + Assert.True(programResult.Either.HasError, "ProgramResult should have error"); + Assert.Equal(Error.Fail, programResult.Either.Error); + Assert.Equal(default, programResult.Either.Value); Assert.Throws(() => programResult.FullCast()); } [Fact] public void Result_With_Error__With_Invalid_Value_Casting_And_Invalid_Error_Casting() { var programResult = Program(5); - Assert.False(programResult.HasValue, "ProgramResult should not have value"); - Assert.True(programResult.HasError, "ProgramResult should have error"); - Assert.Equal(Error.Fail, programResult.Error); - Assert.Equal(default, programResult.Value); + Assert.False(programResult.Either.HasValue, "ProgramResult should not have value"); + Assert.True(programResult.Either.HasError, "ProgramResult should have error"); + Assert.Equal(Error.Fail, programResult.Either.Error); + Assert.Equal(default, programResult.Either.Value); Assert.Throws(() => programResult.FullCast()); } [Fact] public void Result_With_Error__With_Invalid_Value_Casting_And_Valid_Error_Casting() { var programResult = Program(5); - Assert.False(programResult.HasValue, "ProgramResult should not have value"); - Assert.True(programResult.HasError, "ProgramResult should have error"); - Assert.Equal(Error.Fail, programResult.Error); - Assert.Equal(default, programResult.Value); + Assert.False(programResult.Either.HasValue, "ProgramResult should not have value"); + Assert.True(programResult.Either.HasError, "ProgramResult should have error"); + Assert.Equal(Error.Fail, programResult.Either.Error); + Assert.Equal(default, programResult.Either.Value); var castResult = programResult.FullCast(); - Assert.False(castResult.HasValue, "CastResult should not have value"); - Assert.True(castResult.HasError, "CastResult should have error"); - Assert.Equal(1, castResult.Error); - Assert.Equal(default, castResult.Value); + Assert.False(castResult.Either.HasValue, "CastResult should not have value"); + Assert.True(castResult.Either.HasError, "CastResult should have error"); + Assert.Equal(1, castResult.Either.Error); + Assert.Equal(default, castResult.Either.Value); } [Fact] public void Result_With_Error__With_Valid_Casting() { var programResult = Program(5); - Assert.False(programResult.HasValue, "ProgramResult should not have value"); - Assert.True(programResult.HasError, "ProgramResult should have error"); - Assert.Equal(Error.Fail, programResult.Error); - Assert.Equal(default, programResult.Value); + Assert.False(programResult.Either.HasValue, "ProgramResult should not have value"); + Assert.True(programResult.Either.HasError, "ProgramResult should have error"); + Assert.Equal(Error.Fail, programResult.Either.Error); + Assert.Equal(default, programResult.Either.Value); var castResult = programResult.FullCast(); - Assert.False(castResult.HasValue, "CastResult should not have value"); - Assert.True(castResult.HasError, "CastResult should have error"); - Assert.Equal(1, castResult.Error); - Assert.Equal(default, castResult.Value); + Assert.False(castResult.Either.HasValue, "CastResult should not have value"); + Assert.True(castResult.Either.HasError, "CastResult should have error"); + Assert.Equal(1, castResult.Either.Error); + Assert.Equal(default, castResult.Either.Value); } [Fact] public void Result_With_Error__With_Valid_Value_Casting_And_Invalid_Error_Casting() { var programResult = Program(5); - Assert.False(programResult.HasValue, "ProgramResult should not have value"); - Assert.True(programResult.HasError, "ProgramResult should have error"); - Assert.Equal(Error.Fail, programResult.Error); - Assert.Equal(default, programResult.Value); + Assert.False(programResult.Either.HasValue, "ProgramResult should not have value"); + Assert.True(programResult.Either.HasError, "ProgramResult should have error"); + Assert.Equal(Error.Fail, programResult.Either.Error); + Assert.Equal(default, programResult.Either.Value); Assert.Throws(() => programResult.FullCast()); } [Fact] public void Result_With_Error__With_Valid_Value_Casting_And_Valid_Error_Casting() { var programResult = Program(5); - Assert.False(programResult.HasValue, "ProgramResult should not have value"); - Assert.True(programResult.HasError, "ProgramResult should have error"); - Assert.Equal(Error.Fail, programResult.Error); - Assert.Equal(default, programResult.Value); + Assert.False(programResult.Either.HasValue, "ProgramResult should not have value"); + Assert.True(programResult.Either.HasError, "ProgramResult should have error"); + Assert.Equal(Error.Fail, programResult.Either.Error); + Assert.Equal(default, programResult.Either.Value); var castResult = programResult.FullCast(); - Assert.False(castResult.HasValue, "CastResult should not have value"); - Assert.True(castResult.HasError, "CastResult should have error"); - Assert.Equal(1, castResult.Error); - Assert.Equal(default, castResult.Value); + Assert.False(castResult.Either.HasValue, "CastResult should not have value"); + Assert.True(castResult.Either.HasError, "CastResult should have error"); + Assert.Equal(1, castResult.Either.Error); + Assert.Equal(default, castResult.Either.Value); } [Fact] public void Result_With_Value__With_Invalid_Casting() { var programResult = Program(1); - Assert.True(programResult.HasValue, "ProgramResult should have value"); - Assert.False(programResult.HasError, "ProgramResult should not have error"); - Assert.Equal(default, programResult.Error); - Assert.Equal(Gender.Male, programResult.Value); + Assert.True(programResult.Either.HasValue, "ProgramResult should have value"); + Assert.False(programResult.Either.HasError, "ProgramResult should not have error"); + Assert.Equal(default, programResult.Either.Error); + Assert.Equal(Gender.Male, programResult.Either.Value); Assert.Throws(() => programResult.FullCast()); } [Fact] public void Result_With_Value__With_Invalid_Value_Casting_And_Invalid_Error_Casting() { var programResult = Program(1); - Assert.True(programResult.HasValue, "ProgramResult should have value"); - Assert.False(programResult.HasError, "ProgramResult should not have error"); - Assert.Equal(default, programResult.Error); - Assert.Equal(Gender.Male, programResult.Value); + Assert.True(programResult.Either.HasValue, "ProgramResult should have value"); + Assert.False(programResult.Either.HasError, "ProgramResult should not have error"); + Assert.Equal(default, programResult.Either.Error); + Assert.Equal(Gender.Male, programResult.Either.Value); Assert.Throws(() => programResult.FullCast()); } [Fact] public void Result_With_Value__With_Invalid_Value_Casting_And_Valid_Error_Casting() { var programResult = Program(1); - Assert.True(programResult.HasValue, "ProgramResult should have value"); - Assert.False(programResult.HasError, "ProgramResult should not have error"); - Assert.Equal(default, programResult.Error); - Assert.Equal(Gender.Male, programResult.Value); + Assert.True(programResult.Either.HasValue, "ProgramResult should have value"); + Assert.False(programResult.Either.HasError, "ProgramResult should not have error"); + Assert.Equal(default, programResult.Either.Error); + Assert.Equal(Gender.Male, programResult.Either.Value); Assert.Throws(() => programResult.FullCast()); } [Fact] public void Result_With_Value__With_Valid_Casting() { var programResult = Program(1); - Assert.True(programResult.HasValue, "ProgramResult should have value"); - Assert.False(programResult.HasError, "ProgramResult should not have error"); - Assert.Equal(default, programResult.Error); - Assert.Equal(Gender.Male, programResult.Value); + Assert.True(programResult.Either.HasValue, "ProgramResult should have value"); + Assert.False(programResult.Either.HasError, "ProgramResult should not have error"); + Assert.Equal(default, programResult.Either.Error); + Assert.Equal(Gender.Male, programResult.Either.Value); var castResult = programResult.FullCast(); - Assert.True(castResult.HasValue, "CastResult should have value"); - Assert.False(castResult.HasError, "CastResult should not have error"); - Assert.Equal(default, castResult.Error); - Assert.Equal(1, castResult.Value); + Assert.True(castResult.Either.HasValue, "CastResult should have value"); + Assert.False(castResult.Either.HasError, "CastResult should not have error"); + Assert.Equal(default, castResult.Either.Error); + Assert.Equal(1, castResult.Either.Value); } [Fact] public void Result_With_Value__With_Valid_Value_Casting_And_Invalid_Error_Casting() { var programResult = Program(1); - Assert.True(programResult.HasValue, "ProgramResult should have value"); - Assert.False(programResult.HasError, "ProgramResult should not have error"); - Assert.Equal(default, programResult.Error); - Assert.Equal(Gender.Male, programResult.Value); + Assert.True(programResult.Either.HasValue, "ProgramResult should have value"); + Assert.False(programResult.Either.HasError, "ProgramResult should not have error"); + Assert.Equal(default, programResult.Either.Error); + Assert.Equal(Gender.Male, programResult.Either.Value); var castResult = programResult.FullCast(); - Assert.True(castResult.HasValue, "CastResult should have value"); - Assert.False(castResult.HasError, "CastResult should not have error"); - Assert.Equal(default, castResult.Error); - Assert.Equal(1, castResult.Value); + Assert.True(castResult.Either.HasValue, "CastResult should have value"); + Assert.False(castResult.Either.HasError, "CastResult should not have error"); + Assert.Equal(default, castResult.Either.Error); + Assert.Equal(1, castResult.Either.Value); } [Fact] public void Result_With_Value__With_Valid_Value_Casting_And_Valid_Error_Casting() { var programResult = Program(1); - Assert.True(programResult.HasValue, "ProgramResult should have value"); - Assert.False(programResult.HasError, "ProgramResult should not have error"); - Assert.Equal(default, programResult.Error); - Assert.Equal(Gender.Male, programResult.Value); + Assert.True(programResult.Either.HasValue, "ProgramResult should have value"); + Assert.False(programResult.Either.HasError, "ProgramResult should not have error"); + Assert.Equal(default, programResult.Either.Error); + Assert.Equal(Gender.Male, programResult.Either.Value); var castResult = programResult.FullCast(); - Assert.True(castResult.HasValue, "CastResult should have value"); - Assert.False(castResult.HasError, "CastResult should not have error"); - Assert.Equal(default, castResult.Error); - Assert.Equal(1, castResult.Value); + Assert.True(castResult.Either.HasValue, "CastResult should have value"); + Assert.False(castResult.Either.HasError, "CastResult should not have error"); + Assert.Equal(default, castResult.Either.Error); + Assert.Equal(1, castResult.Either.Value); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapAsyncTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapAsyncTests.cs index 4c165206..739fe343 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapAsyncTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapAsyncTests.cs @@ -21,10 +21,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W "Errorselector should get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -43,10 +43,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W "Errorselector should get exeuted since there is an error in the source.."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -71,10 +71,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -99,10 +99,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -124,10 +124,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -143,10 +143,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -171,14 +171,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -201,10 +201,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapTests.cs index ccd7ff76..a4488c8a 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullFlatMapTests.cs @@ -19,10 +19,10 @@ public void Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_With_Er "Errorselector should get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -41,10 +41,10 @@ public void Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_With_Er "Errorselector should get exeuted since there is an error in the source.."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -69,10 +69,10 @@ public void Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result_With_ "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -97,10 +97,10 @@ public void Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result_With_ "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -122,10 +122,10 @@ public void Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_With_Er "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -141,10 +141,10 @@ public void Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_With_Va }); Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -169,14 +169,14 @@ public void Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result_With_ "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -199,10 +199,10 @@ public void Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result_With_ "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullMapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullMapTests.cs index 7c74354a..39e7f628 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/FullMapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/FullMapTests.cs @@ -17,10 +17,10 @@ public void Result_With_Error_Expects__Selector_Never__To_Be_Executed_And_ErrorS Assert.False(selectorExectued, "Should not get exectued since there's an error from the result."); Assert.True(errorSelectorExectued, "Should get exectued since there's an error from the result."); - Assert.Equal(default, result.Value); - Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -37,10 +37,10 @@ public void Result_With_Value_Expects__Selector_To_Be_Executed_And_ErrorSelector Assert.True(selectorExectued, "Should get exectued since there's an value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an value from the result."); - Assert.Equal(50, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(50, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastErrorTests.cs index 4b8a5642..7f7e6056 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastErrorTests.cs @@ -17,10 +17,10 @@ public async Task Result_With_Error__With_Valid_Casting() { var programResult = AssertionUtilities.Program(1); var castResult = await TaskResultFunctions.CastError(programResult); - Assert.False(castResult.HasValue, "Casted Result not should have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal(1, castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result not should have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal(1, castResult.Either.Error); } [Fact] @@ -30,10 +30,10 @@ public async Task Result_With_Value__With_Invalid_Casting() { var exception = await Record.ExceptionAsync(async () => { var castResult = await TaskResultFunctions.CastError(programResult); - Assert.True(castResult.HasValue, "Result should have value"); - Assert.False(castResult.HasError, "Result should not have error"); - Assert.Equal("Success", castResult.Value); - Assert.Equal(default, castResult.Error); + Assert.True(castResult.Either.HasValue, "Result should have value"); + Assert.False(castResult.Either.HasError, "Result should not have error"); + Assert.Equal("Success", castResult.Either.Value); + Assert.Equal(default, castResult.Either.Error); }); Assert.Null(exception); } @@ -45,10 +45,10 @@ public async Task Result_With_Value__With_Valid_Casting() { var castResult = await TaskResultFunctions.CastError(programResult); - Assert.True(castResult.HasValue, "Casted Result should have value."); - Assert.False(castResult.HasError, "Casted Result should not have error."); - Assert.Equal(default, castResult.Error); - Assert.Equal("Success", castResult.Value); + Assert.True(castResult.Either.HasValue, "Casted Result should have value."); + Assert.False(castResult.Either.HasError, "Casted Result should not have error."); + Assert.Equal(default, castResult.Either.Error); + Assert.Equal("Success", castResult.Either.Value); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastTests.cs index 947f3fc6..9ce25013 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/CastTests.cs @@ -11,10 +11,10 @@ public async Task Result_With_Error__With_Invalid_Casting() { var exception = await Record.ExceptionAsync(async () => { var result = TaskResultFunctions.Cast(genderResult); var castResult = await result; - Assert.False(castResult.HasValue, "Casted Result not should have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not determine gender", castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result not should have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not determine gender", castResult.Either.Error); }); Assert.Null(exception); @@ -26,10 +26,10 @@ public async Task Result_With_Error__With_Valid_Casting() { var castResult = await TaskResultFunctions.Cast(genderResult); - Assert.False(castResult.HasValue, "Casted Result not should have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not determine gender", castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result not should have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not determine gender", castResult.Either.Error); } [Fact] @@ -43,10 +43,10 @@ public async Task Result_With_Value__With_Valid_Casting() { var castResult = await TaskResultFunctions.Cast(genderResult); - Assert.True(castResult.HasValue, "Casted Result should have value."); - Assert.False(castResult.HasError, "Casted Result should not have error."); - Assert.Equal(1, castResult.Value); - Assert.Equal(default, castResult.Error); + Assert.True(castResult.Either.HasValue, "Casted Result should have value."); + Assert.False(castResult.Either.HasError, "Casted Result should not have error."); + Assert.Equal(1, castResult.Either.Value); + Assert.Equal(default, castResult.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoTests.cs index 104f9736..ec7f0054 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoTests.cs @@ -13,10 +13,10 @@ public async Task var result = await task; Assert.True(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -26,10 +26,10 @@ public async Task Result_With_Value__Expects_Action_To_be_Invoked() { var result = await task; Assert.True(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithErrorTests.cs index f3b2075a..2561b34d 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithErrorTests.cs @@ -13,10 +13,10 @@ public async Task var result = await doWithError; Assert.True(actionExectued, "Should get exectued since there's an error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -28,10 +28,10 @@ public async Task var result = await doWithError; Assert.False(actionExectued, "Should not get exectued since there's no error."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithTests.cs index b5b9e06f..78b7e345 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/DoWithTests.cs @@ -13,10 +13,10 @@ public async Task var result = await doWith; Assert.False(actionExectued, "Should not get exectued since there's an error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -28,10 +28,10 @@ public async Task var result = await doWith; Assert.True(actionExectued, "Should get exectued since there's no error."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FilterTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FilterTests.cs index 16b34418..18a78919 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FilterTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FilterTests.cs @@ -22,10 +22,10 @@ public async Task "Should not get exectued since there's an error before the predicate was applied."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an error before the predicate was applied."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -44,10 +44,10 @@ public async Task Assert.True(predicateExectued, "Should get exectued since there's a value from the result."); Assert.True(errorSelectorExectued, "Should get exectued since the predicate was truthy."); - Assert.Equal(default, result.Value); - Assert.Equal("Bad", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Bad", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -69,10 +69,10 @@ public async Task "Should get exectued since there's a value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since the predicate was falsy."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatMapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatMapTests.cs index 9eed3aaa..2c5a84fe 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatMapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatMapTests.cs @@ -20,10 +20,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -42,10 +42,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -64,10 +64,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -86,10 +86,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -114,10 +114,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -142,10 +142,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -170,10 +170,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -198,10 +198,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -224,10 +224,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -250,10 +250,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -270,10 +270,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W var result = await flatMap; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -290,10 +290,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W var result = await flatMap; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -319,14 +319,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -352,14 +352,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -384,10 +384,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -412,10 +412,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatmapTestsSameTerror.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatmapTestsSameTerror.cs index e93e8273..4daf5e78 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatmapTestsSameTerror.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlatmapTestsSameTerror.cs @@ -14,10 +14,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -30,10 +30,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -46,10 +46,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -62,10 +62,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -84,10 +84,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -106,10 +106,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -127,10 +127,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -148,10 +148,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -169,10 +169,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -190,10 +190,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -207,10 +207,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W var result = await flatMap; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -224,10 +224,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W var result = await flatMap; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -247,14 +247,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -274,14 +274,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -299,10 +299,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result Assert.True(flatSelectorExecuted, "Flatmapselecotr should get executed."); Assert.True(resultSelectorExectued, "ResultSelector should get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -320,10 +320,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result Assert.True(flatSelectorExecuted, "Flatmapselecotr should get executed."); Assert.True(resultSelectorExectued, "ResultSelector should get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlattenTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlattenTests.cs index 62c8b937..2b80017a 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlattenTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FlattenTests.cs @@ -22,10 +22,10 @@ public async Task "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -46,10 +46,10 @@ public async Task "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -64,10 +64,10 @@ public async Task Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -82,10 +82,10 @@ public async Task Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -106,10 +106,10 @@ public async Task "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -130,10 +130,10 @@ public async Task "Errorselector should not get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -149,10 +149,10 @@ public async Task Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -168,10 +168,10 @@ public async Task Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -193,10 +193,10 @@ public async Task "Errorselector should not exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -218,10 +218,10 @@ public async Task "Errorselector should not exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -236,10 +236,10 @@ public async Task Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -254,10 +254,10 @@ public async Task Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -276,10 +276,10 @@ public async Task var result = await flattenAsync; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -298,10 +298,10 @@ public async Task var result = await flattenAsync; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -314,10 +314,10 @@ public async Task }); var result = await flattenAsync; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -330,10 +330,10 @@ public async Task }); var result = await flattenAsync; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -354,14 +354,14 @@ public async Task Assert.True(errorSelectorExecuted, "Errorselector should get exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -382,14 +382,14 @@ public async Task Assert.True(errorSelectorExecuted, "Errorselector should get exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -404,14 +404,14 @@ public async Task var result = await flattenAsync; Assert.True(flatSelectorExecuted); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -426,14 +426,14 @@ public async Task var result = await flattenAsync; Assert.True(flatSelectorExecuted); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullFlatMapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullFlatMapTests.cs index b670224d..c3b38d53 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullFlatMapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullFlatMapTests.cs @@ -21,10 +21,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W "Errorselector should get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -44,10 +44,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Error__Expects_Result_W "Errorselector should get exeuted since there is an error in the source."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -67,10 +67,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W "Errorselector should get exeuted since there is an error in the source.."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -90,10 +90,10 @@ public async Task Result_With_Error_Flatmaps_Result_with_Value__Expects_Result_W "Errorselector should get exeuted since there is an error in the source.."); Assert.False(flatSelectorExecuted, "The flatmap selector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -119,10 +119,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -148,10 +148,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -177,10 +177,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -206,10 +206,10 @@ public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result "The flatmapSelector should not get exectued if the source Result contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result contains error."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '2' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", result.Either.Error); } [Fact] @@ -232,10 +232,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -258,10 +258,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Error__Expects_Result_W "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -278,10 +278,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W var result = await fullFlatMap; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -298,10 +298,10 @@ public async Task Result_With_Value_Flatmaps_Result_with_Value__Expects_Result_W var result = await fullFlatMap; Assert.True(flatSelectorExecuted, "flatmapselector should get executed."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(0.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(0.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -327,14 +327,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -360,14 +360,14 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '1' with '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '1' with '0'.", result.Either.Error); } [Fact] @@ -391,10 +391,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -418,10 +418,10 @@ public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(1.5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(1.5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullMapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullMapTests.cs index 298b042f..255b8535 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullMapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/FullMapTests.cs @@ -19,10 +19,10 @@ public async Task var result = await task; Assert.False(selectorExectued, "Should not get exectued since there's an error from the result."); - Assert.Equal(default, result.Value); - Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -41,10 +41,10 @@ public async Task Assert.True(selectorExectued, "Should get exectued since there's an value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an value from the result."); - Assert.Equal(50, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(50, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/IsErrorWhenTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/IsErrorWhenTests.cs index 5f4ea697..7592f684 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/IsErrorWhenTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/IsErrorWhenTests.cs @@ -23,10 +23,10 @@ public async Task "Should not get exectued since there's an error before the predicate was applied."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an error before the predicate was applied."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -48,10 +48,10 @@ public async Task "Should get exectued since there's a value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since the predicate was falsy."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } [Fact] @@ -74,10 +74,10 @@ public async Task Assert.True(predicateExectued, "Should get exectued since there's a value from the result."); Assert.True(errorSelectorExectued, "Should get exectued since the predicate was truthy."); - Assert.Equal(default, result.Value); - Assert.Equal("Bad", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Bad", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapErrorTests.cs index 85ac70af..ec732554 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapErrorTests.cs @@ -15,10 +15,10 @@ public async Task Result_With_Error__Expects_Error_To_Be_Mapped() { var result = await task; Assert.True(errorSelectorInvoked, "Errorselector should get exeuted since there is an error in the result."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Either.Error); } [Fact] @@ -31,10 +31,10 @@ public async Task Result_With_Value__Expects_Error_To_Not_Be_Mapped() { Assert.False(errorSelectorInvoked, "Errorselector not should get exeuted since there is an value in the result."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapTests.cs index cc70cd56..155ce064 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/Internal.Asynchronous.Result.Tests/MapTests.cs @@ -14,10 +14,10 @@ public async Task Result_With_Error_Maps__Expects_Selector_Never_Be_Executed() { Assert.False(selectorExectued, "The selector function should never get executed if there's no value in the Result."); - Assert.True(division.HasError, "Result should have error."); - Assert.False(division.HasValue, "Result should not have a value."); - Assert.Equal(default, division.Value); - Assert.Equal("Can not divide '2' with '0'.", division.Error); + Assert.True(division.Either.HasError, "Result should have error."); + Assert.False(division.Either.HasValue, "Result should not have a value."); + Assert.Equal(default, division.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", division.Either.Error); } [Fact] @@ -31,10 +31,10 @@ public async Task var division = await outcome; Assert.True(selectorExectued, "The selector function should get executed since the result has value."); - Assert.False(division.HasError, "Result not should have error."); - Assert.True(division.HasValue, "Result should have a value."); - Assert.Equal(20d, division.Value); - Assert.Equal(default, division.Error); + Assert.False(division.Either.HasError, "Result not should have error."); + Assert.True(division.Either.HasValue, "Result should have a value."); + Assert.Equal(20d, division.Either.Value); + Assert.Equal(default, division.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/IsErrorWhenTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/IsErrorWhenTests.cs index fcfd925e..6a9eee1d 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/IsErrorWhenTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/IsErrorWhenTests.cs @@ -20,10 +20,10 @@ public void "Should not get exectued since there's an error before the predicate was applied."); Assert.False(errorSelectorExectued, "Should not get exectued since there's an error before the predicate was applied."); - Assert.Equal(default, result.Value); - Assert.Equal("Can not divide '10' with '0'.", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Can not divide '10' with '0'.", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } [Fact] @@ -43,10 +43,10 @@ public void "Should get exectued since there's a value from the result."); Assert.False(errorSelectorExectued, "Should not get exectued since the predicate was falsy."); - Assert.Equal(5, result.Value); - Assert.Equal(default, result.Error); - Assert.False(result.HasError, "Result should not have error."); - Assert.True(result.HasValue, "Result should have value."); + Assert.Equal(5, result.Either.Value); + Assert.Equal(default, result.Either.Error); + Assert.False(result.Either.HasError, "Result should not have error."); + Assert.True(result.Either.HasValue, "Result should have value."); } [Fact] @@ -64,10 +64,10 @@ public void Assert.True(predicateExectued, "Should get exectued since there's a value from the result."); Assert.True(errorSelectorExectued, "Should get exectued since the predicate was truthy."); - Assert.Equal(default, result.Value); - Assert.Equal("Bad", result.Error); - Assert.True(result.HasError, "Result should have error."); - Assert.False(result.HasValue, "Result should not have value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("Bad", result.Either.Error); + Assert.True(result.Either.HasError, "Result should have error."); + Assert.False(result.Either.HasValue, "Result should not have value."); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/JoinTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/JoinTests.cs index a24e94e6..5f294f97 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/JoinTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/JoinTests.cs @@ -20,8 +20,8 @@ public void Result_With_No_Value_Joins_Result_With_No_Value_Using_Matching_Key__ return $"{x.Text} {y.Text}"; }, () => string.Empty); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "ERROR 1"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "ERROR 1"); Assert.False(outerSelectorInvoked, "outerSelectorInvoked"); Assert.False(innerSelectorInvoked, "innerSelectorInvoked"); @@ -46,8 +46,8 @@ public void Result_With_No_Value_Joins_Result_With_Value_Using_Matching_Key__Exp return $"{x.Text} {y.Text}"; }, () => string.Empty); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "ERROR 1"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "ERROR 1"); Assert.False(outerSelectorInvoked, "outerSelectorInvoked"); Assert.False(innerSelectorInvoked, "innerSelectorInvoked"); @@ -72,8 +72,8 @@ public void Result_With_Value_Joins_Result_With_No_Value_Using_Matching_Key__Exp return $"{x.Text} {y.Text}"; }, () => string.Empty); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "ERROR 2"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "ERROR 2"); Assert.False(outerSelectorInvoked, "outerSelectorInvoked"); Assert.False(innerSelectorInvoked, "innerSelectorInvoked"); @@ -98,8 +98,8 @@ public void Result_With_Value_Joins_Result_With_Value_Using_Matching_Key__Expect return $"{x.Text} {y.Text}"; }, () => ""); - Assert.Equal(result.Value, "Hello world"); - Assert.Equal(result.Error, default); + Assert.Equal(result.Either.Value, "Hello world"); + Assert.Equal(result.Either.Error, default); Assert.True(outerSelectorInvoked, "outerSelectorInvoked"); Assert.True(innerSelectorInvoked, "innerSelectorInvoked"); @@ -124,8 +124,8 @@ public void Result_With_Value_Joins_Result_With_Value_Using_No_Matching_Key__Exp return $"{x.Text} {y.Text}"; }, () => "No key match"); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "No key match"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "No key match"); Assert.True(outerSelectorInvoked, "outerSelectorInvoked"); Assert.True(innerSelectorInvoked, "innerSelectorInvoked"); diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/MapErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/MapErrorTests.cs index fa73523b..2d4cb04d 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/MapErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/MapErrorTests.cs @@ -13,10 +13,10 @@ public void Result_With_Error__Expects_Error_To_Be_Mapped() { Assert.True(errorSelectorInvoked, "Errorselector should get exeuted since there is an error in the result."); - Assert.False(result.HasValue, "Result should not have a value."); - Assert.True(result.HasError, "Result should have a error."); - Assert.Equal(default, result.Value); - Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Error); + Assert.False(result.Either.HasValue, "Result should not have a value."); + Assert.True(result.Either.HasError, "Result should have a error."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("CAN NOT DIVIDE '10' WITH '0'.", result.Either.Error); } [Fact] @@ -29,10 +29,10 @@ public void Result_With_Value__Expects_Error_To_Not_Be_Mapped() { Assert.False(errorSelectorInvoked, "Errorselector not should get exeuted since there is an value in the result."); - Assert.True(result.HasValue, "Result should have a value."); - Assert.False(result.HasError, "Result should not have a error."); - Assert.Equal(5d, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have a value."); + Assert.False(result.Either.HasError, "Result should not have a error."); + Assert.Equal(5d, result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/MapTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/MapTests.cs index bcf16504..25e48201 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/MapTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/MapTests.cs @@ -13,10 +13,10 @@ public void Result_With_Error_Maps__Expects_Selector_Never_Be_Executed() { Assert.False(selectorExectued, "The selector function should never get executed if there's no value in the Result."); - Assert.True(division.HasError, "Result should have error."); - Assert.False(division.HasValue, "Result should not have a value."); - Assert.Equal(default, division.Value); - Assert.Equal("Can not divide '2' with '0'.", division.Error); + Assert.True(division.Either.HasError, "Result should have error."); + Assert.False(division.Either.HasValue, "Result should not have a value."); + Assert.Equal(default, division.Either.Value); + Assert.Equal("Can not divide '2' with '0'.", division.Either.Error); } [Fact] @@ -28,10 +28,10 @@ public void Result_With_Value_Maps__Expects_Selector_Be_Executed_And_Value_To_Be }); Assert.True(selectorExectued, "The selector function should get executed since the result has value."); - Assert.False(division.HasError, "Result not should have error."); - Assert.True(division.HasValue, "Result should have a value."); - Assert.Equal(20d, division.Value); - Assert.Equal(default, division.Error); + Assert.False(division.Either.HasError, "Result not should have error."); + Assert.True(division.Either.HasValue, "Result should have a value."); + Assert.Equal(20d, division.Either.Value); + Assert.Equal(default, division.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/MergeTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/MergeTests.cs index 61c27aa6..93a7fc9a 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/MergeTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/MergeTests.cs @@ -12,8 +12,8 @@ public void Result_With_No_Value_Zips_Result_With_No_Value__Expects_Result_With_ return $"{x.Text} {y.Text}"; }); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "ERROR 1"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "ERROR 1"); Assert.False(resultSelectorInvoked, "resultSelectorInvoked"); } @@ -27,8 +27,8 @@ public void Result_With_No_Value_Zips_Result_With_Value__Expects_Result_With_No_ return $"{x.Text} {y.Text}"; }); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "ERROR 1"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "ERROR 1"); Assert.False(resultSelectorInvoked, "resultSelectorInvoked"); } @@ -42,8 +42,8 @@ public void Result_With_Value_Zips_Result_With_No_Value__Expects_Result_With_No_ return $"{x.Text} {y.Text}"; }); - Assert.Equal(result.Value, default); - Assert.Equal(result.Error, "ERROR 2"); + Assert.Equal(result.Either.Value, default); + Assert.Equal(result.Either.Error, "ERROR 2"); Assert.False(resultSelectorInvoked, "resultSelectorInvoked"); } @@ -57,8 +57,8 @@ public void Result_With_Value_Zips_Result_With_Value__Expects_Result_With_Value( return $"{x.Text} {y.Text}"; }); - Assert.Equal(result.Value, "Hello world"); - Assert.Equal(result.Error, default); + Assert.Equal(result.Either.Value, "Hello world"); + Assert.Equal(result.Either.Error, default); Assert.True(resultSelectorInvoked, "resultSelectorInvoked"); } } diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/OfTypeTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/OfTypeTests.cs index 664448ee..50be3320 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/OfTypeTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/OfTypeTests.cs @@ -23,10 +23,10 @@ private static Result, string> GetCollection(Collection [Fact] public void Result_With_Error__With_Invalid_Casting() { var collectionResult = GetCollection(Collection.Unknown); - Assert.False(collectionResult.HasValue, "Result should not have value"); - Assert.True(collectionResult.HasError, "Result should have error"); - Assert.Equal(default, collectionResult.Value); - Assert.Equal("Could not obtain a collection.", collectionResult.Error); + Assert.False(collectionResult.Either.HasValue, "Result should not have value"); + Assert.True(collectionResult.Either.HasError, "Result should have error"); + Assert.Equal(default, collectionResult.Either.Value); + Assert.Equal("Could not obtain a collection.", collectionResult.Either.Error); var errorSelectorExectued = false; var castResult = collectionResult.SafeCast(() => { @@ -35,19 +35,19 @@ public void Result_With_Error__With_Invalid_Casting() { }); Assert.False(errorSelectorExectued, "Errorselector should not get executed"); - Assert.False(castResult.HasValue, "Converted result should not have value"); - Assert.True(castResult.HasError, "Converted Result should have error"); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not obtain a collection.", castResult.Error); + Assert.False(castResult.Either.HasValue, "Converted result should not have value"); + Assert.True(castResult.Either.HasError, "Converted Result should have error"); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not obtain a collection.", castResult.Either.Error); } [Fact] public void Result_With_Error__With_Valid_Casting() { var collectionResult = GetCollection(Collection.Unknown); - Assert.False(collectionResult.HasValue, "Result should not have value"); - Assert.True(collectionResult.HasError, "Result should have error"); - Assert.Equal(default, collectionResult.Value); - Assert.Equal("Could not obtain a collection.", collectionResult.Error); + Assert.False(collectionResult.Either.HasValue, "Result should not have value"); + Assert.True(collectionResult.Either.HasError, "Result should have error"); + Assert.Equal(default, collectionResult.Either.Value); + Assert.Equal("Could not obtain a collection.", collectionResult.Either.Error); var errorSelectorExectued = false; var castResult = collectionResult.SafeCast(() => { @@ -56,19 +56,19 @@ public void Result_With_Error__With_Valid_Casting() { }); Assert.False(errorSelectorExectued, "Errorselector should not get executed"); - Assert.False(castResult.HasValue, "Converted result should not have value"); - Assert.True(castResult.HasError, "Converted Result should have error"); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not obtain a collection.", castResult.Error); + Assert.False(castResult.Either.HasValue, "Converted result should not have value"); + Assert.True(castResult.Either.HasError, "Converted Result should have error"); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not obtain a collection.", castResult.Either.Error); } [Fact] public void Result_With_Value__With_Invalid_Casting() { var collectionResult = GetCollection(Collection.Array); - Assert.True(collectionResult.HasValue, "Result should have value"); - Assert.False(collectionResult.HasError, "Result should not have error"); - Assert.IsType(collectionResult.Value); - Assert.Equal(default, collectionResult.Error); + Assert.True(collectionResult.Either.HasValue, "Result should have value"); + Assert.False(collectionResult.Either.HasError, "Result should not have error"); + Assert.IsType(collectionResult.Either.Value); + Assert.Equal(default, collectionResult.Either.Error); var errorSelectorExectued = false; var castResult = collectionResult.SafeCast(() => { @@ -77,19 +77,19 @@ public void Result_With_Value__With_Invalid_Casting() { }); Assert.True(errorSelectorExectued, "Errorselector should get executed"); - Assert.False(castResult.HasValue, "Casted Result should not have value."); - Assert.True(castResult.HasError, "Casted Result should have error."); - Assert.Equal(default, castResult.Value); - Assert.Equal("Could not cast collection to double.", castResult.Error); + Assert.False(castResult.Either.HasValue, "Casted Result should not have value."); + Assert.True(castResult.Either.HasError, "Casted Result should have error."); + Assert.Equal(default, castResult.Either.Value); + Assert.Equal("Could not cast collection to double.", castResult.Either.Error); } [Fact] public void Result_With_Value__With_Valid_Casting() { var collectionResult = GetCollection(Collection.Array); - Assert.True(collectionResult.HasValue, "Result should have value"); - Assert.False(collectionResult.HasError, "Result should not have error"); - Assert.IsType(collectionResult.Value); - Assert.Equal(default, collectionResult.Error); + Assert.True(collectionResult.Either.HasValue, "Result should have value"); + Assert.False(collectionResult.Either.HasError, "Result should not have error"); + Assert.IsType(collectionResult.Either.Value); + Assert.Equal(default, collectionResult.Either.Error); var errorSelectorExectued = false; var castResult = collectionResult.SafeCast(() => { @@ -98,10 +98,10 @@ public void Result_With_Value__With_Valid_Casting() { }); Assert.False(errorSelectorExectued, "Errorselector should not get executed"); - Assert.True(castResult.HasValue, "Casted Result should have value."); - Assert.False(castResult.HasError, "Casted Result should not have error."); - Assert.Equal(new[] {1}, castResult.Value); - Assert.Equal(default, castResult.Error); + Assert.True(castResult.Either.HasValue, "Casted Result should have value."); + Assert.False(castResult.Either.HasError, "Casted Result should not have error."); + Assert.Equal(new[] {1}, castResult.Either.Value); + Assert.Equal(default, castResult.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToErrorTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToErrorTests.cs index a1f2cdd9..1b5d9ed2 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToErrorTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToErrorTests.cs @@ -7,10 +7,10 @@ public class ToResultErrorTests { public void Convert_Int_To_ResultError() { var result = 2.ToResultError(i => true, () => ""); - Assert.False(result.HasValue, "Result should have error."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Equal(2, result.Error); - Assert.Equal(default, result.Value); + Assert.False(result.Either.HasValue, "Result should have error."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Equal(2, result.Either.Error); + Assert.Equal(default, result.Either.Value); } [Fact] @@ -18,20 +18,20 @@ public void Convert_Null_String_To_ResultError() { string str = null; var result = str.ToResultError(x => true, () => ""); - Assert.False(result.HasValue, "Result should have error."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Null(result.Error); - Assert.Equal(default, result.Value); + Assert.False(result.Either.HasValue, "Result should have error."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Null(result.Either.Error); + Assert.Equal(default, result.Either.Value); } [Fact] public void Convert_String_To_ResultError() { var result = "hello".ToResultError(s => true, () => ""); - Assert.False(result.HasValue, "Result should have value."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Equal("hello", result.Error); - Assert.Equal(default, result.Value); + Assert.False(result.Either.HasValue, "Result should have value."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Equal("hello", result.Either.Error); + Assert.Equal(default, result.Either.Value); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToOkTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToOkTests.cs index 42cb7759..933e0d7c 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToOkTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToOkTests.cs @@ -6,10 +6,10 @@ public class ToResultOkTests { public void Convert_Int_To_ResultOk() { var result = 2.ToResult(x => true, () => ""); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Equal(2, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Equal(2, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -17,19 +17,19 @@ public void Convert_Null_String_To_ResultOk() { string str = null; var result = str.ToResult(x => true, () => ""); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Null(result.Value); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Null(result.Either.Value); } [Fact] public void Convert_String_To_ResultOk() { var result = "hello".ToResult(x => true, () => ""); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Equal("hello", result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Equal("hello", result.Either.Value); + Assert.Equal(default, result.Either.Error); } } } \ No newline at end of file diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToResultTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToResultTests.cs index 7bffbc07..81348a47 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToResultTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToResultTests.cs @@ -7,10 +7,10 @@ public class ToResultTests { public void Convert_Maybe_Int_Whose_Property_HasValue_Is_False__Expects_Result_With_error_Value() { var result = 2.ToMaybeNone().ToResult(() => "ERROR"); - Assert.False(result.HasValue, "Result should have error."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Equal(default, result.Value); - Assert.Equal("ERROR", result.Error); + Assert.False(result.Either.HasValue, "Result should have error."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("ERROR", result.Either.Error); } [Fact] @@ -26,10 +26,10 @@ public void public void Convert_Maybe_Int_Whose_Property_HasValue_Is_True__Expects_Result_With_Ok_Value() { var result = 2.ToMaybe().ToResult(() => "ERROR"); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Equal(2, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Equal(2, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -38,8 +38,8 @@ public void var exception = Record.Exception(() => { Func errorSelector = null; var result = 2.ToMaybe().ToResult(errorSelector); - Assert.True(result.HasValue, "Result should have value."); - Assert.Equal(2, result.Value); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.Equal(2, result.Either.Value); }); Assert.Null(exception); } @@ -48,39 +48,39 @@ public void public void Convert_Maybe_String_Whose_Property_HasValue_Is_False__Expects_Result_With_error_Value() { var result = 2.ToMaybeNone().ToResult(() => "ERROR"); - Assert.False(result.HasValue, "Result should have value."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Equal("ERROR", result.Error); - Assert.Equal(default, result.Value); + Assert.False(result.Either.HasValue, "Result should have value."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Equal("ERROR", result.Either.Error); + Assert.Equal(default, result.Either.Value); } [Fact] public void Convert_Maybe_String_Whose_Property_HasValue_Is_True__Expects_Result_With_Ok_Value() { var result = 2.ToMaybe().ToResult(() => "ERROR"); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Equal(default, result.Error); - Assert.Equal(2, result.Value); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Equal(default, result.Either.Error); + Assert.Equal(2, result.Either.Value); } [Fact] public void Convert_Maybe_String_With_Null_Whose_Property_HasValue_Is_False__Expects_Result_With_error_Value() { string str = null; var result = 2.ToMaybeNone().ToResult(() => str); - Assert.False(result.HasValue, "Result should have error."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Null(result.Error); + Assert.False(result.Either.HasValue, "Result should have error."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Null(result.Either.Error); } [Fact] public void Convert_Maybe_String_With_Null_Whose_Property_HasValue_Is_True__Expects_Result_With_Ok_value() { string str = null; var result = 2.ToMaybe().ToResult(() => str); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Equal(2, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Equal(2, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -88,10 +88,10 @@ public void Convert_Nullable_Int_Whose_Property_HasValue_Is_False__Expects_Resul int? number = null; var result = number.ToResult(() => "ERROR"); - Assert.False(result.HasValue, "Result should have error."); - Assert.True(result.HasError, "Result should have a error value."); - Assert.Equal(default, result.Value); - Assert.Equal("ERROR", result.Error); + Assert.False(result.Either.HasValue, "Result should have error."); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal("ERROR", result.Either.Error); } [Fact] @@ -109,10 +109,10 @@ public void Convert_Nullable_Int_Whose_Property_HasValue_Is_True__Expects_Result int? number = 2; var result = number.ToResult(() => "ERROR"); - Assert.True(result.HasValue, "Result should have value."); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.Equal(2, result.Value); - Assert.Equal(default, result.Error); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.Equal(2, result.Either.Value); + Assert.Equal(default, result.Either.Error); } [Fact] @@ -122,8 +122,8 @@ public void Func errorSelector = null; int? nullable = 2; var result = nullable.ToResult(errorSelector); - Assert.True(result.HasValue, "Result should have value."); - Assert.Equal(2, result.Value); + Assert.True(result.Either.HasValue, "Result should have value."); + Assert.Equal(2, result.Either.Value); }); Assert.Null(exception); } diff --git a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToStringTests.cs b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToStringTests.cs index 82b5e62d..c43b8ef4 100644 --- a/test/Lemonad.ErrorHandling.Test/Result.Tests/ToStringTests.cs +++ b/test/Lemonad.ErrorHandling.Test/Result.Tests/ToStringTests.cs @@ -6,10 +6,10 @@ public class ToStringTests { public void Error_Result_With_Char__Expects_Char_To_have__Single_Quotes() { var result = 2.ToMaybeNone().ToResult(() => 'I'); - Assert.True(result.HasError, "Result should have a error value."); - Assert.False(result.HasValue, "Result should not have a Ok value."); - Assert.Equal(default, result.Value); - Assert.Equal('I', result.Error); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.False(result.Either.HasValue, "Result should not have a Ok value."); + Assert.Equal(default, result.Either.Value); + Assert.Equal('I', result.Either.Error); Assert.Equal("Error ==> Result('I')", result.ToString()); } @@ -18,10 +18,10 @@ public void Error_Result_With_Int() { string hello = null; var result = hello.ToMaybeNone().ToResult(() => 2); - Assert.True(result.HasError, "Result should have a error value."); - Assert.False(result.HasValue, "Result should not have a Ok value."); - Assert.Equal(2, result.Error); - Assert.Equal(default, result.Value); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.False(result.Either.HasValue, "Result should not have a Ok value."); + Assert.Equal(2, result.Either.Error); + Assert.Equal(default, result.Either.Value); Assert.Equal("Error ==> Result(2)", result.ToString()); } @@ -29,10 +29,10 @@ public void Error_Result_With_Int() { public void Error_Result_With_String__Expects_String_To_have__Doble_Quotes() { var result = 2.ToMaybeNone().ToResult(() => "hello"); - Assert.True(result.HasError, "Result should have a error value."); - Assert.False(result.HasValue, "Result should not have a Ok value."); - Assert.Equal("hello", result.Error); - Assert.Equal(default, result.Value); + Assert.True(result.Either.HasError, "Result should have a error value."); + Assert.False(result.Either.HasValue, "Result should not have a Ok value."); + Assert.Equal("hello", result.Either.Error); + Assert.Equal(default, result.Either.Value); Assert.Equal("Error ==> Result(\"hello\")", result.ToString()); } @@ -40,10 +40,10 @@ public void Error_Result_With_String__Expects_String_To_have__Doble_Quotes() { public void Ok_Result_With_Char__Expects_Char_To_have__Single_Quotes() { var result = 'I'.ToMaybe().ToResult(() => 2); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.True(result.HasValue, "Result should have a Ok value."); - Assert.Equal('I', result.Value); - Assert.Equal(default, result.Error); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.True(result.Either.HasValue, "Result should have a Ok value."); + Assert.Equal('I', result.Either.Value); + Assert.Equal(default, result.Either.Error); Assert.Equal("Ok ==> Result('I')", result.ToString()); } @@ -51,10 +51,10 @@ public void Ok_Result_With_Char__Expects_Char_To_have__Single_Quotes() { public void Ok_Result_With_String__Expects_String_To_have__Doble_Quotes() { var result = "hello".ToMaybe().ToResult(() => 2); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.True(result.HasValue, "Result should have a Ok value."); - Assert.Equal("hello", result.Value); - Assert.Equal(default, result.Error); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.True(result.Either.HasValue, "Result should have a Ok value."); + Assert.Equal("hello", result.Either.Value); + Assert.Equal(default, result.Either.Error); Assert.Equal("Ok ==> Result(\"hello\")", result.ToString()); } @@ -62,10 +62,10 @@ public void Ok_Result_With_String__Expects_String_To_have__Doble_Quotes() { public void Ok_Result_With_String_Using_Backslash__Expects_String_To_have__Backslash() { var result = "hello\\".ToMaybe().ToResult(() => 2); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.True(result.HasValue, "Result should have a Ok value."); - Assert.Equal("hello\\", result.Value); - Assert.Equal(default, result.Error); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.True(result.Either.HasValue, "Result should have a Ok value."); + Assert.Equal("hello\\", result.Either.Value); + Assert.Equal(default, result.Either.Error); Assert.Equal("Ok ==> Result(\"hello\\\")", result.ToString()); } @@ -73,10 +73,10 @@ public void Ok_Result_With_String_Using_Backslash__Expects_String_To_have__Backs public void Ok_Result_With_String_Using_NewLines__Expects_String_To_have__Escaped_Values() { var result = "hello\r\nfoo".ToMaybe().ToResult(() => 2); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.True(result.HasValue, "Result should have a Ok value."); - Assert.Equal("hello\r\nfoo", result.Value); - Assert.Equal(default, result.Error); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.True(result.Either.HasValue, "Result should have a Ok value."); + Assert.Equal("hello\r\nfoo", result.Either.Value); + Assert.Equal(default, result.Either.Error); Assert.Equal("Ok ==> Result(\"hello\r\nfoo\")", result.ToString()); } @@ -84,10 +84,10 @@ public void Ok_Result_With_String_Using_NewLines__Expects_String_To_have__Escape public void Ok_Result_With_String_Using_Tab__Expects_String_To_have__Escaped_Values() { var result = "hello\tfoo".ToMaybe().ToResult(() => 2); - Assert.False(result.HasError, "Result should not have a error value."); - Assert.True(result.HasValue, "Result should have a Ok value."); - Assert.Equal("hello\tfoo", result.Value); - Assert.Equal(default, result.Error); + Assert.False(result.Either.HasError, "Result should not have a error value."); + Assert.True(result.Either.HasValue, "Result should have a Ok value."); + Assert.Equal("hello\tfoo", result.Either.Value); + Assert.Equal(default, result.Either.Error); Assert.Equal("Ok ==> Result(\"hello\tfoo\")", result.ToString()); } }