public async Task RecoverValueAsyncFailure_SourceIsDefaultOrFailureAndOtherIsFailure_ExpectOther(
            Result <RefType, StructType> source)
        {
            Result <RefType, SomeError> other = new SomeError(PlusFifteen);
            var actual = await source.RecoverValueAsync(_ => ValueTask.FromResult(other));

            Assert.AreEqual(other, actual);
        }
        public async Task ForwardAsyncMapFailure_SourceIsSuccessAndNextIsDefault_ExpectDefault(
            Result <RefType, StructType> source)
        {
            var next          = default(Result <string, SomeError>);
            var mappedFailure = new SomeError(PlusFifteen);

            var actual = await source.ForwardAsync(_ => Task.FromResult(next), _ => Task.FromResult(mappedFailure));

            Assert.AreEqual(next, actual);
        }
Esempio n. 3
0
        public void FilterAsyncWithMapFailure_CauseFactoryIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var mapped = new SomeError(MinusFifteen);

            var actualException = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.FilterAsync(_ => Task.FromResult(true), null !, _ => Task.FromResult(mapped)));

            Assert.AreEqual("causeFactoryAsync", actualException !.ParamName);
        }
        public void ForwardAsyncMapFailure_MapFailureIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            Result <SomeRecord, SomeError> next = new SomeError(MinusFifteen);

            var actualException = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.ForwardAsync(_ => Task.FromResult(next), null !));

            Assert.AreEqual("mapFailureAsync", actualException !.ParamName);
        }
        public void ForwardAsyncMapFailure_NextFactoryAsyncIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var mappedFailure = new SomeError(PlusFifteen);

            var actualException = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.ForwardAsync <SomeRecord, SomeError>(null !, _ => Task.FromResult(mappedFailure)));

            Assert.AreEqual("nextFactoryAsync", actualException !.ParamName);
        }
Esempio n. 6
0
        public void FilterWithMapFailure_MapFailureIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var causeFailure = new SomeError(int.MinValue);

            var actualException = Assert.Throws <ArgumentNullException>(
                () => _ = source.Filter(_ => true, _ => causeFailure, null !));

            Assert.AreEqual("mapFailure", actualException !.ParamName);
        }
Esempio n. 7
0
        public void FilterWithMapFailure_CauseFactoryIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var mappedFailure = new SomeError(int.MaxValue);

            var actualException = Assert.Throws <ArgumentNullException>(
                () => _ = source.Filter(_ => false, null !, _ => mappedFailure));

            Assert.AreEqual("causeFactory", actualException !.ParamName);
        }
        public async Task ForwardAsyncMapFailure_SourceIsSuccessAndNextIsFailure_ExpectNext(
            Result <RefType, StructType> source)
        {
            Result <SomeRecord, SomeError> next = Result.Failure(new SomeError(MinusFifteen));
            var mappedFailure = new SomeError(int.MinValue);

            var actual = await source.ForwardAsync(_ => Task.FromResult(next), _ => Task.FromResult(mappedFailure));

            Assert.AreEqual(next, actual);
        }
Esempio n. 9
0
        public void TaggedUnion_ToResult_SourceUnionIsSecond_ExpectFailureResult()
        {
            var sourceValue = new SomeError(MinusFifteen);
            var sourceUnion = TaggedUnion <RefType?, SomeError> .Second(sourceValue);

            var actual   = sourceUnion.ToResult();
            var expected = Result <RefType?, SomeError> .Failure(sourceValue);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 10
0
        public void RecoverWithMapSuccess_SourceIsDefaultOrFailureAndOtherIsFailure_ExpectOther(
            Result <RefType, StructType> source)
        {
            Result <object, SomeError> other = new SomeError(PlusFifteen);
            var mappedValue = new object();

            var actual = source.Recover(_ => other, _ => mappedValue);

            Assert.AreEqual(other, actual);
        }
        public async Task ForwardValueAsyncMapFailure_SourceIsSuccessAndNextIsSuccess_ExpectNext(
            Result <RefType, StructType> source)
        {
            Result <RefType, SomeError> next = Result.Success(PlusFifteenIdRefType);
            var mappedFailure = new SomeError(int.MaxValue);

            var actual = await source.ForwardValueAsync(_ => ValueTask.FromResult(next), _ => ValueTask.FromResult(mappedFailure));

            Assert.AreEqual(next, actual);
        }
Esempio n. 12
0
        public void MapAsync_MapSuccessAsyncIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var failureResult = new SomeError(MinusFifteen);

            var actualException = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.MapAsync <int, SomeError>(null !, _ => Task.FromResult(failureResult)));

            Assert.AreEqual("mapSuccessAsync", actualException !.ParamName);
        }
