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); }
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); }
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); }
public void ImplicitFirst_ExpectIsSecondGetsFalse() { TaggedUnion <RefType, StructType> taggedUnion = MinusFifteenIdRefType; Assert.False(taggedUnion.IsSecond); }
public void ImplicitSecond_ExpectIsFirstGetsFalse() { TaggedUnion <StructType?, RefType> taggedUnion = ZeroIdRefType; Assert.False(taggedUnion.IsFirst); }
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); }
public void First_Implicit_ExpectIsSecondGetsFalse() { TaggedUnion <StructType, RefType> taggedUnion = SomeTextStructType; Assert.False(taggedUnion.IsSecond); }
public void Second_Explicit_ExpectIsInitializedGetsTrue( object? sourceValue) { var taggedUnion = TaggedUnion<StructType, object?>.Second(sourceValue); Assert.True(taggedUnion.IsInitialized); }
public void Second_Explicit_ExpectIsSecondGetsTrue( object? sourceValue) { var taggedUnion = TaggedUnion<RefType?, object?>.Second(sourceValue); Assert.True(taggedUnion.IsSecond); }
public void Second_Implicit_ExpectIsFirstGetsFalse() { TaggedUnion <StructType, RefType?> taggedUnion = PlusFifteenIdRefType; Assert.False(taggedUnion.IsFirst); }
public void First_Constructor_ExpectIsSecondGetsFalse() { var taggedUnion = new TaggedUnion <StructType, RefType>(SomeTextStructType); Assert.False(taggedUnion.IsSecond); }