我正在尝试模拟对索引属性的调用.IE.我想要起订量以下:
I am attempting to mock a call to an indexed property. I.e. I would like to moq the following:
object result = myDictionaryCollection["SomeKeyValue"];
还有setter值
myDictionaryCollection["SomeKeyValue"] = myNewValue;
我这样做是因为我需要模拟我的应用使用的类的功能.
I am doing this because I need to mock the functionality of a class my app uses.
有人知道如何使用最小起订量来做到这一点吗?我尝试了以下变体:
Does anyone know how to do this with MOQ? I've tried variations on the following:
Dictionary<string, object> MyContainer = new Dictionary<string, object>();
mock.ExpectGet<object>( p => p[It.IsAny<string>()]).Returns(MyContainer[(string s)]);
但这不会编译.
我想通过 MOQ 实现的目标是否可行,有没有人可以举例说明我如何做到这一点?
Is what I am trying to achieve possible with MOQ, does anyone have any examples of how I can do this?
看来我试图用 MOQ 做的事情是不可能的.
It appears that what I was attempting to do with MOQ is not possible.
基本上我是在尝试最小化一个 HTTPSession 类型的对象,其中被设置为索引的项的键只能在运行时确定.访问索引属性需要返回先前设置的值.这适用于基于整数的索引,但基于字符串的索引不起作用.
Essentially I was attempting to MOQ a HTTPSession type object, where the key of the item being set to the index could only be determined at runtime. Access to the indexed property needed to return the value which was previously set. This works for integer based indexes, but string based indexes do not work.
这篇关于如何最小起订量索引属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并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 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超
使用电子邮件地址和应用程序密码从 oauth2/tokenGetting access token using email address and app password from oauth2/token(使用电子邮件地址和应用程序密码从 oauth2/token 获取访问令
新的 Azure AD 应用程序在通过管理门户更新之前无New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 应用程序在通过管理门户更新之前无法运行