2014-12-23 51 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。