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

如何模擬 Elmah 的 ErrorSignal 例程?

How can I mock Elmah#39;s ErrorSignal routine?(如何模擬 Elmah 的 ErrorSignal 例程?)
本文介紹了如何模擬 Elmah 的 ErrorSignal 例程?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我們使用 ELMAH 來處理我們的 ASP.Net MVC c# 應用程序中的錯誤,并且在我們捕獲的異常中,我們正在做這樣的事情:

We're using ELMAH for handling errors in our ASP.Net MVC c# application and in our caught exceptions, we're doing something like this:

ErrorSignal.FromCurrentContext().Raise(exception);

但是當我嘗試對捕獲的異常進行單元測試時,我收到以下消息:

but when I try to unit test the caught exceptions, I get this message:

System.ArgumentNullException: Value cannot be null.
Parameter name: context

如何模擬 FromCurrentContext() 調用?有什么我應該做的嗎?

How can I mock the FromCurrentContext() call? Is there something else I should be doing instead?

僅供參考...我們目前正在使用 Moq 和 RhinoMocks.

FYI... We're currently using Moq and RhinoMocks.

謝謝!

推薦答案

由于 FromCurrentContext() 方法是一個靜態方法,你不能簡單地模擬對它的調用.你還有另外兩個選擇.

Since the FromCurrentContext() method is a static method you can't simply mock the call to it. You do have two other options.

  1. 由于 FromCurrentContext() 在內部調用 HttpContext.Current 您可以在其中推送一個假上下文.例如:

  1. Since FromCurrentContext() internally makes a call to HttpContext.Current you can push a fake context in that. For example:

SimpleWorkerRequest request = new SimpleWorkerRequest(
    "/blah", @"c:inetpubwwwrootlah", "blah.html", null, new StringWriter());

HttpContext.Current= new HttpContext(request);

有了這個,它不應該再拋出異常,因為 HttpContext.Current 不為空.

With this it should not throw the exception anymore since HttpContext.Current is not null.

圍繞對 Raise 的調用創建一個封裝類,然后模擬出封裝類.

Create a wrapper class around the call to Raise and just mock out the wrapper class.

public class ErrorSignaler {

    public virtual void SignalFromCurrentContext(Exception e) {
        if (HttpContext.Current != null)
            Elmah.ErrorSignal.FromCurrentContext().Raise(e);
    } 
}

這篇關于如何模擬 Elmah 的 ErrorSignal 例程?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 亚洲精品1区 | 呦呦在线视频 | 国产亚洲人成a在线v网站 | 国产成人久久精品一区二区三区 | 久久亚洲国产精品 | 男女视频在线观看网站 | 天天干天天谢 | 国产成人精品一区二区三区网站观看 | 久久久久久国产免费视网址 | 在线高清免费观看视频 | 日本在线一二 | 日韩av成人在线 | 午夜欧美 | 国产视频1区2区 | 一区二区成人 | 一区二区三区四区在线免费观看 | 蜜桃视频在线观看www社区 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 特黄特色大片免费视频观看 | 国产乱码精品1区2区3区 | 免费av一区二区三区 | 久久久99精品免费观看 | 日日夜夜操天天干 | 成人欧美日韩一区二区三区 | 亚洲精品中文字幕在线 | 自拍 亚洲 欧美 老师 丝袜 | 国产视频二区在线观看 | 色婷婷av99xx | 精品一区二区三区在线观看国产 | 日本一区二区三区四区 | 久久久九九 | 伊人网在线播放 | 久久久久成人精品 | 一级黄色片免费 | 天天色天天色 | 免费在线观看成人 | 国产精品成人在线 | 欧美亚洲国产日韩 | 亚洲视频一区二区三区 | 亚洲一区二区免费电影 | 久久久久久网站 |