c# - 使用 Raven Db 进行边界测试

标签 c# testing asp.net-web-api ravendb

我正在使用 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);
    }
}

当我提交条目时,ControllerDocumentStore 交互,因为这就是它在生产中的工作方式。

我遇到的问题是测试中产生的数据从未被清理过。

根据我所阅读的内容,我应该使用 EmbeddableDocumentStore 进行验收测试。

在执行像这样的边界测试时,如何正常使用 DocumentStore 而不是 EmbeddableDocumentStore

最佳答案

如何在 Controller 中“与 DocumentStore 交互”? Controller 实际上只需要与可以由 WebAPI 基础结构注入(inject)的 IDocumentSession 进行“交互”,并且在您的集成测试中,您注册 IDocumentStore 以由 EmbeddableDocumentStore 实现(前提是您使用某种 IoC 容器)。

关于c# - 使用 Raven Db 进行边界测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27626070/

相关文章:

c# - 在一个程序中组合 32 位和 64 位 DLL

testing - 让 JUnit 失败的测试实际上并不运行断言

python - 使用 C 扩展构建/测试 Python 项目

c# - 找不到 Request.GetOwinContext

c# - WEB API + ASP.NET 尝试以 json 格式显示来自 WEB.API 的数据

c# - 如何将 102.555 舍入为 102.55?

c# - 如何在 ItemsControl 中实现自定义内联搜索?

c# - Python 与 C# Twitter API 库

haskell - cabal 测试无法链接自己的对象

c# - Owin 中间件而不是 web api 中的消息处理程序