public virtual void PerformCommandTest() { PersistentTcpConnection conn = CreateConnection("test"); try { PersistentTcpConnection_Accessor accessor = GetConnectionAccessor(conn); // assign mock socket accessor.Socket = new ClientSocketMock(); accessor.Socket.Open(); XmlFormatterFactoryMock factory = new XmlFormatterFactoryMock(); accessor.FormatterFactory = factory; IBinaryWriter writer = factory.CreateWriter(accessor.DataStream); // command id and version const ServerCommand id = ServerCommand.Status; const short ver = 1; MockCommand command = new MockCommand(conn, id, ver); accessor.PerformCommand(command); StreamAdapter_Accessor streamAccessor = GetStreamAccessor((StreamAdapter)accessor.DataStream); streamAccessor.Stream.Seek(0, SeekOrigin.Begin); IBinaryReader reader = factory.CreateReader(accessor.DataStream); // read & check data sent by mock command code ServerCommand actualId = (ServerCommand)reader.ReadInt16(); Assert.AreEqual(id, actualId); short actualVer = reader.ReadInt16(); Assert.AreEqual(ver, actualVer); } finally { conn.Close(); } }
public virtual void PerformCommandTest() { ConnectionBase conn = CreateConnection("test"); try { TcpConnection_Accessor accessor = GetConnectionAccessor(conn); // assign mock socket accessor.Socket = new ClientSocketMock(); accessor.Socket.Open(); XmlFormatterFactoryMock factory = new XmlFormatterFactoryMock(); accessor.FormatterFactory = factory; IBinaryWriter writer = factory.CreateWriter(accessor.DataStream); // preserialize server protocol version and rewind to start pos. (emulate first stage of handshake procedure) int protocolVersion = TcpConnection_Accessor.MAJOR_PROTOCOL_VERSION; writer.Write(protocolVersion); StreamAdapter_Accessor streamAccessor = GetStreamAccessor((StreamAdapter)accessor.DataStream); long pos = streamAccessor.Stream.Position; streamAccessor.Stream.Seek(0, SeekOrigin.Begin); // command id and version const ServerCommand id = ServerCommand.Status; const short ver = 1; MockCommand command = new MockCommand(conn, id, ver); accessor.PerformCommand(command); accessor.Socket.Open(); streamAccessor.Stream.Seek(pos, SeekOrigin.Begin); IBinaryReader reader = factory.CreateReader(accessor.DataStream); // skip protocol version sent by hadshake method int clientProtocol = reader.ReadInt32(); // read & check data sent by mock command code ServerCommand actualId = (ServerCommand)reader.ReadInt16(); Assert.AreEqual(id, actualId); short actualVer = reader.ReadInt16(); Assert.AreEqual(ver, actualVer); } finally { conn.Close(); } }