Пример #1
0
        public void EqualsWithObject_SourceIsFirstAndObjectIsDefault_ExpectFalse()
        {
            var source = TaggedUnion <RefType, StructType> .First(ZeroIdRefType);

            object?obj = default(TaggedUnion <RefType, StructType>);

            var actual = source.Equals(obj);

            Assert.False(actual);
        }
Пример #2
0
        public void EqualsWithObject_SourceIsFirstAndObjectIsSecond_ExpectFalse()
        {
            var source = TaggedUnion <RefType?, RefType?> .First(null);

            object?obj = TaggedUnion <RefType?, RefType?> .Second(null);

            var actual = source.Equals(obj);

            Assert.False(actual);
        }
Пример #3
0
        public void Inequality_UnionAIsDefaultAndUnionBIsFirst_ExpectTrue()
        {
            var unionA = TaggedUnion <RefType, StructType> .First(ZeroIdRefType);

            var unionB = default(TaggedUnion <RefType, StructType>);

            var actual = unionA != unionB;

            Assert.True(actual);
        }
Пример #4
0
        public void EqualsWithObject_SourceFirstValueEqualsObjectFirstValue_ExpectTrue()
        {
            var source = TaggedUnion <StructType?, RefType> .First(null);

            object?obj = TaggedUnion <StructType?, RefType> .First(null);

            var actual = source.Equals(obj);

            Assert.True(actual);
        }
Пример #5
0
        public void GetHashCode_SourceIsDefaultAndOtherIsNotDefault_ExpectValuesAreNotEqual()
        {
            var source = default(TaggedUnion <RefType?, StructType>);
            var other  = TaggedUnion <RefType?, StructType> .First(null);

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

            Assert.AreNotEqual(sourceHashCode, otherHashCode);
        }
Пример #6
0
        public void EqualsWithOther_SourceFirstValueEqualsOtherFirstValue_ExpectTrue()
        {
            var source = TaggedUnion <StructType?, RefType> .First(null);

            var other = TaggedUnion <StructType?, RefType> .First(null);

            var actual = source.Equals(other);

            Assert.True(actual);
        }
Пример #7
0
        public void Optional_ToTaggedUnion_OptionalIsPresent_ExpectActualIsFirst(
            object?sourceValue)
        {
            var optional = Optional.Present(sourceValue);
            var actual   = optional.ToTaggedUnion();

            var expected = TaggedUnion <object?, Unit> .First(sourceValue);

            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void ToString_SourceIsFirstAndValueToStringReturnsNull_ExpectEmptyString()
        {
            var sourceValue = new StubToStringType(null);

            var source = TaggedUnion <StubToStringType, RefType> .First(sourceValue);

            var actual = source.ToString();

            Assert.IsEmpty(actual);
        }
Пример #9
0
        public void SecondOrThrowWithFactory_SourceIsFirst_ExpectCreatedException()
        {
            var source = TaggedUnion <RefType, object> .First(ZeroIdRefType);

            var resultException = new SomeException();

            var actualExcepption = Assert.Throws <SomeException>(
                () => _ = source.SecondOrThrow(() => resultException));

            Assert.AreSame(resultException, actualExcepption);
        }
Пример #10
0
        public void Equals_UnionAFirstValueEqualsUnionBFirstValue_ExpectTrue(
            object?sourceValue)
        {
            var unionA = TaggedUnion <object?, StructType> .First(sourceValue);

            var unionB = TaggedUnion <object?, StructType> .First(sourceValue);

            var actual = TaggedUnion.Equals(unionA, unionB);

            Assert.True(actual);
        }
Пример #11
0
        public void TaggedUnion_ToOptional_UnionIsFirst_ExpectPresent(
            object?sourceValue)
        {
            var union = TaggedUnion <object?, Unit> .First(sourceValue);

            var actual = union.ToOptional();

            var expected = Optional.Present(sourceValue);

            Assert.AreEqual(expected, actual);
        }
Пример #12
0
        public void GetHashCode_SourceFirstValueAreNotEqualOtherFirstValue_ExpectValuesAreNotEqual()
        {
            var source = TaggedUnion <object, StructType> .First(new object());

            var other = TaggedUnion <object, StructType> .First(new object());

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

            Assert.AreNotEqual(sourceHashCode, otherHashCode);
        }
Пример #13
0
        public void FoldWithOther_MapFirstIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <RefType, StructType> .First(PlusFifteenIdRefType);

            var second = int.MinValue;
            var other  = int.MaxValue;

            var ex = Assert.Throws <ArgumentNullException>(() => _ = source.Fold(null !, _ => second, other));

            Assert.AreEqual("mapFirst", ex !.ParamName);
        }
