Esempio n. 1
0
        public void Equality_UnionAFirstValueEqualsUnionBFirstValue_ExpectTrue()
        {
            var aValue = new StructType
            {
                Text = SomeString
            };
            var unionA = (TaggedUnion <StructType, RefType?>)aValue;

            var bValue = new StructType
            {
                Text = SomeString
            };
            var unionB = TaggedUnion <StructType, RefType?> .First(bValue);

            var actual = unionA == unionB;

            Assert.True(actual);
        }
        public async Task FoldValueAsyncWithOtherFactory_SourceIsSecond_ExpectSecondResult()
        {
            var source = TaggedUnion <object, RefType?> .Second(null);

            var first = new StructType {
                Text = "first"
            };
            var second = new StructType {
                Text = "second"
            };
            var other = new StructType {
                Text = "other"
            };

            var actual = await source.FoldValueAsync(
                _ => ValueTask.FromResult(first), _ => ValueTask.FromResult(second), () => other);

            Assert.AreEqual(second, actual);
        }
        public async Task FoldValueAsyncWithOtherFactoryAsync_SourceIsSecond_ExpectSecondResult()
        {
            var source = TaggedUnion <decimal, RefType> .Second(MinusFifteenIdRefType);

            var first  = SomeTextStructType;
            var second = new StructType {
                Text = "second"
            };
            var other = new StructType {
                Text = "other"
            };

            var actual = await source.FoldValueAsync(
                _ => ValueTask.FromResult(first),
                _ => ValueTask.FromResult(second),
                () => ValueTask.FromResult(other));

            Assert.AreEqual(second, actual);
        }
        public bool Equals(TaggedUnion <TFirst, TSecond> other)
        {
            if (tag != other.tag)
            {
                return(false);
            }

            if (tag == Tag.First)
            {
                return(FirstComparer.Equals(first, other.first));
            }

            if (tag == Tag.Second)
            {
                return(SecondComparer.Equals(second, other.second));
            }

            return(true);
        }
Esempio n. 5
0
        public void GetHashCode_SourceSecondValueIsNotSameAsOtherSecondValue_ExpectValuesAreNotEqual()
        {
            var id          = PlusFifteen;
            var sourceValue = new RefType
            {
                Id = id
            };
            var source = TaggedUnion <StructType?, RefType> .Second(sourceValue);

            var otherValue = new RefType
            {
                Id = id
            };
            var other = TaggedUnion <StructType?, RefType> .Second(otherValue);

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

            Assert.AreNotEqual(sourceHashCode, otherHashCode);
        }
Esempio n. 6
0
        public void Equals_UnionASecondValueEqualsUnionBSecondValue_ExpectTrue()
        {
            var text = "some-text";

            var aValue = new StructType
            {
                Text = text
            };
            var unionA = TaggedUnion <RefType, StructType> .Second(aValue);

            var bValue = new StructType
            {
                Text = text
            };
            var unionB = (TaggedUnion <RefType, StructType>)bValue;

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

            Assert.True(actual);
        }
        public void First_Explicit_ExpectIsSecondGetsFalse()
        {
            var taggedUnion = TaggedUnion <StructType, RefType> .First(SomeTextStructType);

            Assert.False(taggedUnion.IsSecond);
        }
Esempio n. 8
0
        public void ImplicitFirst_ExpectIsSecondGetsFalse()
        {
            TaggedUnion <RefType, StructType> taggedUnion = MinusFifteenIdRefType;

            Assert.False(taggedUnion.IsSecond);
        }
Esempio n. 9
0
        public void ImplicitSecond_ExpectIsFirstGetsFalse()
        {
            TaggedUnion <StructType?, RefType> taggedUnion = ZeroIdRefType;

            Assert.False(taggedUnion.IsFirst);
        }
Esempio n. 10
0
 public static bool Equals(TaggedUnion <TFirst, TSecond> left, TaggedUnion <TFirst, TSecond> right)
 =>
 left.Equals(right);
        public void Second_ExpectIsFirstGetsFalse()
        {
            var taggedUnion = new TaggedUnion <StructType, RefType?>(PlusFifteenIdRefType);

            Assert.False(taggedUnion.IsFirst);
        }
Esempio n. 12
0
        public void First_Implicit_ExpectIsSecondGetsFalse()
        {
            TaggedUnion <StructType, RefType> taggedUnion = SomeTextStructType;

            Assert.False(taggedUnion.IsSecond);
        }
Esempio n. 13
0
 public void Second_Explicit_ExpectIsInitializedGetsTrue(
     object? sourceValue)
 {
     var taggedUnion = TaggedUnion<StructType, object?>.Second(sourceValue);
     Assert.True(taggedUnion.IsInitialized);
 }
Esempio n. 14
0
 public void Second_Explicit_ExpectIsSecondGetsTrue(
     object? sourceValue)
 {
     var taggedUnion = TaggedUnion<RefType?, object?>.Second(sourceValue);
     Assert.True(taggedUnion.IsSecond);
 }
Esempio n. 15
0
        public void Second_Implicit_ExpectIsFirstGetsFalse()
        {
            TaggedUnion <StructType, RefType?> taggedUnion = PlusFifteenIdRefType;

            Assert.False(taggedUnion.IsFirst);
        }
Esempio n. 16
0
        public void First_Constructor_ExpectIsSecondGetsFalse()
        {
            var taggedUnion = new TaggedUnion <StructType, RefType>(SomeTextStructType);

            Assert.False(taggedUnion.IsSecond);
        }