public void SerializeTest()
        {
            using (ConnectionMock connection = new ConnectionMock())
            {
                ArrayList calls  = new ArrayList();
                ArrayList buffer = new ArrayList();
                connection.SetFormatterFactory(new ArrayListFormatterFactoryMock(buffer));

                const string commandinfoSerializeIsCalled = "commandInfo Serialize is called";
                MCommandInfo commandInfo = new MCommandInfo
                {
                    SerializeIBinaryWriter = (writer) => calls.Add(commandinfoSerializeIsCalled)
                };

                var target = CreateCommandWithResultBase(connection);
                target.CommandInfoGet = () => commandInfo;
                const string serializeRequestIsCalled = "SerializeRequest is called";
                target.SerializeRequestIBinaryWriter = (writer) => calls.Add(serializeRequestIsCalled);
                var          accessor           = GetCommandAccessor(target);
                const string writebytesIsCalled = "WriteBytes is called";
                var          streamAdapter      = new SStreamAdapter(new MemoryStream())
                {
                    WriteBytesByteArrayInt32 = (array, len) => calls.Add(writebytesIsCalled)
                };

                accessor.Serialize(streamAdapter);

                CollectionAssert.AreEqual(buffer, new int[] { 0 });
                CollectionAssert.AreEqual(calls, new [] { commandinfoSerializeIsCalled, serializeRequestIsCalled, writebytesIsCalled });
            }
        }
        public void DeserializeTest()
        {
            using (ConnectionMock connection = new ConnectionMock())
            {
                ArrayList calls  = new ArrayList();
                ArrayList buffer = new ArrayList();
                connection.SetFormatterFactory(new ArrayListFormatterFactoryMock(buffer));
                const CommandStatus expectedStatus = CommandStatus.Ok;
                buffer.Add((short)expectedStatus);
                const short expectedCommandVersion = 1;
                buffer.Add(expectedCommandVersion);
                const int expectedLength = 1;
                buffer.Add(expectedLength);
                buffer.Add(1);                 // body stub

                var          target = CreateCommandWithResultBase(connection);
                const string validateResponseIsCalled = "ValidateResponse is called";
                target.ValidateResponseIBinaryReaderInt16 = (bodyReader, serverCommandVersion) =>
                {
                    if (serverCommandVersion == expectedCommandVersion)
                    {
                        calls.Add(validateResponseIsCalled);
                    }
                };
                const string deserializeResponseIsCalled = "DeserializeResponse is called";
                target.DeserializeResponseIBinaryReader = (bodyReader) =>
                {
                    calls.Add(deserializeResponseIsCalled);
                };
                const string streamAdapterReadBytesIsCalled = "ReadBytes is called";
                var          streamAdapter = new SStreamAdapter(new MemoryStream())
                {
                    ReadBytesByteArrayInt32 = (array, len) =>
                    {
                        if (len == expectedLength)
                        {
                            calls.Add(streamAdapterReadBytesIsCalled);
                        }
                        return(len);
                    }
                };
                var accessor = GetCommandAccessor(target);
                accessor.Result = new CommandResultBaseMock();

                accessor.Deserialize(streamAdapter);

                Assert.AreEqual(expectedStatus, target.Result.Status);
                CollectionAssert.AreEqual(calls, new[] { streamAdapterReadBytesIsCalled, validateResponseIsCalled, deserializeResponseIsCalled });
            }
        }