5. Web API
User Data
from External
Source
Services
Logic
Events
External
Workflow
Repositories
DTO Command Queries
What gets tested?
6. How? An example of Integration Test
6
var response = restClient.Execute(request);
Assert.IsNotNull(response, "No response");
Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode, "Invalid status code");
var responseResult = JsonConvert.DeserializeObject<List<LeaveStatusTypeDto>>(response.Content);
Assert.IsNotNull(responseResult, "Invalid StatusType object");
Assert.IsTrue(responseResult.Exists(t => t.Type == "In Process"), "Missing In Process status");
Assert.IsTrue(responseResult.Exists(t => t.Type == "Rejected"), "Missing Rejected status");
Assert.IsTrue(responseResult.Exists(t => t.Type == "Approved"), "Missing Approved status");
}
[TestMethod]
public void ShouldGetAllStatusTypes()
{
var restClient = new RestClient();
restClient.BaseUrl = new Uri("http://dev.SomeSite.com/");
var request = new RestRequest("api/updateRequest/status/type", Method.GET);
Setup (Create Request)
Assert (Assert all
Responses)
Trigger (Execute
Request(s))
7. Configuration should be minimal
Test cases should be independent
Tests should be efficient
The test suite should clean up after itself
Principles
7