public async Task Results_From_Stages_And_Source_Are_Combined() { var data = new Dictionary <int, int> { { 1, 4 }, { 2, 3 }, { 5, 9 } }; var stage = new StaticDataStage <int, int>(data.Where(pair => pair.Key % 2 != 0).ToDictionary(pair => pair.Key, pair => pair.Value)); var source = new StaticDataSource <int, int>(data.Where(pair => pair.Key % 2 == 0).ToDictionary(pair => pair.Key, pair => pair.Value)); var pipeline = new Pipeline <int, int>(source, stage); var results = await pipeline.GetAsync(data.Keys); Assert.Equal(data, results); }
public static IEnumerable <object[]> GetPossibleConstructorCalls() { var config = new PipelineConfig <int, int>(); var source = new StaticDataSource <int, int>(); var stage = new StaticDataStage <int, int>(); yield return(new object[] { null, config, new IStage <int, int>[] { stage } }); yield return(new object[] { source, null, new IStage <int, int>[] { stage } }); yield return(new object[] { source, config, new IStage <int, int>[] { stage, null } }); yield return(new object[] { source, config, null }); }
public async Task InvalidOperationException_Is_Thrown_If_State_Has_Invalid_Index(int index) { var source = new StaticDataSource <int, int> { { 1, 1 }, { 2, 2 } }; var stage = new StaticDataStage <int, int>(); var machine = new Mock <IStateMachine <int, int> >(); machine.Setup(m => m.Handle(It.IsAny <State <int, int> >(), It.IsAny <IRequest <int, int> >())) .Returns <State <int, int>, IRequest <int, int> >((s, t) => { s.Index = index; return(s); }); var pipeline = new Pipeline <int, int>(source, new PipelineConfig <int, int> { InitialStateMachine = machine.Object }, stage); var exception = await Assert.ThrowsAnyAsync <PipelineException <int, int> >(() => pipeline.GetAsync(source.Keys.ToArray())); Assert.Collection(exception.InnerExceptions, ex => Assert.IsType <InvalidOperationException>(ex)); }
public async Task Partial_Results_Are_Returned_When_Exceptions_Occur_In_A_Source() { var data = new Dictionary <int, int> { { 5, 2 }, { 6, 3 }, { 7, 4 } }; var source = new BlockingSource <int, int>(); var stage = new StaticDataStage <int, int>(data); var cancellationSource = new CancellationTokenSource(); var pipeline = new Pipeline <int, int>(source, stage); var resultsTask = pipeline.GetAsync(data.Keys, cancellationSource.Token); await Assert.ThrowsAsync <TimeoutException>( () => resultsTask.TimeoutAfter(TimeSpan.FromMilliseconds(100))); cancellationSource.Cancel(); Assert.Equal(data, await resultsTask); }