Exemplo n.º 1
0
        public void BasicCommandBufferTest()
        {
            var payload = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05};

            var commandStore = new byte[] {(byte) MessageIdentifier.Echo, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
            var responseStore = new byte[] {(byte) MessageIdentifier.Echo, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};

            var command = new EchoCommand {PayLoad = payload};
            byte[] store = command.Store;
            Assert.IsTrue(BufferCompare(store, commandStore), "EchoCommand.Execute() creates invalid store.");

            EchoResponse response = command.CreateResponse(responseStore);
            Assert.IsNotNull(response, "EchoCommand.CreateResponse() did not create a response.");
            Assert.IsInstanceOfType(response, typeof (EchoResponse),
                "EchoCommand.CreateResponse() did not create a response of type EchoResponse.");
            Assert.IsTrue(BufferCompare(response.Payload, payload), "EchoResponse.Payload doesn't match payload.");
        }
        public void BasicCommandTest()
        {
            var payload = new byte[] {0x01, 0x02, 0x03, 0x04};

            var command = new EchoCommand { Payload = payload};

            var idBytes= BitConverter.GetBytes((ushort) new Identifier(MessageIdentifier.Echo, MessageType.ResponseType));

            var responseStore = new byte[idBytes.Length + payload.Length];
            System.Buffer.BlockCopy(idBytes, 0, responseStore, 0, idBytes.Length);
            System.Buffer.BlockCopy(payload, 0, responseStore, idBytes.Length, payload.Length);

            var response = command.CreateResponse();

            Assert.IsNotNull(response);

            response.SetStore(responseStore);

            Assert.IsTrue(response.Key.IsMatch(responseStore));
            Assert.IsInstanceOfType(response, typeof(EchoResponse));
            Assert.IsTrue(BufferCompare(response.Payload, payload));
        }