The Post Conflict test

With this test, we check if our service responds with a status of Conflict. How can we do this?

Send the same data twice, and this is what we do.

We get our Green model as before. Call post using our HttpClient, and although this is an act, in this context of this particular test, it is part of our setup. Now call post again, which is where we act. We then assert that we get back a conflict:

    [TestMethod] 
    public async Task ReturnConflictForAPost() 
    { 
      // arrange  
      using (HttpClient client = new HttpClient()) 
      { 
         client.BaseAddress = new Uri(_baseUri); 
                 //arrange  
         StoreModel storeModel = GreenStoreModel(); 
         storeModel.Name = "ConflictStore"; 
         HttpResponseMessage response = await client.PostAsJsonAsync(" stores", storeModel); ...

Get Mastering ASP.NET Web API now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.