想象这种情况:
在默认的MVC3项目中,在中创建一个新的复杂类型 AccountModels.cs
public class GlobalAccount
{
public GlobalAccount()
{
this.LogOn = new LogOnModel();
this.Register = new RegisterModel();
}
public LogOnModel LogOn { get; set; }
public RegisterModel Register { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在RegisterModel更改UserName为:
[Required]
[Remote("UserNameExists", "Validation", "", ErrorMessage = "Username is already taken.")]
[RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed.")]
[Display(Name = "Username (spaces will be stripped, must be at least 6 characters long)")]
public string UserName { get; set; }
Run Code Online (Sandbox Code Playgroud)
控制器中的 …
我有一个使用NUnit 3.4.1,NSubstitute 1.10.0和NCrunch 2.23.0.2的文本夹具
在任何时间点,该夹具中都有2次测试.每次更改内容时,哪个测试失败似乎都会有所不同.并非所有的测试最终都会失败一段时间,但大多数测试都会失败,并且问题始终是一条线上的NSubstitute异常:
// _clock is initialized as _clock = Substitute.For<IClock>();
// the dates in the Returns statement change on every test
_clock.Now.Returns(new DateTime(2015, 1, 1));
Run Code Online (Sandbox Code Playgroud)
我将NCrunch添加到这个组合中,因为所有测试似乎都通过了Resharper 2016测试运行器.大多.
我总是得到的例外是:
NSubstitute.Exceptions.UnexpectedArgumentMatcherException : Argument matchers
(Arg.Is, Arg.Any) should only be used in place of member arguments.
Do not use in a Returns() statement or anywhere else outside of a member call.
Run Code Online (Sandbox Code Playgroud)
这很清楚,除了在大多数测试中我不使用任何Arg.Is或Arg.Any.
这是IClock所有荣耀中的表面.Now是一个只有吸气剂的属性,但对于NSubstitute来说这应该不是问题,不是吗?
public interface IClock
{
DateTime Now { get; …Run Code Online (Sandbox Code Playgroud) 我需要插入不在db中的项目.所以我试图运行以下(这不起作用):
foreach(var rep in model.Reps.Where(x => x.Value !=
this.dictionaryItemRepository.List().Select(y => y.Value)))
Run Code Online (Sandbox Code Playgroud)
其中model.Reps是:
public ICollection<DictionaryItemBrand> Reps { get; set; }
Run Code Online (Sandbox Code Playgroud)
从模型绑定器返回
我正在尝试做一个foreach循环 - > 选择model.Reps中的所有项目,这些项目在存储库中尚不存在.
我该怎么做?谢谢
我有两个叫做"a"和"b"的动作.我也有两种观点.这些观点的布局是不同的.为一个:
@{
Layout = "~/Views/Shared/_X.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
对于b:
@{
Layout = "~/Views/Shared/_Y.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
错误视图也是共享的.
如何为Error视图使用动态布局.例如,当处理动作"a"时发生错误时,错误显示在动作"a"的布局中,如果在处理动作"b"时发生错误,则错误显示在动作"b"的布局中?
我有一个名为Infrastructure的类,我认为它可以很方便地继承HttpClient.这个类公开了get,post,put和delete的方法.
import {Aurelia} from "aurelia-framework";
import {HttpClient, json} from "aurelia-fetch-client";
export default class Infrastructure extends HttpClient {
get(url, queryString, contentType) {
//..
}
post(url, data, contentType) {
//..
}
put(url, data, contentType) {
//..
}
delete(url, contentType) {
//..
}
}
Run Code Online (Sandbox Code Playgroud)
我的想法是,我现在可以拥有注入的服务,Infrastructure他们可以调用configure基础设施
import {inject} from "aurelia-framework";
import Infrastructure from "./infrastructure";
@inject(Infrastructure)
export class InventoryService {
constructor (infrastructure) {
infrastructure.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl(`http://localhost:64441/inventory`);
});
this.infrastructure = infrastructure;
}
}
Run Code Online (Sandbox Code Playgroud)
我有几个使用Infrastructure这样的服务,一切正常.问题是我不需要将两个 …
javascript dependency-injection ecmascript-6 aurelia aurelia-http-client
我创建了一些返回整数的静态函数.在我看来,我想要这些功能的总和.我使用以下代码:
@myrepository.OverDraftCount() +
@myrepository.MortgageCount() +
@myrepository.InstallmentCount()+
@myrepository.RevolvingCount()+
@myrepository.OthersCount()
Run Code Online (Sandbox Code Playgroud)
但它返回2 + 2 + 2 + 2 + 2而不是10,它认为所有这些函数的输出都是字符串.我该怎么改变它?
谢谢
asp.net-mvc ×3
asp.net ×1
aurelia ×1
c# ×1
ecmascript-6 ×1
javascript ×1
linq ×1
ncrunch ×1
nsubstitute ×1
nunit-3.0 ×1
razor ×1
validation ×1