Пример #14
0
        public void FoldWithOtherFactory_MapSecondIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <RefType, StructType> .First(PlusFifteenIdRefType);

            var first = new object();
            var other = new object();

            var ex = Assert.Throws <ArgumentNullException>(() => _ = source.Fold(_ => first, null !, () => other));

            Assert.AreEqual("mapSecond", ex !.ParamName);
        }
Пример #15
0
        public void FoldWithOtherFactory_OtherFactoryIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <StructType, RefType> .First(SomeTextStructType);

            var first  = decimal.MinValue;
            var second = decimal.MaxValue;

            var ex = Assert.Throws <ArgumentNullException>(() => _ = source.Fold(_ => first, _ => second, null !));

            Assert.AreEqual("otherFactory", ex !.ParamName);
        }
Пример #16
0
        public void Fold_SourceIsFirst_ExpectFirstResult()
        {
            var source = TaggedUnion <RefType, object> .First(MinusFifteenIdRefType);

            var first  = SomeTextStructType;
            var second = NullTextStructType;

            var actual = source.Fold(_ => first, _ => second);

            Assert.AreEqual(first, actual);
        }
Пример #17
0
        public void FoldWithOtherFactory_MapFirstIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <StructType, object?> .First(SomeTextStructType);

            var second = PlusFifteenIdRefType;
            var other  = MinusFifteenIdRefType;

            var ex = Assert.Throws <ArgumentNullException>(() => _ = source.Fold(null !, _ => second, () => other));

            Assert.AreEqual("mapFirst", ex !.ParamName);
        }
Пример #18
0
        public void ToString_SourceIsFirstAndValueToStringDoesNotReturnNull_ExpectResultOfValueToString(
            string resultOfValueToString)
        {
            var sourceValue = new StubToStringType(resultOfValueToString);

            var source = TaggedUnion <StubToStringType, RefType> .First(sourceValue);

            var actual = source.ToString();

            Assert.AreEqual(resultOfValueToString, actual);
        }
Пример #19
0
        public async Task MapSecondValueAsync_SourceIsFirst_ExpectSourceValueFirstUnion()
        {
            var sourceValue = SomeString;
            var source      = TaggedUnion <string, StructType> .First(sourceValue);

            RefType?mappedValue = PlusFifteenIdRefType;
            var     actual      = await source.MapSecondValueAsync(_ => ValueTask.FromResult(mappedValue));

            var expected = TaggedUnion <string, RefType?> .First(sourceValue);

            Assert.AreEqual(expected, actual);
        }
Пример #20
0
        public void FoldWithOtherFactory_SourceIsFirst_ExpectFirstResult()
        {
            var source = TaggedUnion <StructType?, RefType> .First(null);

            int?first  = null;
            var second = Zero;
            var other  = int.MinValue;

            var actual = source.Fold(_ => first, _ => second, () => other);

            Assert.AreEqual(first, actual);
        }
Пример #21
0
        public void MapSecond_SourceIsFirst_ExpectSourceValueFirstUnion()
        {
            var sourceValue = SomeTextStructType;
            var source      = TaggedUnion <StructType?, object?> .First(sourceValue);

            var mappedValue = MinusFifteenIdRefType;
            var actual      = source.MapSecond(_ => mappedValue);

            var expected = TaggedUnion <StructType?, RefType> .First(sourceValue);

            Assert.AreEqual(expected, actual);
        }
