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 GivenBuffer_ApplyTransformAndTwoSubpiplines_ShouldPass()
        {
            const int max    = 1000;
            const int offset = 10000;
            var       list   = new List <int>();
            var       list2  = new List <int>();

            var s1         = new List <int>();
            var s1Pipeline = new PipelineBlock <int>().DoAction(x => s1.Add(x));

            var s2         = new List <int>();
            var s2Pipeline = new PipelineBlock <int>().DoAction(x => s2.Add(x));

            var jobs = new PipelineBlock <int>()
                       .Register(s1Pipeline)
                       .Register(s2Pipeline)
                       .Select(x => x + 5)
                       .Broadcast()
                       .DoAction(x => list.Add(x))
                       .DoAction(x => list2.Add(x + offset))
                       .DoAction(x => s1Pipeline.Post(x))
                       .DoAction(x => s2Pipeline.Post(x));

            Enumerable.Range(0, max)
            .ForEach(async x => await jobs.Send(x));

            jobs.CompleteAndWait().Wait();

            list.Count.Should().Be(max);
            list2.Count.Should().Be(max);
            s1.Count.Should().Be(max);
            s2.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();

            s1
            .Select((x, i) => new { x, i })
            .All(x => x.x == x.i + 5)
            .Should().BeTrue();

            s2
            .Select((x, i) => new { x, i })
            .All(x => x.x == x.i + 5)
            .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 GivenRegisteredPipeline_WhenCompleteAndWait_ShouldProcessAllMessage()
        {
            const int postValue = 100;

            var s1         = new List <int>();
            var s1Pipeline = new PipelineBlock <int>().DoAction(x => s1.Add(x));

            var job = new PipelineBlock <int>()
                      .Register(s1Pipeline)
                      .DoAction(x => s1Pipeline.Post(x));

            job.Post(postValue);

            job.CompleteAndWait().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);
        }