コード例 #1
0
        public void SingleInputSingleOutput()
        {
            var board = new RelayBoard();

            var input  = new RelayInputMock("I");
            var output = new RelayOutputMock("O");

            board.Connect(input, output);
            board.Initialize();

            output.Check(false);

            input.Notify();
            output.Check(true);

            output.Reset();
            output.Check(false);

            input.Notify();
            output.Check(true);

            input.Notify();
            output.Check(true);

            output.Reset();
            output.Check(false);

            output.Reset();
            output.Check(false);

            board.Dispose();
        }
コード例 #2
0
        public void SingleInputManyOutputs()
        {
            const int nbSusbscriber = 10;

            var board = new RelayBoard();

            var input   = new RelayInputMock("I");
            var outputs = new RelayOutputMock[nbSusbscriber];

            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i] = new RelayOutputMock("O" + (i + 1));
            }

            for (var i = 0; i < nbSusbscriber; i++)
            {
                board.Connect(input, outputs[i]);
            }
            board.Initialize();

            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i].Check(false);
            }

            input.Notify();
            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i].Check(true);
            }

            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i].Reset();
                outputs[i].Check(false);
            }

            input.Notify();
            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i].Check(true);
            }

            input.Notify();
            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i].Check(true);
            }

            for (var i = 0; i < nbSusbscriber; i++)
            {
                outputs[i].Reset();
                outputs[i].Check(false);
            }

            board.Dispose();
        }
コード例 #3
0
        public void UnsubcribeUseCaseFailed()
        {
            var board = new RelayBoard();

            var i1 = new RelayInputMock("I1");
            var i2 = new RelayInputMock("I2");
            var i3 = new RelayInputMock("I3");
            var i4 = new RelayInputMock("I4");

            var o1 = new RelayOutputMock("O1");

            var c1 = board.Connect(i1, o1);
            var s1 = c1.Subscribe(p => { });
            var c2 = board.Connect(i2, o1);
            var s2 = c2.Subscribe(p => { });
            var c3 = board.Connect(i3, o1);
            var s3 = c3.Subscribe(p => { });
            var c4 = board.Connect(i4, o1);
            var s4 = c4.Subscribe(p => { });

            board.Initialize();

            o1.Check(false);

            i1.Notify();
            board.Poll(DateTime.Now);
            o1.CheckAndReset(true);

            i1.Notify();
            board.Poll(DateTime.Now);
            o1.CheckAndReset(true);

            i1.Notify();
            i2.Notify();
            i4.Notify();
            board.Poll(DateTime.Now);
            o1.CheckAndReset(true);

            i4.Notify();
            board.Poll(DateTime.Now);
            o1.CheckAndReset(true);

            c2.Dispose();
            s2.Dispose();

            i4.Notify();
            i1.Notify();
            board.Poll(DateTime.Now);
            o1.CheckAndReset(true);

            board.Dispose();
        }
コード例 #4
0
        public void UnsubcribeCallbackManyInputSingleOutput()
        {
            var board = new RelayBoard();

            var i1 = new RelayInputMock("I1");
            var i2 = new RelayInputMock("I2");
            var o1 = new RelayOutputMock("O1");

            var c1 = board.Connect(i1, o1)
                     .Subscribe(p => { });
            var c2 = board.Connect(i2, o1)
                     .Subscribe(p => { });

            board.Initialize();

            o1.Check(false);

            i1.Notify();
            o1.Check(true);

            o1.Reset();
            o1.Check(false);

            i2.Notify();
            o1.Check(true);

            o1.Reset();
            o1.Check(false);

            c2.Dispose();

            i1.Notify();
            o1.Check(true);

            o1.Reset();
            o1.Check(false);

            i2.Notify();
            o1.Check(true);

            board.Dispose();
        }
コード例 #5
0
        public void UnsubcribeConnectorSingleInputManyOutput()
        {
            var board = new RelayBoard();

            var i1 = new RelayInputMock("I1");
            var o1 = new RelayOutputMock("O1");
            var o2 = new RelayOutputMock("O2");

            var c1 = board.Connect(i1, o1);

            c1.Subscribe(p => { });
            var c2 = board.Connect(i1, o2);

            c2.Subscribe(p => { });

            board.Initialize();
            Console.WriteLine(board.Report());

            o1.Check(false);
            o2.Check(false);

            i1.Notify();
            o1.Check(true);
            o2.Check(true);

            o1.Reset();
            o2.Reset();
            o1.Check(false);
            o2.Check(false);

            c2.Dispose();
            Console.WriteLine(board.Report());

            i1.Notify();
            o1.Check(true);
            o2.Check(false);

            board.Dispose();
        }