久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

有沒有人成功地模擬過 .NET 中的 Socket 類?

Has anyone successfully mocked the Socket class in .NET?(有沒有人成功地模擬過 .NET 中的 Socket 類?)
本文介紹了有沒有人成功地模擬過 .NET 中的 Socket 類?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我正在嘗試在 C# 中模擬 System.net.Sockets.Socket 類 - 我嘗試使用 NUnit 模擬,但它無法模擬具體類.我也嘗試使用 Rhino Mocks,但它似乎使用了該類的真實(shí)版本,因?yàn)樗谡{(diào)用 Send(byte[]) 時(shí)拋出了 SocketException.是否有人使用任何模擬框架成功創(chuàng)建并使用了 Socket 模擬?

I'm trying to mock out the System.net.Sockets.Socket class in C# - I tried using NUnit mocks but it can't mock concrete classes. I also tried using Rhino Mocks but it seemed to use a real version of the class because it threw a SocketException when Send(byte[]) was called. Has anyone successfully created and used a Socket mock using any mocking framework?

推薦答案

每當(dāng)我遇到 Moq 的這類問題時(shí),我最終都會(huì)創(chuàng)建一個(gè)接口來抽象出我無法模擬的東西.

Whenever I run into these kinds of problems with Moq I end up creating an interface to abstract away the thing I can't mock.

因此,在您的實(shí)例中,您可能有一個(gè)實(shí)現(xiàn) Send 方法的 ISocket 接口.然后讓你的模擬框架模擬它.

So in your instance you might have an ISocket interface that implements the Send method. Then have your mocking framework mock that instead.

在你的實(shí)際代碼中,你會(huì)有一個(gè)這樣的類

In your actual code, you'd have a class like this

public class MySocket : ISocket
{
  System.Net.Sockets.Socket _socket;

  public void MySocket(System.Net.Sockets.Socket theSocket)
  {
    _socket = theSocket;
  }

  public virtual void Send(byte[] stuffToSend)
  {
    _socket.Send(stuffToSend);
  }

}

不確定這是否滿足您的需求,但這是一種選擇.

Not sure if that meets your needs, but it's an option.

這篇關(guān)于有沒有人成功地模擬過 .NET 中的 Socket 類?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請(qǐng)求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應(yīng)用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應(yīng)用程序在通過管理門戶更新之前無法運(yùn)行)
主站蜘蛛池模板: 国产aaaaav久久久一区二区 | 成人在线视频一区 | 欧美精品一区二区三区在线播放 | 成人免费在线视频 | 国产午夜精品一区二区三区 | 一级视频黄色 | 国产日韩欧美精品 | 精品免费国产一区二区三区 | 亚洲欧美男人天堂 | 亚洲精品一区二区三区 | 羞羞视频在线观看免费观看 | 国产精品欧美一区二区三区不卡 | 日日草夜夜草 | 亚洲香蕉在线视频 | 免费视频一区二区 | 午夜影院在线播放 | av毛片在线播放 | 在线精品国产 | 日韩一级在线 | 国产精品99久久久久久动医院 | 精品国产乱码久久久久久1区2区 | 一区二区免费高清视频 | 国产精品成av人在线视午夜片 | 欧美日韩亚洲三区 | 欧美一区二区三区一在线观看 | 欧美操操操 | 免费在线a视频 | 不卡的av电影 | 自拍偷拍精品 | 久久久影院 | 二区视频| 五月天天丁香婷婷在线中 | 亚洲免费在线 | 欧美11一13sex性hd | 99久久久99久久国产片鸭王 | 亚洲精品91 | 国产精品美女久久久久aⅴ国产馆 | 国产美女精品视频 | 国产一二区在线 | 国产一区二区三区久久久久久久久 | 欧美日韩黄色一级片 |