public void CheckAcknowledgeCommand2Test()
 {
     Mock privateTarget = new Mock<BaseSimulatorPlcCommunication>();
     BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));
     Assert.AreEqual<bool>(false, target.CheckAcknowledgeCommand("\u010600FF"));
 }
 public void CheckReadWriteCommand5Test()
 {
     Mock privateTarget = new Mock<BaseSimulatorPlcCommunication>();
     BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));
     Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.Msg>(BaseSimulatorPlcCommunication_Accessor.Msg.ProtocolError, target.CheckReadWriteCommand("\u000100FFCR00012001" + target.CalculateCheckSum("00FFCR00012001")));
 }
        public void ProcessReadWriteCommandThrowsNotImplementedExceptionTest()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            // calling read before write
            target.Open();
            target.Read();
        }
 public void CharactersCheck2Test()
 {
     Mock privateTarget = new Mock<BaseSimulatorPlcCommunication>();
     BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));
     Assert.AreEqual<bool>(false, target.CharactersCheck("a0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_\u0000\u0002\u0003\u0004\u0005\u0006\u000A\u000C\u000D\u0015"));
 }
        public void ProcessReadWriteCommand3Test()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            // invalid command
            target.Open();
            target.Write("\u000500FFXX00012002ABCD1234F5");

            privateTarget.Verify(x => x.ErrorMethod(), Times.Exactly(1));
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.CW, target._machineState);
            Assert.AreEqual<string>("\u001500FF06", target.Read());
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.READY, target._machineState);
        }
        public void ProcessReadWriteCommand4Test()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            int errorCode = 0;
            privateTarget.Setup<bool>(x => x.CheckForErrorReadCommand(It.IsAny<string>(), out errorCode)).Returns(true);

            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            // calling 2x write
            target.Open();
            target.Write("\u000500FFCR0001200509");
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.CR, target._machineState);

            target.Write("\u000500FFCR0001200509");
            privateTarget.Verify(x => x.ErrorMethod(), Times.Exactly(1));
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.READY, target._machineState);
        }
        public void ProcessReadWriteCommand1Test()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            int errorCode = 0;
            privateTarget.Setup<bool>(x => x.CheckForErrorReadCommand(It.IsAny<string>(), out errorCode)).Returns(true);
            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            target._memory._memory[0x5] = 0xABCD;
            target._memory._memory[0x6] = 0x1234;

            target.Open();
            target.Write("\u000500FFCR0000050208");
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.CR, target._machineState);
            Assert.AreEqual<string>("ABCD1234", PlcMemoryReadData.Create(target.Read()).Data);
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.ACK, target._machineState);
            target.Write("\u000600FF");
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.READY, target._machineState);
        }
        public void ProcessReadWriteCommand2Test()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            int errorCode = 0;
            privateTarget.Setup<bool>(x => x.CheckForErrorWriteCommand(It.IsAny<string>(), out errorCode)).Returns(true);

            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            target.Open();
            target.Write("\u000500FFCW00012002ABCD1234DF");
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.CW, target._machineState);
            Assert.AreEqual<string>(new PlcMemoryAcknowledge().CommandToString(), target.Read());
            Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.READY, target._machineState);
        }
        public void ParseWriteCommand2Test()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            int errorCode = 0;
            privateTarget.Setup<bool>(x => x.CheckForErrorWriteCommand(It.IsAny<string>(), out errorCode)).Returns(true);

            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            Assert.AreEqual<string>("\u000600FF", target.ParseWriteCommand("\u000500FFCW00003F015678FA"));
            Assert.AreEqual<ushort>(0x5678, target._memory._memory[63]);
        }
 public void CalculateCheckSumTest()
 {
     Mock privateTarget = new Mock<BaseSimulatorPlcCommunication>();
     BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));
     Assert.AreEqual<string>("10", target.CalculateCheckSum("00FFABCDEFGH"));
 }
        public void ParseReadCommand2Test()
        {
            Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            int errorCode = 0;
            privateTarget.Setup<bool>(x => x.CheckForErrorReadCommand(It.IsAny<string>(), out errorCode)).Returns(true);
            privateTarget.Setup<bool>(x => x.CheckForErrorWriteCommand(It.IsAny<string>(), out errorCode)).Returns(true);

            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            Assert.AreEqual<string>("\u000600FF", target.ParseWriteCommand("\u000500FFCW00002302ABCD1234E1"));
            Assert.AreEqual<ushort>(0xABCD, target._memory._memory[35]);
            Assert.AreEqual<ushort>(0x1234, target._memory._memory[36]);
            Assert.AreEqual<string>("\u000200FFABCD1234\u0003C3", target.ParseReadCommand("\u000500FFCR0000230208"));
        }
        public void IsMyMessage3Test()
        {
            Mock privateTarget = new Mock<BaseSimulatorPlcCommunication>();
            BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));

            Assert.AreEqual<bool>(false, target.IsMyMessage("\u000500FECR00012001"));
        }
 public void CtorTest()
 {
     Mock<BaseSimulatorPlcCommunication> privateTarget = new Mock<BaseSimulatorPlcCommunication>();
     BaseSimulatorPlcCommunication_Accessor target = new BaseSimulatorPlcCommunication_Accessor(new PrivateObject(privateTarget.Object, new PrivateType(typeof(BaseSimulatorPlcCommunication))));
     Assert.AreEqual<BaseSimulatorPlcCommunication_Accessor.State>(BaseSimulatorPlcCommunication_Accessor.State.READY, target._machineState);
 }