Exemple #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public Cable()
        {
            CurrentPowerState = PowerState.On;

            Top    = new EnergyPort();
            Bottom = new EnergyPort();
            Right  = new EnergyPort();
            Left   = new EnergyPort();
            _ports = new[] { Top, Right, Bottom, Left };

            UpgradeContainer = new UpgradeContainer(this, 5);
        }
        public void ReceiveTest()
        {
            // given: EnergyPort
            var ep = new EnergyPort()
            {
                CurrentIOMode = IOMode.Input
            };
            var packet = new Packet(1);

            // when: receiving data
            var result = ep.Receive(packet);

            // then:
            // data in the receive buffer
            Assert.That(ep.ReceiveBuffer, Is.SameAs(packet));
            // returned true
            Assert.That(result, Is.True);
        }
        public void CollectReceiveBuffer()
        {
            // given: EnergyPort with Packet
            var ep = new EnergyPort()
            {
                CurrentIOMode = IOMode.Input
            };
            var packet = new Packet(1);

            ep.Receive(packet);

            // when: collecting the receive buffer
            var receivedObject = ep.CollectReceivedData();

            // then:
            // object received
            Assert.That(receivedObject, Is.SameAs(packet));
            // buffer empty
            Assert.That(ep.ReceiveBuffer, Is.Null);
        }
        public void ReceiveDenyTest()
        {
            // given: EnergyPort with data in the receive buffer
            var ep = new EnergyPort
            {
                CurrentIOMode      = IOMode.Input,
                CurrentReceiveMode = EnergyPort.ReceiveMode.Deny
            };
            var packet1 = new Packet(1);

            ep.Receive(packet1);
            var packet2 = new Packet(2);

            // when: receiving the second packet
            var result = ep.Receive(packet2);

            // then:
            // ReceiveBuffer did not change
            Assert.That(ep.ReceiveBuffer, Is.EqualTo(packet1));
            // returned false
            Assert.That(result, Is.False);
        }
        public void ReceiveOverwriteTest()
        {
            // given: EnergyPort with data in the receive buffer
            var ep = new EnergyPort
            {
                CurrentIOMode      = IOMode.Input,
                CurrentReceiveMode = EnergyPort.ReceiveMode.Overwrite
            };
            var packet1 = new Packet(1);

            ep.Receive(packet1);
            var packet2 = new Packet(2);

            // when: receiving the second packet
            var result = ep.Receive(packet2);

            // then:
            // first packet overwritten
            Assert.That(ep.ReceiveBuffer, Is.SameAs(packet2));
            // returned true
            Assert.That(result, Is.True);
        }
        public void SendTest()
        {
            // given: Connected EnergyPorts
            var ep1 = new EnergyPort()
            {
                CurrentIOMode = IOMode.Output
            };
            var ep2 = new EnergyPort()
            {
                CurrentIOMode = IOMode.Input
            };
            var packet = new Packet(1);

            ep1.ConnectToPort(ep2);

            // when: ep1 sends to ep2
            var result = ep1.Send(packet);

            // then:
            // data was sent
            Assert.That(ep2.ReceiveBuffer, Is.SameAs(packet));
            // returned true
            Assert.That(result, Is.True);
        }