コード例 #1
0
ファイル: ToString.cs プロジェクト: pfpack/pfpack-core
        public void ToString_SourceIsSecondAndValueIsNull_ExpectEmptyString()
        {
            var source = TaggedUnion <decimal, StructType?> .Second(null);

            var actual = source.ToString();

            Assert.IsEmpty(actual);
        }
コード例 #2
0
        public void Result_ToTaggedUnion_SourceResultIsDefault_ExpectUnionSecondOfDefaultValue(
            Result <RefType?, StructType> sourceResult)
        {
            var actual   = sourceResult.ToTaggedUnion();
            var expected = TaggedUnion <RefType?, StructType> .Second(default(StructType));

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void Result_ToTaggedUnion_SourceResultIsFailure_ExpectUnionSecondOfSourceFailureValue(
            Result <RefType, StructType> sourceResult)
        {
            var actual   = sourceResult.ToTaggedUnion();
            var expected = TaggedUnion <RefType, StructType> .Second(SomeTextStructType);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
ファイル: FirstOrThrow.cs プロジェクト: pfpack/pfpack-core
        public void FirstOrThrow_SourceIsSecond_ExpectInvalidOperationException()
        {
            var source = TaggedUnion <StructType, RefType> .Second(PlusFifteenIdRefType);

            var ex = Assert.Throws <InvalidOperationException>(() => _ = source.FirstOrThrow());

            AssertContainsFirst(First, ex !.Message);
        }
コード例 #5
0
        public void SecondOrThrowWithFactory_ExceptionFactoryIsNull_ExpectArgumentNullException()
        {
            var source = TaggedUnion <StructType, RefType> .Second(MinusFifteenIdRefType);

            var ex = Assert.Throws <ArgumentNullException>(() => _ = source.SecondOrThrow(null !));

            Assert.AreEqual("exceptionFactory", ex !.ParamName);
        }
コード例 #6
0
        public void EqualsWithOther_SourceIsDefaultAndOtherIsSecond_ExpectFalse()
        {
            var source = default(TaggedUnion <StructType, RefType>);
            var other  = TaggedUnion <StructType, RefType> .Second(PlusFifteenIdRefType);

            var actual = source.Equals(other);

            Assert.False(actual);
        }
コード例 #7
0
        public async Task OrInitializeAsync_SourceIsDefault_ExpectOther()
        {
            var source = default(TaggedUnion <int, RefType>);
            var other  = TaggedUnion <int, RefType> .Second(new RefType());

            var actual = await source.OrInitializeAsync(() => Task.FromResult(other));

            Assert.AreEqual(other, actual);
        }
コード例 #8
0
        public void Inequality_UnionAIsDefaultAndUnionBIsSecond_ExpectTrue()
        {
            var unionA = default(TaggedUnion <RefType?, StructType?>);
            var unionB = TaggedUnion <RefType?, StructType?> .Second(null);

            var actual = unionA != unionB;

            Assert.True(actual);
        }
コード例 #9
0
ファイル: Equality.cs プロジェクト: pfpack/pfpack-core
        public void Equality_UnionASecondValueEqualsUnionBSecondValue_ExpectTrue()
        {
            var unionA = (TaggedUnion <StructType?, RefType>)ZeroIdRefType;
            var unionB = TaggedUnion <StructType?, RefType> .Second(ZeroIdRefType);

            var actual = unionA == unionB;

            Assert.True(actual);
        }
コード例 #10
0
        public void Optional_ToTaggedUnion_OptionalIsAbsent_ExpectActualIsSecond()
        {
            var optional = Optional.Absent <RefType>();
            var actual   = optional.ToTaggedUnion();

            var expected = TaggedUnion <RefType, Unit> .Second(Unit.Value);

            Assert.AreEqual(expected, actual);
        }
コード例 #11
0
ファイル: EqualityObject.cs プロジェクト: pfpack/pfpack-core
        public void EqualsWithObject_SourceIsSecondAndObjectIsDefault_ExpectFalse()
        {
            var source = TaggedUnion <StructType, RefType> .Second(ZeroIdRefType);

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

            var actual = source.Equals(obj);

            Assert.False(actual);
        }
コード例 #12
0
ファイル: EqualityObject.cs プロジェクト: pfpack/pfpack-core
        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);
        }
コード例 #13
0
ファイル: EqualityObject.cs プロジェクト: pfpack/pfpack-core
        public void EqualsWithObject_SourceSecondValueEqualsObjectSecondValue_ExpectTrue()
        {
            var source = TaggedUnion <StructType, RefType> .Second(MinusFifteenIdRefType);

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

            var actual = source.Equals(obj);

            Assert.True(actual);
        }
コード例 #14
0
ファイル: ToString.cs プロジェクト: pfpack/pfpack-core
        public void ToString_SourceIsSecondAndValueToStringReturnsNull_ExpectEmptyString()
        {
            var sourceValue = new StubToStringType(null);

            var source = TaggedUnion <string, StubToStringType> .Second(sourceValue);

            var actual = source.ToString();

            Assert.IsEmpty(actual);
        }
コード例 #15
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);
        }
