public void GivenPipelineBlock_WhenSendMessage_ShouldReceiveMessage() { const int max = 100; var list = new List <int>(); var list2 = new List <int>(); var jobs = new PipelineBlock <int>() .Broadcast() .DoAction(x => list.Add(x)) .DoAction(x => list2.Add(x + 1000)); Enumerable.Range(0, max) .ForEach(x => jobs.Post(x).Verify().Assert(x => x == true, "Failed to post")); jobs.Complete(); jobs.Completion.Wait(); list.Count.Should().Be(max); list2.Count.Should().Be(max); list .Select((i, x) => new { i, x }) .All(x => x.i == x.x) .Should().BeTrue(); list2 .Select((x, i) => new { i, x }) .All(x => x.i + 1000 == x.x) .Should().BeTrue(); }
public void GivenPipelineBlock_ApplyTransform_ShouldPass() { const int max = 1000; const int offset = 10000; var list = new List <int>(); var list2 = new List <int>(); var jobs = new PipelineBlock <int>() .Select(x => x + 5) .Broadcast() .DoAction(x => list.Add(x)) .DoAction(x => list2.Add(x + offset)); Enumerable.Range(0, max) .ForEach(async x => await jobs.Send(x)); jobs.Complete(); jobs.Completion.Wait(); list.Count.Should().Be(max); list2.Count.Should().Be(max); list .Select((x, i) => new { x, i }) .All(x => x.x == x.i + 5) .Should().BeTrue(); list2 .Select((x, i) => new { i, x }) .All(x => x.i + offset + 5 == x.x) .Should().BeTrue(); }
public void GivenSimplePipeline_WhenPost_ShouldProcessMessage() { const int postValue = 100; var s1 = new List <int>(); var s1Pipeline = new PipelineBlock <int>().DoAction(x => s1.Add(x)); s1Pipeline.Post(postValue); s1Pipeline.Complete(); s1Pipeline.Completion.Wait(); s1.Count.Should().Be(1); s1[0].Should().Be(postValue); }
public void GivenPipelineBlock_WhenPostMessage_ShouldReceiveMessage() { const int max = 10; int count = 0; var list = new List <string>(); var pipeline = new PipelineBlock <string>() .Broadcast() .DoAction(x => count++) .DoAction(x => list.Add(x)); Enumerable.Range(0, max) .ForEach(x => pipeline.Post($"{x} message")); pipeline.Complete(); pipeline.Completion.Wait(); count.Should().Be(max); list.Count.Should().Be(max); }