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

Rhino Mocks - 通過(guò)多次調(diào)用模擬其返回值更改(即使

Rhino Mocks - mocking a method whose return value changes (even when passed the same parameter) with multiple calls(Rhino Mocks - 通過(guò)多次調(diào)用模擬其返回值更改(即使傳遞相同的參數(shù))的方法) - IT屋-程序員軟件開發(fā)技
本文介紹了Rhino Mocks - 通過(guò)多次調(diào)用模擬其返回值更改(即使傳遞相同的參數(shù))的方法的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

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

我正在尋找如何模擬一個(gè)在第二次調(diào)用它時(shí)返回不同值的方法.例如,像這樣:

I'm looking to find out how I can mock a method that returns a different value the second time it is called to the first time. For example, something like this:

public interface IApplicationLifetime
{
    int SecondsSinceStarted {get;}
}

[Test]
public void Expected_mock_behaviour()
{
    IApplicationLifetime mock = MockRepository.GenerateMock<IApplicationLifetime>();

    mock.Expect(m=>m.SecondsSinceStarted).Return(1).Repeat.Once();
    mock.Expect(m=>m.SecondsSinceStarted).Return(2).Repeat.Once();

    Assert.AreEqual(1, mock.SecondsSinceStarted);
    Assert.AreEqual(2, mock.SecondsSinceStarted);
}

有什么可以讓這成為可能嗎?除了為實(shí)現(xiàn)狀態(tài)機(jī)的 getter 實(shí)現(xiàn) sub 之外?

Is there anything that makes this possible? Besides implementing a sub for the getter that implements a state machine?

推薦答案

您可以使用 .WhenCalled 方法截取返回值.請(qǐng)注意,您仍然需要通過(guò) .Return 方法提供一個(gè)值,但是如果 ReturnValue 從方法調(diào)用中被更改,Rhino 將忽略它:

You can intercept return values with the .WhenCalled method. Note that you still need to provide a value via the .Return method, however Rhino will simply ignore it if ReturnValue is altered from the method invocation:

int invocationsCounter = 1;
const int IgnoredReturnValue = 10;
mock.Expect(m => m.SecondsSinceLifetime)
    .WhenCalled(mi => mi.ReturnValue = invocationsCounter++)
    .Return(IgnoredReturnValue);

Assert.That(mock.SecondsSinceLifetime, Is.EqualTo(1));
Assert.That(mock.SecondsSinceLifetime, Is.EqualTo(2));


再深入研究一下,似乎 .Repeat.Once() 確實(shí) 在這種情況下確實(shí)有效,并且可以用于實(shí)現(xiàn)相同的結(jié)果:


Digging around a bit more, it seems that .Repeat.Once() does indeed work in this case and can be used to achieve the same result:

mock.Expect(m => m.SecondsSinceStarted).Return(1).Repeat.Once();
mock.Expect(m => m.SecondsSinceStarted).Return(2).Repeat.Once();
mock.Expect(m => m.SecondsSinceStarted).Return(3).Repeat.Once();

將在連續(xù)調(diào)用時(shí)返回 1、2、3.

Will return 1, 2, 3 on consecutive calls.

這篇關(guān)于Rhino Mocks - 通過(guò)多次調(diào)用模擬其返回值更改(即使傳遞相同的參數(shù))的方法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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 訪問(wèn)令牌和刷新令牌) - 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 獲取訪問(wèn)令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應(yīng)用程序在通過(guò)管理門戶更新之前無(wú)法運(yùn)行)
主站蜘蛛池模板: 韩日一区 | 国产激情| 91精品国产综合久久国产大片 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 国产精品欧美一区二区三区不卡 | 99久久精品国产麻豆演员表 | 欧美激情视频一区二区三区在线播放 | 少妇黄色 | 久久久久久久久毛片 | 欧美日本一区 | 亚洲国产免费 | 男人的天堂久久 | 精品国产乱码一区二区三区 | 成年人在线观看视频 | 久久无毛 | 中文字幕亚洲欧美 | 久久久久久国产精品 | 成人久久 | 天堂久| 日韩毛片免费视频 | 日韩一区二区福利 | 91视视频在线观看入口直接观看 | 国产精品美女久久久久久久久久久 | 国产农村一级片 | av一级久久| 91免费在线看 | 久久伦理中文字幕 | 欧洲精品久久久久毛片完整版 | 国产精品精品视频一区二区三区 | 国产一级特黄aaa大片评分 | 久久性av| 久久天堂 | 91亚洲国产 | 色资源在线观看 | 亚洲精品久久嫩草网站秘色 | 国产精品日韩欧美一区二区三区 | 日本不卡一区 | 国产电影精品久久 | 国产精品一区在线观看你懂的 | jlzzjlzz国产精品久久 | 老司机久久 |