public void ToString_SourceIsSecondAndValueIsNull_ExpectEmptyString() { var source = TaggedUnion <decimal, StructType?> .Second(null); var actual = source.ToString(); Assert.IsEmpty(actual); }
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); }
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); }
public void FirstOrThrow_SourceIsSecond_ExpectInvalidOperationException() { var source = TaggedUnion <StructType, RefType> .Second(PlusFifteenIdRefType); var ex = Assert.Throws <InvalidOperationException>(() => _ = source.FirstOrThrow()); AssertContainsFirst(First, ex !.Message); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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 EqualsWithObject_SourceSecondValueEqualsObjectSecondValue_ExpectTrue() { var source = TaggedUnion <StructType, RefType> .Second(MinusFifteenIdRefType); object?obj = (TaggedUnion <StructType, RefType>)MinusFifteenIdRefType; var actual = source.Equals(obj); Assert.True(actual); }
public void ToString_SourceIsSecondAndValueToStringReturnsNull_ExpectEmptyString() { var sourceValue = new StubToStringType(null); var source = TaggedUnion <string, StubToStringType> .Second(sourceValue); var actual = source.ToString(); Assert.IsEmpty(actual); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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 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); }
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); }
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); }