public void BindShouldSucceedWhenSuccess() { // Arrange var value = 1; Exceptional <int> exceptional = value; Exceptional <bool> exceptionalWithSuccess = true; var exception = new SomeException("Some exception"); Exceptional <bool> exceptionalWithException = exception; Func <int, Exceptional <bool> > toAnotherExceptional = (i) => { if (i.Equals(1)) { return(exceptionalWithSuccess); } else { return(exceptionalWithException); } }; // Act var result = exceptional.Bind(toAnotherExceptional); // Assert result.Should().Be(exceptionalWithSuccess); }
public void BindShouldNotInvokeFuncWhenException() { // Arrange var exception = new SomeException("Some exception"); Exceptional <int> exceptional = exception; Exceptional <bool> exceptionalWithSuccess = true; var anotherException = new SomeException("Some another exception"); Exceptional <bool> exceptionalWithException = anotherException; Func <int, Exceptional <bool> > toAnotherExceptional = (i) => { if (i.Equals(1)) { return(exceptionalWithSuccess); } else { return(exceptionalWithException); } }; // Act var result = exceptional.Bind(toAnotherExceptional); // Assert result.ToString().Should().Be(exceptional.ToString()); }
public void SingleOrAbsentWithExceptionFactory_ReadOnlyListSourceContainsMoreThanOneElement_ExpectCreatedException() { var source = CreateReadOnlyList(PlusFifteenIdRefType, MinusFifteenIdRefType); var createdException = new SomeException(); var ex = Assert.Throws <SomeException>(() => _ = source.SingleOrAbsent(() => createdException)); Assert.AreSame(createdException, ex); }
public void OrThrowWithFactory_SourceIsAbsent_ExpectFactoryResultException() { var source = Optional <StructType> .Absent; var resultException = new SomeException(); var actualException = Assert.Throws <SomeException>(() => _ = source.OrThrow(() => resultException)); Assert.AreSame(resultException, actualException); }
public void FailureOrThrowWithExceptionFactory_SourceIsSuccess_ExpectExceptionFromFactory( Result <RefType, StructType> source) { var exceptionFromFactory = new SomeException(); var actualException = Assert.Throws <SomeException>( () => _ = source.FailureOrThrow(() => exceptionFromFactory)); Assert.AreEqual(exceptionFromFactory, actualException); }
public void FilterNotNullOrThrowWithFactory_SourceValueIsNull_ExpectCreatedException() { var source = Optional <StructType?> .Present(null); var resultException = new SomeException(); var ex = Assert.Throws <SomeException>(() => _ = source.FilterNotNullOrThrow(() => resultException)); Assert.AreSame(resultException, ex); }
public void FirstOrThrowWithFactory_SourceIsDefault_ExpectInvalidOperationException() { var source = default(TaggedUnion <int, RefType?>); var resultException = new SomeException(); var actualExcepption = Assert.Throws <SomeException>( () => _ = source.FirstOrThrow(() => resultException)); Assert.AreSame(resultException, actualExcepption); }
public void ImplicitOperatorOverloadingShouldThrowWhenExceptionIsNull() { // Arrange SomeException exception = null; // Act Action act = () => { Exceptional <string> exceptional = exception; }; // Assert act.Should().Throw <ExceptionalExceptionMustNotBeNullException>(); }
public void ImplicitOperatorOverloadingShouldNotThrowWhenExceptionIsNotNull() { // Arrange var exception = new SomeException(); // Act Action act = () => { Exceptional <string> exceptional = exception; }; // Assert act.Should().NotThrow(); }
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 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 FilterNotNullOrThrowWithFactory_SourceValueIsNullStructType_ExpectCreatedException() { var source = Optional <StructType?> .Present(null); var createdException = new SomeException(); var actualExcepton = Assert.Throws <SomeException>( () => _ = source.FilterNotNullOrThrow(() => createdException)); Assert.AreSame(createdException, actualExcepton); }
public void FirstOrThrowWithFactory_SourceIsFirst_ExpectSourceValue() { var sourceValue = SomeTextStructType; TaggedUnion <StructType, RefType> source = sourceValue; var resultException = new SomeException(); var actual = source.FirstOrThrow(() => 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 ImplicitOperatorOverloadingShouldSetCorrectDataWhenExceptionIsNotNull() { // Arrange var exception = new SomeException(); // Act Exceptional <string> exceptional = exception; // Assert exceptional.Exception.Should().Be(exception); exceptional.Value.Should().BeNull(); }
public void EquableNullMustPassWhenException() { // Arrange var exception = new SomeException(); Exceptional <string> exceptional = exception; // Act var result = new Equable().Null(exceptional); // Assert result.Should().Pass(); }
public void MapShouldNotInvokeFuncWhenException() { // Arrange var exception = new SomeException("Some exception"); Exceptional <int> exceptional = exception; Func <int, int> increment = i => i + 1; // Act var result = exceptional.Map(increment); // Assert result.ToString().Should().Be("Exception(Some exception)"); }
public void EquableEqualMustPassWhenBothException() { // Arrange var firstException = new SomeException(); Exceptional <string> first = firstException; var secondException = new SomeException(); Exceptional <string> second = secondException; // Act var result = new Equable().Equal(first, second); // Assert result.Should().Pass(); }
public async Task MatchWithTaskShouldReturnException() { // Arrange var exception = new SomeException("message"); Exceptional <string> exceptional = exception; // Act var result = await exceptional.Match( Exception : (x) => $"Result=Exception({x.GetType().Name})", Success : async (x) => await Task.FromResult($"Result=Success({x})") ); // Assert result.Should().Be("Result=Exception(SomeException)"); }
public void MatchShouldReturnException() { // Arrange var exception = new SomeException(); Exceptional <string> exceptional = exception; // Act var result = exceptional.Match( Exception: (x) => $"Result=Exception({x.GetType().Name})", Success: (x) => $"Result=Success({x})" ); // Assert result.Should().Be("Result=Exception(SomeException)"); }
public void EquableUnequalMustPassWhenFirstExceptionAndSecondSuccess() { // Arrange var firstException = new SomeException(); Exceptional <string> first = firstException; var value = "any value of any type besides Exception"; Exceptional <string> second = value; // Act var result = new Equable().Unequal(first, second); // Assert result.Should().Pass(); }
public void SingleOrAbsentByPredicateAndFactory_ReadOnlyListPredicateResultIsTrueMoreThanOneTime_ExpectCreatedException() { var expectedText = "Expected Text"; var expectedValue = new StructType { Text = expectedText }; var expectedTextStructType = new StructType { Text = expectedText }; var source = CreateReadOnlyList <StructType?>(SomeTextStructType, expectedValue, NullTextStructType, null, expectedTextStructType); var mockPredicate = CreateMockPredicate <StructType?>( item => expectedText.Equals(item?.Text, StringComparison.InvariantCultureIgnoreCase)); var createdException = new SomeException(); var actualException = Assert.Throws <SomeException>(() => _ = source.SingleOrAbsent( mockPredicate.Object.Invoke, () => createdException)); Assert.AreSame(createdException, actualException); }