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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void ToString_SourceIsFirstAndValueToStringReturnsNull_ExpectEmptyString() { var sourceValue = new StubToStringType(null); var source = TaggedUnion <StubToStringType, RefType> .First(sourceValue); var actual = source.ToString(); Assert.IsEmpty(actual); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }