我正在尝试为我的ApiController编写一些单元测试并遇到一些问题.有一个很好的扩展方法叫做Request.CreateResponse,可以帮助生成响应.
public HttpResponseMessage Post(Product product)
{
var createdProduct = repo.Add(product);
return this.Request.CreateResponse(HttpStatusCode.Created, createdProduct);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在不使用部分模拟或直接使用"new HttpResponseMessage(...)"的情况下模拟CreateResponse?
我有应用程序设置的node.js应用程序和conf.json文件,即:
{
"settings": [
{
"name": "setting1",
"connectionString": {
"host": "mongodb://127.0.0.1:27017/db",
"collection": "collection1"
}
},
{
"name": "setting2",
"file": "/path/file",
"token": "development token"
}
]
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在nconf或其他工具中使用.NET的配置转换模拟,所以我可能有生成配置文件覆盖,即conf.production.json:
{
"settings": [
{
"name": "setting2",
"token": "production token"
}
]
}
Run Code Online (Sandbox Code Playgroud)
生产模式中"setting2"的预期值是"生产令牌",并从默认配置文件中休息.我试图用nconf加载基本文件,但它不起作用:
nconf.file(process.env.NODE_ENV, './conf.' + process.env.NODE_ENV + '.json');
nconf.file('./conf.json');
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的模型:
public class PhraseMeta:
{
public int Id { get; set; }
public string ModuleName { get; set; }
public string Description { get; set; }
public DateTime ModifiedDate { get; set; }
}
public class Phrase
{
public int Id { get; set; }
public int PhraseMetaId { get; set; } //reference to PhraseMeta
public string Language { get; set; }
public string Text { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
短语包含一些翻译,PhraseMeta包含几个短语的元信息.我试图找到具有ModuleName和Language的Phrase的文本.据我所知,RavenDB的Multi Maps/Reduce索引功能可以帮助它,而不是使用WhereEntityIs.我的索引是:
public class PhraseEntry
{
public string MetaId { …Run Code Online (Sandbox Code Playgroud)