public async Task Result_With_Error_FlatmapsRS_Result_with_Value__Expects_Result_With_Error() { var flatSelectorExecuted = false; var resultSelectorExectued = false; var errorSelectorExecuted = false; await AssertionUtilities .DivisionAsync(2, 0) .FullFlatMap(x => { flatSelectorExecuted = true; return(AssertionUtilities.Division(x, 2)); }, (y, x) => { resultSelectorExectued = true; return(y + x); }, s => { errorSelectorExecuted = true; return(s); }) .AssertError("Can not divide '2' with '0'."); Assert.True(errorSelectorExecuted, "Errorselector should get exeuted since there is an error in the soruce."); Assert.False(flatSelectorExecuted, "The flatmapSelector should not get exectued if the source Result<T, TError> contains error."); Assert.False(resultSelectorExectued, "The resultSelector should not get exectued if the source Result<T, TError> contains error."); }
public async System.Threading.Tasks.Task First_True() => await AssertionUtilities .DivisionAsync(10, 2) .Multiple( x => x.Filter(y => true, d => "Should never happen!"), x => x.Filter(y => false, d => "Should happen!") ).AssertError(new[] { "Should happen!" });
public async Task Result_With_Value_FlatmapsRS_Result_with_Error__Expects_Result_With_Error() { var flatSelectorExecuted = false; var resultSelectorExectued = false; var errorSelectorExecuted = false; await AssertionUtilities .DivisionAsync(2, 2) .FullFlatMap(x => { flatSelectorExecuted = true; return(AssertionUtilities.Division(x, 0)); }, (y, x) => { resultSelectorExectued = true; return(y + x); }, s => { errorSelectorExecuted = true; return(s); }) .AssertError("Can not divide '1' with '0'."); Assert.False(errorSelectorExecuted, "Errorselector should not get exeuted since the errror came from the result given to the flatselector."); Assert.True(flatSelectorExecuted, "The flatmapSelector should get exectued."); Assert.False(resultSelectorExectued, "The resultSelector should not get executed since flatselector result failed."); }
public void Passing_Null_Predicate_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.PredicateName, () => AssertionUtilities.DivisionAsync(10, 2).IsErrorWhenAsync(null, d => "") ); }
public async System.Threading.Tasks.Task Result_With_Error__Expects_Enumerable_With_Element_Element() { var result = (await AssertionUtilities.DivisionAsync(20, 0).ToErrorEnumerable()).ToArray(); Assert.Single(result); Assert.Collection(result, x => Assert.Equal("Can not divide '20' with '0'.", x)); }
public async Task Result_With_Value_FlatmapsRS_Result_with_Value__Expects_Result_With_Value() { var flatSelectorExecuted = false; var resultSelectorExectued = false; var errorSelectorExecuted = false; await AssertionUtilities .DivisionAsync(2, 2) .FlatMapAsync(x => { flatSelectorExecuted = true; return(AssertionUtilities.DivisionAsync(x, 2)); }, (y, x) => { resultSelectorExectued = true; return(y + x); }, s => { errorSelectorExecuted = true; return(s); }) .AssertValue(1.5d); Assert.True(flatSelectorExecuted, "Flatmapselecotr should get executed."); Assert.True(resultSelectorExectued, "ResultSelector should get executed since both source and the result from flatmapselector contains values."); Assert.False(errorSelectorExecuted, "Erroselector should not get executed since both source and the result from flatmapselector contains values."); }
public async System.Threading.Tasks.Task Result_With_Value__Expects_Enumerable_With_One_Element() { var result = (await AssertionUtilities.DivisionAsync(20, 2).ToEnumerable()).ToArray(); Assert.Single(result); Assert.Collection(result, x => Assert.Equal(10, x)); }
public async System.Threading.Tasks.Task First_And_Second_True() => await AssertionUtilities .DivisionAsync(10, 2) .Multiple( x => x.Filter(y => true, d => "Should never happen!"), x => x.Filter(y => true, d => "Should never happen!") ).AssertValue(5);
public async System.Threading.Tasks.Task With_Error_First_True() => await AssertionUtilities .DivisionAsync(10, 0) .Multiple( x => x.Filter(y => true, d => "Should never happen!"), x => x.Filter(y => false, d => "Should happen!") ).AssertError(new[] { "Can not divide '10' with '0'." });
public void Passing_Null_Predicate_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.PredicateName, () => AssertionUtilities.DivisionAsync(10, 0).FilterAsync(null, x => "This should never happen!") ); }
public async System.Threading.Tasks.Task Passing_Null_Selector_Throws() { await Assert.ThrowsAsync <ArgumentNullException>( AssertionUtilities.SelectorName, () => AssertionUtilities.DivisionAsync(10, 0).MapError(x => - 1d).Match((Func <double, double>)null) ); }
public void Passing_Null_Selector_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.SelectorName, () => AssertionUtilities.DivisionAsync(10, 2) .FlatMapAsync( (Func <double, IAsyncResult <double, string> >)null ) );
public void Passing_Null_ResultSelector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.ResultSelector, () => AssertionUtilities .DivisionAsync(2, 0) .FullFlatMap(x => AssertionUtilities.Division(x, 2), (Func <double, double, double>)null, s => s)); }
public void Passing_Null_ResultSelector_Overload_ErrorSelector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.ErrorSelectorName, () => AssertionUtilities .DivisionAsync(2, 0) .FlatMap(x => AssertionUtilities.Division(x, 0), (d, d1) => d + d1, null)); }
public void Passing_Null_Selector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.SelectorName, () => AssertionUtilities .DivisionAsync(2, 0) .FullFlatMap((Func <double, IResult <double, string> >)null, (d, d1) => d + d1, s => s)); }
public void Passing_Null_ErrorSelector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.ErrorSelectorName, () => AssertionUtilities .DivisionAsync(2, 0) .FullFlatMap(x => AssertionUtilities.Division(x, 2), null)); }
public void Passing_Null_ErrorSelector_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.ErrorSelectorName, () => AssertionUtilities.DivisionAsync(10, 2) .FlatMapAsync( d => AssertionUtilities.DivisionAsync(d, 2), null ) );
public void Passing_Null_Action_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.ActionParamName, () => AssertionUtilities .DivisionAsync(10, 0) .DoWithAsync(null) ); }
public void Async_Selector_And_ErrorSelector_Passing_Null_ErrorSelector_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.ErrorSelectorName, () => AssertionUtilities.DivisionAsync(10, 2) .FullMapAsync(async d => { await AssertionUtilities.Delay; return(string.Empty); }, (Func <string, Task <string> >)null) );
public void Async_Selector_And_ErrorSelector_Passing_Null_Selector_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.SelectorName, () => AssertionUtilities.DivisionAsync(10, 2).FullMapAsync((Func <double, Task <string> >)null, async s => { await AssertionUtilities.Delay; return(s); }) );
public void Passing_Null_ResultSelector_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.ResultSelector, () => AssertionUtilities.Division(10, 2) .FlatMapAsync( s => AssertionUtilities.DivisionAsync(s, 2), (Func <double, double, double>)null ) );
public void Passing_Null_Selector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.SelectorName, () => AssertionUtilities .DivisionAsync(2, 0) .MapError <string>(null) ); }
public void Passing_Null_Selector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.SelectorName, () => { AssertionUtilities .DivisionAsync(2, 0) .FlatMap <double, string>(null, s => s); }); }
public void Passing_Null_ErrorSelector_Throws() { Assert.Throws <ArgumentNullException>( AssertionUtilities.ErrorSelectorName, () => AssertionUtilities .DivisionAsync(10, 0).FilterAsync(async d => { await Task.Delay(50); return(d == 2); }, null) ); }
public async System.Threading.Tasks.Task Pressure_Test() => await AssertionUtilities.DivisionAsync(10, 2).Multiple( x => x, x => x, Enumerable.Range(0, 100000).Select(x => new Func <IAsyncResult <double, string>, IAsyncResult <double, string> >( y => y.Filter(d => true, _ => "This should never happen!") ) ).ToArray() ).AssertValue(5);
public void Passing_Null_ErrorSelector_With_ResultSelector_Overload_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.ErrorSelectorName, () => AssertionUtilities.DivisionAsync(10, 2) .FlatMapAsync( s => AssertionUtilities.DivisionAsync(s, 2), (d, d1) => d + d1, null ) );
Result_With_Value__Expect_Action() { var selectorExectued = false; var errorSelectorExectued = false; await AssertionUtilities.DivisionAsync(10, 2) .Match(d => { selectorExectued = true; }, s => { errorSelectorExectued = true; }); Assert.True(selectorExectued, "Selector should get executed."); Assert.False(errorSelectorExectued, "Error selector not should get exectued."); }
public async Task Result_With_Error__Expect_ErrorAction() { var selectorExectued = false; var errorSelectorExectued = false; await AssertionUtilities.DivisionAsync(10, 0) .Match(d => { selectorExectued = true; }, s => { errorSelectorExectued = true; }); Assert.False(selectorExectued, "Selector should not get executed."); Assert.True(errorSelectorExectued, "Error selector should get exectued."); }
Result_With_Value__Expects_Action_Not_To_Be_Invoked() { var actionExectued = false; await AssertionUtilities .DivisionAsync(10, 2) .DoWithError(d => actionExectued = true) .AssertValue(5); Assert.False(actionExectued, "Should not get exectued since there's an error."); }
public void Passing_Null_Selector_With_ResultSelector_Overload_Throws() => Assert.Throws <ArgumentNullException>( AssertionUtilities.SelectorName, () => AssertionUtilities.DivisionAsync(10, 2) .FlatMapAsync( (Func <double, IAsyncResult <double, string> >)null, (d, d1) => d + d1 , s => s ) );