我有一个api服务,调用另一个API服务.当我设置Mock对象时,它失败并出现错误:
NotSupportedException:expression引用不属于模拟对象的方法.
这是代码:
private Mock<IEnumerable<ICarrierApiService<AccountSearchModel>>> _mockCarrierService;
private Mock<IApiService<AccountSearchModel>> _mockApiService;
[SetUp]
public void SetUp()
{
_mockApiService = new Mock<IApiService<AccountSearchModel>>();
_mockCarrierService = new Mock<IEnumerable<ICarrierApiService<AccountSearchModel>>>();
_mockApiService.Setup(x => x.GetFromApiWithQuery(It.IsAny<string>())).Returns(ApiValue());
// Error occurred when call _mockApiService.GetFromApiWithQuery() in .Select()
_mockCarrierService.Setup(x => x
.Select(s => s
.GetFromApiWithQuery(It.IsAny<string>())).ToList())
.Returns(new List<IQueryable<AccountSearchModel>> { ApiValue() });
}
Run Code Online (Sandbox Code Playgroud)
我用Moq阅读表达式测试,但它对我的情况不起作用.如果我删除它_mockCarrierService.Setup(),测试用例可以运行但是失败,NullReferenceException因为它没有有效的List<IQueryable<AccountSearchModel>>设置.
知道我怎么能做到这一点?
脚注:当前的解决方案
FWIW,这是我目前使用的解决方案.我很乐意更好地解决这个问题(直到Moq开始支持模拟扩展方法).
private List<ICarrierApiService<AccountSearchModel>> _mockCarrierService;
private AccountSearchController _mockController;
private Mock<ICarrierApiService<AccountSearchModel>> _mockApiService;
[SetUp]
public void SetUp()
{
_mockApiService = …Run Code Online (Sandbox Code Playgroud) 我一直在使用DotNetOpenAuth工作.首先我们使用5.0.0-alpha1,但我们切换到v4.0.30319,因为我们找不到导致我们问题的原因.
我们在Visual Studio 2013的.NET 4.5.1建立一个C#的Web API项目RC与MVC 5 RC我们已经实施了IAuthorizationServerHost,INonceStore和ICryptoKeyStore.
我们遇到的问题是以下情况:
public class TokensController : Controller
{
private readonly AuthorizationServer authorizationServer = new AuthorizationServer(new MyAuthorizationServer());
/// <summary>
/// This action will handle all token requests.
/// </summary>
/// <returns>The action result that will output the token response.</returns>
[HttpPost]
public ActionResult Index()
{
var outgoingWebResponse = this.authorizationServer.HandleTokenRequest(this.Request);
return outgoingWebResponse.AsActionResult();
}
}
Run Code Online (Sandbox Code Playgroud)
return outgoingWebResponse.AsActionResult();与起源的方法DotNetOpenAuth.Messaging和MessagingUtilities静态类.该DotNetOpenAuth.Core(包含此代码)引用MVC 4.0和HttpResponseMessageActionResult类从继承ActionResult.
这意味着当前版本的DotNetOpenAuth与MVC 5不兼容.编译并尝试运行它只会出现500个错误. …
我编写了一个PowerShell脚本来自动部署IIS网站,但是当我将参数传递给脚本时,我收到以下错误:
找不到驱动器.名为"IIS"的驱动器不存在.
我的脚本(iss_website_version_update.ps1)如下所示,但请注意它还没有完成:
param(
[array]$iishostlist=$(throw "Parameter missing: -name iishostlist"),
[array]$websiteName=$(throw "Parameter missing: -name websiteName")
)
For($i=0;$i -lt $iishostlist.Count; $i++){
For($j=0;$j -lt $websiteName.Count; $j++){
$start = get-date
$tempSession = new-pssession -ComputerName $($iishostlist[$i])
Invoke-Command -Session $tempSession -ScriptBlock {
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -command Import-Module WebAdministration;set-location IIS:\;(Stop-Website $($websiteName[$j]))
}
.......
Run Code Online (Sandbox Code Playgroud)
请让我知道为什么命令set-location IIS:\;中的子命令 Invoke-Command不被识别?
我在设置下拉列表的初始值时遇到了一个小问题.下面的代码是视图模型定义和初始化$(document).ready.我有一个名为sourceMaterialTypesa 的数组,selectedSourceMaterialType表示该数组的选定值.我正在使用(ASP.Net MVC)Model和ViewBag中的值初始化视图模型.
var viewModel = {
sourceMaterialTypes :
ko.observableArray(@Html.Raw(Json.Encode(ViewBag.SourceMaterialTypes))),
selectedSourceMaterialType :
ko.observable(@Html.Raw(Json.Encode(Model.SourceMaterialType))),
ingredientTypes :
ko.observableArray(@Html.Raw(Json.Encode(ViewBag.IngredientTypes))),
selectedIngredientType : ko.observable()
};
$(document).ready(function () {
ko.applyBindings(viewModel);
viewModel.selectedSourceMaterialType.subscribe(function(newSourceMaterialType) {
$.getJSON("/IngredientType/FindByMaterialType",
{ "id": newSourceMaterialType })
.success(function (data) {
viewModel.ingredientTypes($.parseJSON(data));
})
.error(function () { alert("error"); });
});
});
Run Code Online (Sandbox Code Playgroud)
以下是具有Knockout绑定定义的下拉列表(select)列表的定义.
<select id="SourceMaterialTypeId"
name="SourceMaterialTypeId"
data-bind="options: sourceMaterialTypes,
optionsText: 'Name',
optionsValue : 'Id',
value: selectedSourceMaterialType"></select>
Run Code Online (Sandbox Code Playgroud)
这一切都正常,除了源材料下拉列表中最初选择的值(selectedSourceMaterialType正确绑定所以当下拉选择更改其值正确更新时,它只是我遇到问题的初始选择),这始终是第一个sourceMaterialTypes我视图模型中数组中的项.
我希望最初选择的值是从(服务器端)模型初始化的值作为selectedSourceMaterialType视图模型属性的值.
我如何添加新行到Label的Text在设计时?Stack Overflow上有一些关于如何在代码隐藏中执行此操作的帖子,但似乎没有关于设计时间的帖子,似乎?
我正在使用highcharts.当我在我的系列中得到小数字时,y轴开始使用浮动数字.无论我的数据如何,我如何强制它只使用整数?
注意:我的最小设置为"4",因此即使有一个结果,y轴范围也将是0-4.
我的WCF serice似乎使用的是计算机名而不是域名.当我查看MyService.svc?wsdl链接时,它显示我的计算机名称.
我在哪里可以在web.config中添加我的域名?端点地址,基址还是身份?
注意:我正在使用SSL,所以必须这样做 https://www.example.com/myservice.svc
我一直在寻找但找不到相关文档applyBindings().第二个参数可以合法地包含哪些内容?它可以是一系列元素吗?它必须是一个单一元素吗?可以通过调用applyBindings两次将绑定应用于两个单独节点的子元素吗?
ko.applyBindings(myViewModel, div1);
ko.applyBindings(myViewModel, div2);
Run Code Online (Sandbox Code Playgroud) Get<T>(object id)和之间有什么区别Load<T>(object id)?文档几乎都是一样的.此外,如果重要,在什么情况下我应该使用一个而不是另一个?
我在某些测试中有属性,理想情况下我不想在每个构建上运行.我的大多数测试都是正常的单元测试,我确实希望它们在每个构建上运行.
那么:我如何按类别或项目类型排除测试?
例如,我想排除CodedUItests:
[CodedUITest]
public class SearchViewTests
Run Code Online (Sandbox Code Playgroud)
...或排除给定的测试TestCategory:
[TestMethod]
[TestCategory("Database Integration")]
public void ContactRepositoryGetByIdWithIdExpectCorrectContact()
Run Code Online (Sandbox Code Playgroud)
我特别希望排除编码的UI测试,因为它们会破坏我继续工作的能力,而所有其他测试都会在后台愉快地运行而不会打扰我.
最初这个问题是关于Visual Studio 2012的,所以我更喜欢那个版本以及更高版本的解决方案.
tdd unit-testing visual-studio coded-ui-tests visual-studio-2012
c# ×3
asp.net-mvc ×2
iis ×2
knockout.js ×2
unit-testing ×2
asp.net ×1
expression ×1
highcharts ×1
javascript ×1
label ×1
linq ×1
moq ×1
namespaces ×1
newline ×1
nhibernate ×1
oauth-2.0 ×1
powershell ×1
ssl ×1
tdd ×1
wcf ×1
web-services ×1
winforms ×1