2014-12-23 49 views
0

我正在构建一个使用Web API和Raven DB的系统。边界测试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

回答

1

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