コード例 #16
0
        public void EqualsStatic_UnionASecondValueEqualsUnionBSecondValue_ExpectTrue()
        {
            var unionA = TaggedUnion <StructType, RefType?> .Second(MinusFifteenIdRefType);

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

            var actual = TaggedUnion <StructType, RefType?> .Equals(unionA, unionB);

            Assert.True(actual);
        }
コード例 #17
0
        public void OrInitialize_SourceIsSecond_ExpectSource()
        {
            var source = TaggedUnion <object, RefType> .Second(ZeroIdRefType);

            var other = TaggedUnion <object, RefType> .Second(PlusFifteenIdRefType);

            var actual = source.OrInitialize(() => other);

            Assert.AreEqual(source, actual);
        }
コード例 #18
0
        public void TaggedUnion_ToOptional_UnionIsSecond_ExpectAbsent()
        {
            var union = TaggedUnion <RefType, Unit> .Second(Unit.Value);

            var actual = union.ToOptional();

            var expected = Optional.Absent <RefType>();

            Assert.AreEqual(expected, actual);
        }
コード例 #19
0
        public async Task OrInitializeAsync_SourceIsSecond_ExpectSource()
        {
            var source = TaggedUnion <object, StructType> .Second(SomeTextStructType);

            var other = default(TaggedUnion <object, StructType>);

            var actual = await source.OrInitializeAsync(() => Task.FromResult(other));

            Assert.AreEqual(source, actual);
        }
コード例 #20
0
        public void OrInitialize_SourceIsFirst_ExpectSource()
        {
            var source = TaggedUnion <object, StructType> .First(new object());

            var other = TaggedUnion <object, StructType> .Second(SomeTextStructType);

            var actual = source.OrInitialize(() => other);

            Assert.AreEqual(source, actual);
        }
コード例 #21
0
        public void EqualsWithOther_SourceIsFirstAndOtherIsSecond_ExpectFalse()
        {
            var source = TaggedUnion <RefType?, RefType?> .First(null);

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

            var actual = source.Equals(other);

            Assert.False(actual);
        }
コード例 #22
0
        public void EqualsWithOther_SourceSecondValueEqualsOtherSecondValue_ExpectTrue()
        {
            var source = TaggedUnion <StructType, RefType> .Second(MinusFifteenIdRefType);

            var other = (TaggedUnion <StructType, RefType>)MinusFifteenIdRefType;

            var actual = source.Equals(other);

            Assert.True(actual);
        }
コード例 #23
0
        public void SecondOrThrowWithFactory_SourceIsSecond_ExpectSourceValue(
            object?sourceValue)
        {
            var source = TaggedUnion <RefType, object?> .Second(sourceValue);

            var resultException = new SomeException();

            var actual = source.SecondOrThrow(() => resultException);

            Assert.AreEqual(sourceValue, actual);
        }
コード例 #24
0
        public void FirstOrThrowWithFactory_SourceIsSecond_ExpectCreatedException()
        {
            var source = TaggedUnion <StructType, object?> .Second(new object());

            var resultException = new SomeException();

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

            Assert.AreSame(resultException, actualExcepption);
        }
コード例 #25
0
ファイル: ToString.cs プロジェクト: pfpack/pfpack-core
        public void ToString_SourceIsSecondAndValueToStringDoesNotReturnNull_ExpectResultOfValueToString(
            string resultOfValueToString)
        {
            var sourceValue = new StubToStringType(resultOfValueToString);

            var source = TaggedUnion <StructType, StubToStringType> .Second(sourceValue);

            var actual = source.ToString();

            Assert.AreEqual(resultOfValueToString, actual);
        }
コード例 #26
0
        public void Fold_SourceIsSecond_ExpectSecondResult()
        {
            var source = TaggedUnion <int, StructType> .Second(SomeTextStructType);

            var first  = PlusFifteenIdRefType;
            var second = ZeroIdRefType;

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

            Assert.AreEqual(second, actual);
        }
コード例 #27
0
ファイル: HashCode.cs プロジェクト: pfpack/pfpack-core
        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);
        }
コード例 #28
0
        public async Task MapSecondValueAsync_SourceIsSecond_ExpectMapppedValueSecondUnion()
        {
            var sourceValue = SomeTextStructType;
            var source      = TaggedUnion <object, StructType> .Second(sourceValue);

            var mappedValue = MinusFifteenIdRefType;
            var actual      = await source.MapSecondValueAsync(_ => ValueTask.FromResult(mappedValue));

            var expected = TaggedUnion <object, RefType> .Second(mappedValue);

            Assert.AreEqual(expected, actual);
        }
コード例 #29
0
        public void FoldWithOtherFactory_SourceIsSecond_ExpectSecondResult()
        {
            var source = TaggedUnion <int, object> .Second(new object());

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

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

            Assert.AreEqual(second, actual);
        }
コード例 #30
0
ファイル: MapSecond.cs プロジェクト: pfpack/pfpack-core
        public void MapSecond_SourceIsSecond_ExpectMappedValueSecondUnion()
        {
            var sourceValue = new object();
            var source      = TaggedUnion <StructType, object> .Second(sourceValue);

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

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

            Assert.AreEqual(expected, actual);
        }