Esempio n. 13
0
        public async Task MapFailureAsync_SourceIsDefaultOrFailure_FailureExpectResultOfMapFailureAsync(
            Result <RefType, StructType> source)
        {
            var failureResult = new SomeError(PlusFifteen);
            var actual        = await source.MapFailureAsync(_ => Task.FromResult(failureResult));

            var exected = new Result <RefType, SomeError>(failureResult);

            Assert.AreEqual(exected, actual);
        }
Esempio n. 14
0
        public async Task MapFailureAsync_SourceIsSuccess_ExpectResultOfSourceSuccess(
            Result <RefType, StructType> source)
        {
            var failureResult = new SomeError(int.MaxValue);
            var actual        = await source.MapFailureAsync(_ => Task.FromResult(failureResult));

            var exected = new Result <RefType, SomeError>(PlusFifteenIdRefType);

            Assert.AreEqual(exected, actual);
        }
Esempio n. 15
0
        public void ForwardMapFailure_SourceIsSuccessAndNextIsFailure_ExpectNext(
            Result <RefType, StructType> source)
        {
            Result <SomeRecord, SomeError> next = new SomeError(MinusFifteen);
            var mappedFailure = new SomeError(int.MaxValue);

            var actual = source.Forward(_ => next, _ => mappedFailure);

            Assert.AreEqual(next, actual);
        }
Esempio n. 16
0
        public void ForwardMapFailure_NextFactoryIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var mappedFailure = new SomeError(MinusFifteen);

            var actualException = Assert.Throws <ArgumentNullException>(
                () => _ = source.Forward <SomeRecord, SomeError>(null !, _ => mappedFailure));

            Assert.AreEqual("nextFactory", actualException !.ParamName);
        }
Esempio n. 17
0
        public void MapFailure_SourceIsSuccess_ExpectResultOfSourceSuccess(
            Result <RefType, StructType> source)
        {
            var failureResult = new SomeError(int.MaxValue);
            var actual        = source.MapFailure(_ => failureResult);

            var exected = new Result <RefType, SomeError>(MinusFifteenIdRefType);

            Assert.AreEqual(exected, actual);
        }
Esempio n. 18
0
        public void MapFailure_SourceIsDefaultOrFailure_FailureExpectResultOfMapFailure(
            Result <RefType, StructType> source)
        {
            var failureResult = new SomeError(MinusFifteen);
            var actual        = source.MapFailure(_ => failureResult);

            var exected = new Result <RefType, SomeError>(failureResult);

            Assert.AreEqual(exected, actual);
        }
        public async Task RecoverAsyncWithMapSuccess_SourceIsDefaultOrFailureAndOtherIsFailure_ExpectOther(
            Result <RefType, StructType> source)
        {
            Result <string, SomeError> other = new SomeError(PlusFifteen);
            var mappedValue = "Some success text value";

            var actual = await source.RecoverAsync(_ => Task.FromResult(other), _ => Task.FromResult(mappedValue));

            Assert.AreEqual(other, actual);
        }
Esempio n. 20
0
        public void FilterWithMapFailure_PredicateIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var causeFailure  = new SomeError(MinusFifteen);
            var mappedFailure = new SomeError(int.MinValue);

            var actualException = Assert.Throws <ArgumentNullException>(
                () => _ = source.Filter(null !, _ => causeFailure, _ => mappedFailure));

            Assert.AreEqual("predicate", actualException !.ParamName);
        }
