public void CreateSendResult_ReturnsAResult_WithMessageReceivedFalse()
        {
            // Arrange
            var result = ReceiveOrSendResult <int, string> .CreateSendResult();

            // Act
            var messageReceived = result.MessageReceived;

            // Assert
            messageReceived.Should().BeFalse();
        }
        public void CreateSendResult_ReturnsAResult_WithMessageSentTrue()
        {
            // Arrange
            var result = ReceiveOrSendResult <int, string> .CreateSendResult();

            // Act
            var messageSent = result.MessageSent;

            // Assert
            messageSent.Should().BeTrue();
        }
Esempio n. 3
0
        public void ReceiveOrSend_GivenASendResultIsReturned_ReturnsThatResult()
        {
            // Arrange
            var expectedResult = ReceiveOrSendResult <int, string> .CreateSendResult();

            resultOutlet.Setup(r => r.Receive()).Returns(expectedResult);

            // Act
            var actualResult = valve.ReceiveOrSend("hello");

            // Assert
            actualResult.MessageSent.Should().BeTrue();
        }
Esempio n. 4
0
        public BigValvedPipe(IReadOnlyList <ISimpleInlet <TReceive> > inlets, IReadOnlyList <ISimpleOutlet <TSend> > outlets, TTieBreaker tieBreaker)
            : base(inlets, outlets)
        {
            Inlets     = inlets;
            Outlets    = outlets;
            TieBreaker = tieBreaker;

            // Construct all necessary pipes
            var preparationCapacityPipe = PipeBuilder.New.CapacityPipe <TSend>().WithCapacity(1).Build();
            var flushEitherOutletPipe   = PipeBuilder.New.BigEitherOutletPipe <TSend>().WithSize(Outlets.Count + 1).Build();

            var splittingPipes = Enumerable.Repeat <Func <ISplittingPipe <TSend> > >(() =>
                                                                                     PipeBuilder.New.SplittingPipe <TSend>().Build(), Outlets.Count)
                                 .Select(f => f()).ToList();

            var sendTransformPipes = Enumerable.Repeat <Func <ITransformPipe <TSend, ReceiveOrSendResult <TReceive, TSend> > > >(() =>
                                                                                                                                 PipeBuilder.New.TransformPipe <TSend, ReceiveOrSendResult <TReceive, TSend> >().WithMap(m => ReceiveOrSendResult <TReceive, TSend> .CreateSendResult()).Build(), Outlets.Count)
                                     .Select(f => f()).ToList();

            var receiveTransformPipes = Enumerable.Repeat <Func <ITransformPipe <TReceive, ReceiveOrSendResult <TReceive, TSend> > > >(() =>
                                                                                                                                       PipeBuilder.New.TransformPipe <TReceive, ReceiveOrSendResult <TReceive, TSend> >().WithMap(ReceiveOrSendResult <TReceive, TSend> .CreateReceiveResult).Build(), Inlets.Count)
                                        .Select(f => f()).ToList();

            var resultPipe = PipeBuilder.New.BigEitherInletPipe <ReceiveOrSendResult <TReceive, TSend> >().WithSize(inlets.Count + outlets.Count).WithTieBreaker(TieBreaker).Build();

            // Form the pipe system. Note that this DOES form a non-tree, but its correctness is guaranteed
            // by the fact the individual receivers of the splitting pipes are distinct.
            preparationCapacityPipe.Outlet.ConnectTo(flushEitherOutletPipe.Inlet, false);

            for (var i = 0; i < Outlets.Count; i++)
            {
                flushEitherOutletPipe.Outlets[i].ConnectTo(splittingPipes[i].Inlet, false);
                splittingPipes[i].RightOutlet.ConnectTo(sendTransformPipes[i].Inlet, false);
                sendTransformPipes[i].Outlet.ConnectTo(resultPipe.Inlets[Inlets.Count + i], false);

                CreateAndConnectAdapter(splittingPipes[i].LeftOutlet, Outlets[i]);
            }

            for (var i = 0; i < Inlets.Count; i++)
            {
                receiveTransformPipes[i].Outlet.ConnectTo(resultPipe.Inlets[i], false);

                CreateAndConnectAdapter(receiveTransformPipes[i].Inlet, Inlets[i]);
            }

            Valve = new Valve <TReceive, TSend>(preparationCapacityPipe.Inlet, flushEitherOutletPipe.Outlets[outlets.Count], resultPipe.Outlet);
        }
Esempio n. 5
0
        public ValvedPipe(ISimpleInlet <TReceive> inlet, ISimpleOutlet <TSend> outlet, TTieBreaker tieBreaker) : base(new[] { inlet }, new[] { outlet })
        {
            Inlet      = inlet;
            Outlet     = outlet;
            TieBreaker = tieBreaker;

            var preparationCapacityPipe = PipeBuilder.New.CapacityPipe <TSend>().WithCapacity(1).Build();
            var flushEitherOutletPipe   = PipeBuilder.New.EitherOutletPipe <TSend>().Build();
            var splittingPipe           = PipeBuilder.New.SplittingPipe <TSend>().Build();
            var sendTransformPipe       = PipeBuilder.New.TransformPipe <TSend, ReceiveOrSendResult <TReceive, TSend> >().WithMap(m => ReceiveOrSendResult <TReceive, TSend> .CreateSendResult()).Build();
            var receiveTransformPipe    = PipeBuilder.New.TransformPipe <TReceive, ReceiveOrSendResult <TReceive, TSend> >().WithMap(ReceiveOrSendResult <TReceive, TSend> .CreateReceiveResult).Build();
            var eitherInletPipe         = PipeBuilder.New.EitherInletPipe <ReceiveOrSendResult <TReceive, TSend> >().WithTieBreaker(TieBreaker).Build();

            preparationCapacityPipe.Outlet.ConnectTo(flushEitherOutletPipe.Inlet);
            flushEitherOutletPipe.RightOutlet.ConnectTo(splittingPipe.Inlet);
            splittingPipe.RightOutlet.ConnectTo(sendTransformPipe.Inlet);
            sendTransformPipe.Outlet.ConnectTo(eitherInletPipe.LeftInlet);
            receiveTransformPipe.Outlet.ConnectTo(eitherInletPipe.RightInlet);

            CreateAndConnectAdapter(splittingPipe.LeftOutlet, Outlet);
            CreateAndConnectAdapter(receiveTransformPipe.Inlet, Inlet);

            Valve = new Valve <TReceive, TSend>(preparationCapacityPipe.Inlet, flushEitherOutletPipe.LeftOutlet, eitherInletPipe.Outlet);
        }