public void SocketState_GetMessageBuffer() { // create a socket using to pass to a SocketState object Network.MakeSocket("localhost", out Socket sock, out IPAddress address); try { SocketState state = new SocketState(sock, -1); //the size of the buffer should be 1024 byte[] buffer = state.GetMessageBuffer(); Assert.AreEqual(1024, buffer.Length); // the message buffer should be filled with 0's byte zeroByte = 0x0; for (int i = 0; i < buffer.Length; i++) { Assert.IsTrue(buffer[i] == zeroByte); } } // make sure we close the socket when we are done testing our state finally { sock.Dispose(); } }
public void SocketState_ConstructorTest() { // create a socket using to pass to a SocketState object Network.MakeSocket("localhost", out Socket sock, out IPAddress address); try { SocketState state = new SocketState(sock, -1); //the state should not be reporting an error Assert.IsFalse(state.HasError); // there error messgae should be an empty string Assert.IsTrue(state.ErrorMessage == ""); //the size of the buffer should be 1024 byte[] buffer = state.GetMessageBuffer(); Assert.AreEqual(1024, buffer.Length); // the message buffer should be filled with 0's byte zeroByte = 0x0; for (int i = 0; i < buffer.Length; i++) { Assert.IsTrue(buffer[i] == zeroByte); } // growable string builder which represents the message sent by server // should not contain anything. StringBuilder sb = state.GetStringBuilder(); Assert.IsTrue(sb.ToString() == ""); Assert.AreEqual(0, sb.Length); // the socket returned by GetSocket should be the same instance as // passed to the constructor Assert.AreEqual(sock, state.GetSocket()); // We have not set a network action, but it should still not be null // trying to invoke this action would be bad if it was null and cause // test to fail state.InvokeNetworkAction(state); // ID should be same as what it was set Assert.AreEqual(-1, state.GetID()); } // make sure we close the socket when we are done testing our state finally { sock.Dispose(); } }