我正在使用 Web API 和 Raven DB 构建一个系统。
我正在针对该系统的外部边界编写集成测试。
public void GetAfterPostingPollReturnsPoll()
{
using (var client = HttpClientFactory.Create())
{
var poll = new
{
Question = "What is the answer?",
Options = new[] { "Yes", "No", "Maybe" }
};
var postResponse = client.PostAsJsonAsync("", poll).Result;
var pollLocation = postResponse.Headers.Location;
var getResponse = client.GetAsync(pollLocation).Result;
var actual = JsonConvert.DeserializeObject<Poll>(
getResponse.Content
.ReadAsStringAsync()
.Result);
Assert.Equal(poll.Question, actual.Question);
Assert.Equal(poll.Options, actual.Options);
}
}
当我提交条目时,Controller
与 DocumentStore
交互,因为这就是它在生产中的工作方式。
我遇到的问题是测试中产生的数据从未被清理过。
根据我所阅读的内容,我应该使用 EmbeddableDocumentStore
进行验收测试。
在执行像这样的边界测试时,如何正常使用 DocumentStore
而不是 EmbeddableDocumentStore
?
最佳答案
如何在 Controller 中“与 DocumentStore 交互”? Controller 实际上只需要与可以由 WebAPI 基础结构注入(inject)的 IDocumentSession 进行“交互”,并且在您的集成测试中,您注册 IDocumentStore 以由 EmbeddableDocumentStore 实现(前提是您使用某种 IoC 容器)。
关于c# - 使用 Raven Db 进行边界测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27626070/