异步服务器套接字系统的单元测试或模拟 [英] Unit Testing or Mocking of Asynchronous Server Socket System

查看:65
本文介绍了异步服务器套接字系统的单元测试或模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public
静态 void
AcceptCallback
< span style ="color:#fafcfe; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans -serif; font-size:14px; white-space:pre; background-color:#222324">( IAsyncResult
ar
{
//发出主线程信号继续。
allDone.Set();
//获取处理客户端
请求的套接字。
Socket
listener =(Socket)ar.AsyncState; Socket handler = listener.EndAccept(ar);

//创建状态对象。
StateObject
state =
new
StateObject(); state.workSocket = handler; handler.BeginReceive(state.buffer,

0
StateObject.BufferSize,
0
new
AsyncCallback(ReadCallback),state);}

public static void AcceptCallback(IAsyncResult ar){ // Signal the main thread to continue. allDone.Set(); // Get the socket that handles the client request. Socket listener = (Socket) ar.AsyncState; Socket handler = listener.EndAccept(ar); // Create the state object. StateObject state = new StateObject(); state.workSocket = handler; handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state); }

怎么做上面给出的代码的模拟或单元测试,因为它取决于
IAsyncResult 界面。

How to do the mocking or the unit testing of the above given code, as it depends on IAsyncResult interface.

请帮助。 

Please help. 

推荐答案

Hi Kapil13,

欢迎来到MSDN论坛。

根据您提供的代码,我认为关键点不在
以上
IAsyncResult ,需要做
的模型
套接字。 请看一下这个帖子可能有帮助对你而言。

https://social.msdn.microsoft.com/Forums/azure/en-US/76c8fc15-0510-44b1-a64f-245776bcf48c/how-to-write-a-unit-test-to -mock-socket-communication-server-and-client?forum = csharpgeneral

问候,

Judyzh


这篇关于异步服务器套接字系统的单元测试或模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