Esempio n. 21
0
        public void ForwardMapFailure_SourceIsDefaultOrFailure_ExpectResultOfMappedFailure(
            Result <RefType, StructType> source)
        {
            Result <SomeRecord, SomeError> next = new SomeRecord();
            var mappedFailure = new SomeError(MinusFifteen);

            var actual   = source.Forward(_ => next, _ => mappedFailure);
            var expected = new Result <SomeRecord, SomeError>(mappedFailure);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 22
0
        public void GetHashCode_SourceIsNotDefaultAndOtherIsSameAsSourceFailure_ExpectHashCodesAreNotEqual()
        {
            var failure = new SomeError(PlusFifteen);
            var source  = Result.Failure(failure);
            var other   = failure;

            var sourceHashCode = source.GetHashCode();
            var otherHashCode  = other.GetHashCode();

            Assert.AreNotEqual(sourceHashCode, otherHashCode);
        }
        public async Task ForwardAsyncMapFailure_SourceIsDefaultOrFailure_ExpectResultOfMappedFailure(
            Result <RefType, StructType> source)
        {
            Result <SomeRecord, SomeError> next = new SomeRecord();
            var mappedFailure = new SomeError(MinusFifteen);

            var actual = await source.ForwardAsync(_ => Task.FromResult(next), _ => Task.FromResult(mappedFailure));

            var expected = new Result <SomeRecord, SomeError>(mappedFailure);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 24
0
        public void Equality_LeftFailureIsNotEqualToRightFailure_ExpectFalse()
        {
            var leftFailure = new SomeError(PlusFifteen);
            var left        = Result.Failure(leftFailure);

            var rightFailure = new SomeError(MinusFifteen);
            var right        = Result.Failure(rightFailure);

            var actual = left == right;

            Assert.False(actual);
        }
Esempio n. 25
0
        public async Task FoldValueAsync_SourceIsDefaultOrFailure_ExpectResultOfMapFailure(
            Result <RefType, StructType> source)
        {
            SomeError?successResult = new SomeError(PlusFifteen);
            SomeError?failureResult = null;

            var actual = await source.FoldValueAsync(
                _ => ValueTask.FromResult(successResult),
                _ => ValueTask.FromResult(failureResult));

            Assert.AreEqual(failureResult, actual);
        }
Esempio n. 26
0
        public void Inequality_LeftFailureIsNotEqualToRightFailure_ExpectTrue()
        {
            var leftFailure = new SomeError(MinusFifteen);
            var left        = Result.Failure(leftFailure);

            var rightFailure = new SomeError(int.MaxValue);
            var right        = Result.Failure(rightFailure);

            var actual = left != right;

            Assert.True(actual);
        }
        public void FilterValueAsyncWithMapFailure_PredicateIsNull_ExpectArgumentNullException(
            Result <RefType, StructType> source)
        {
            var cause  = new SomeError(MinusFifteen);
            var mapped = new SomeError(int.MaxValue);

            var actualException = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.FilterValueAsync(
                    null !, _ => ValueTask.FromResult(cause), _ => ValueTask.FromResult(mapped)));

            Assert.AreEqual("predicateAsync", actualException !.ParamName);
        }
Esempio n. 28
0
        public void EqualsObject_SourceFailureIsNotEqualToOtherFailureAndTypesAreSame_ExpectFalse()
        {
            var sourceFailure = new SomeError(PlusFifteen);
            var source        = Result.Failure(sourceFailure);

            var    otherFailure = new SomeError(MinusFifteen);
            object?other        = Result.Failure(otherFailure);

            var actual = source.Equals(other);

            Assert.False(actual);
        }
Esempio n. 29
0
        public void GetHashCode_SourceFailureIsNotEqualToOtherFailureAndTypesAreSame_ExpectHashCodesAreNotEqual()
        {
            var sourceFailure = new SomeError(PlusFifteen);
            var source        = Result.Failure(sourceFailure);

            var otherFailure = new SomeError(MinusFifteen);
            var other        = Result.Failure(otherFailure);

            var sourceHashCode = source.GetHashCode();
            var otherHashCode  = other.GetHashCode();

            Assert.AreNotEqual(sourceHashCode, otherHashCode);
        }
Esempio n. 30
0
        public void EqualsInequality_ResultAIsFailureAndResultBIsFailureAndValuesAreEqual_ExpectFalse()
        {
            var errorCode = PlusFifteen;
            var aValue    = new SomeError(errorCode);
            var resultA   = Result <DateTimeOffset, SomeError> .Failure(aValue);

            var bValue  = new SomeError(errorCode);
            var resultB = new Result <DateTimeOffset, SomeError>(bValue);

            var actual = resultA != resultB;

            Assert.False(actual);
        }