我有一个Web服务,我正在尝试进行单元测试.在服务中,它从HttpContext类似物中提取了几个值,因此:
m_password = (string)HttpContext.Current.Session["CustomerId"];
m_userID = (string)HttpContext.Current.Session["CustomerUrl"];
Run Code Online (Sandbox Code Playgroud)
在单元测试中,我使用简单的工作者请求创建上下文,如下所示:
SimpleWorkerRequest request = new SimpleWorkerRequest("", "", "", null, new StringWriter());
HttpContext context = new HttpContext(request);
HttpContext.Current = context;
Run Code Online (Sandbox Code Playgroud)
但是,每当我尝试设置值时 HttpContext.Current.Session
HttpContext.Current.Session["CustomerId"] = "customer1";
HttpContext.Current.Session["CustomerUrl"] = "customer1Url";
Run Code Online (Sandbox Code Playgroud)
我得到null引用异常,表示HttpContext.Current.Session为null.
有没有办法在单元测试中初始化当前会话?
我正在编写一个程序,通过TCP与一个设备的管理界面进行交互.问题是,设备的文档是用C语言编写的,而我写的程序是用C#编写的.我的问题是,文档指定
通信基于基于C结构的API缓冲区
没有任何谷歌搜索可以指向我这个API或我如何通过TCP发送原始结构.文档似乎暗示我应该使用memcpy将结构复制到TCP缓冲区,但C#不直接支持memcpy.在C#中是否存在等效方法或以不同方式实现此目的