Пример #22
0
        public async Task MapSecondAsync_SourceIsFirst_ExpectSourceValueFirstUnion()
        {
            RefType?sourceValue = null;
            var     source      = TaggedUnion <RefType?, object> .First(sourceValue);

            var mappedValue = SomeTextStructType;
            var actual      = await source.MapSecondAsync(_ => Task.FromResult(mappedValue));

            var expected = TaggedUnion <RefType?, StructType> .First(sourceValue);

            Assert.AreEqual(expected, actual);
        }
Пример #23
0
        public void GetHashCode_SourceFirstValueIsSameAsOtherSecondValue_ExpectValuesAreNotEqual(
            object?sourceValue)
        {
            var source = TaggedUnion <object?, object?> .First(sourceValue);

            var other = TaggedUnion <object?, object?> .Second(sourceValue);

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

            Assert.AreNotEqual(sourceHashCode, otherHashCode);
        }
Пример #24
0
        public void FoldAsyncWithOther_MapFirstAsyncIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <StructType, RefType> .First(SomeTextStructType);

            var second = int.MinValue;
            var other  = int.MaxValue;

            var ex = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.FoldAsync(null !, _ => Task.FromResult(second), other));

            Assert.AreEqual("mapFirstAsync", ex !.ParamName);
        }
Пример #25
0
        public void GetHashCode_SourceFirstValueIsSameAsOtherFirstValue_ExpectValuesAreEqual(
            object?sourceValue)
        {
            var source = TaggedUnion <object?, StructType> .First(sourceValue);

            var other = TaggedUnion <object?, StructType> .First(sourceValue);

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

            Assert.AreEqual(sourceHashCode, otherHashCode);
        }
Пример #26
0
        public void FoldWithOther_SourceIsFirst_ExpectFirstResult()
        {
            var source = TaggedUnion <object, StructType?> .First(new object());

            var first  = MinusFifteenIdRefType;
            var second = ZeroIdRefType;
            var other  = PlusFifteenIdRefType;

            var actual = source.Fold(_ => first, _ => second, other);

            Assert.AreEqual(first, actual);
        }
        public void FoldValueAsyncWithOtherFactory_MapFirstAsyncIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <StructType, RefType> .First(SomeTextStructType);

            var second = new { Text = SomeString };
            var other  = new { Text = EmptyString };

            var ex = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.FoldValueAsync(null !, _ => ValueTask.FromResult(second), () => other));

            Assert.AreEqual("mapFirstAsync", ex !.ParamName);
        }
Пример #28
0
        public async Task MapFirstValueAsync_SourceIsFirst_ExpectMappedValueFirstUnion()
        {
            object sourceValue = null !;
            var    source      = TaggedUnion <object, RefType> .First(sourceValue);

            StructType mappedValue = SomeTextStructType;
            var        actual      = await source.MapFirstValueAsync(_ => ValueTask.FromResult(mappedValue));

            var expected = TaggedUnion <StructType, RefType> .First(mappedValue);

            Assert.AreEqual(expected, actual);
        }
        public void FoldValueAsyncWithOtherFactory_MapSecondAsyncIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <StructType?, object> .First(null);

            var first = PlusFifteenIdRefType;
            var other = ZeroIdRefType;

            var ex = Assert.ThrowsAsync <ArgumentNullException>(
                async() => _ = await source.FoldValueAsync(_ => ValueTask.FromResult(first), null !, () => other));

            Assert.AreEqual("mapSecondAsync", ex !.ParamName);
        }
Пример #30
0
        public async Task MapFirstAsync_SourceIsFirst_ExpectMappedValueFirstUnion()
        {
            var sourceValue = ZeroIdRefType;
            var source      = TaggedUnion <RefType?, object> .First(sourceValue);

            StructType?mappedValue = null;
            var        actual      = await source.MapFirstAsync(_ => Task.FromResult(mappedValue));

            var expected = TaggedUnion <StructType?, object> .First(mappedValue);

            Assert.AreEqual(expected, actual);
        }