c# unit tests using sockets -
I am trying to write a unit test for a server application which requires sockets in C # . To process the request, I need to read from the socket. I can avoid sockets in Java using currents, so when writing a unit test, I can easily convert a string into a stream.
// ====== input ====== InputStream socket InputStream = new input stream (socket.getInputStream ()); // InputStream socket input instead of such a string = new bytereinputstream ("string" .getBytes ()); BufferedReader = new BufferedReader (new InputStreamReader (socketInputStream)); // ====== Output ====== OutputStream socketOptputTream = New outputstream (socket. Getoutputstream ()); // I need to write stream BufferedOutputStream Out = new BufferedOutputStream (socketOutputStream) byte []; I just found NetworkStream () but it also requires a socket.
How can I get it in C # so that I can make the stream without sockets? And how can I write a stream and read it again to see if the message is correct?
[Nkvu - in response to the comments based on the poster's question against comments and comments is; @Andree's thunder is not trying to steal]
Then you are doing in Java:
InputStream socketInputStream = new byteArrayInputStream ("string" .getBytes ()); In your unit tests (I'm assuming, based on your basic question)
You can do this in C #:
Stream Socket InputStream = New MemoryStream (encoding.UTF 8.Getbates ("string")); It will be worth noting that I have not created the real world for a while. A C # -Secimal equivalent Since MemoryStream is just a sub-class of you, Normal stream methods can be used to read (like, read)
You can also write memorystream, eg:
bytes [] towrite = Encoding.UTF8.GetBytes ("Write On Stream"); Stream writestream = new memorystream (); WriteToStream.Write (towrite, 0, towrite.Length); HH, Nathan
Comments
Post a Comment