ThenContext: Validation - LiberatorTestTools/RESTore GitHub Wiki

The ThenContext is used in RESTore to validate the response from the server after the call has been executed. This validation phase begins with the ThenContext being called:

.Then()

Validation in RESTore can be achieved in two ways. One can either Assess the values of multiple settings before asserting that the test passes, or to Assert a value immediately. The choice depends on whether an NUnit test is required for each of the assertions or whether the call itself is the focus of the test. The former is helpful in development, whereas the latter is more helpful in regression - neither is considered "right".

At this point we have the response from the server and can validate that we have the correct details. There are three methods that validate the status returned from the server - whether the call was a success, failure or an exact status:

.AssessSuccessStatus()
.AssessFailureStatus()
.AssessStatus(HttpStatus.OK)

.AssertSuccessStatus()
.AssertFailureStatus()
.AssertStatus(HttpStatus.OK)

We can check that the correct headers are returned with the correct values:

.AssessHeader("name", "value")
.AssessHeaders(headerDictionary)

.AssertHeader("name", "value")
.AssertHeader(headerDictionary)

We can check that the body of the request meets certain criteria, including that it can be de-serialised into a particular object. This object is controlled by the end user and should conform to the expected return values.

.AssessBody("testName", lambdaFunction)
.AssertBody(lambdaFunction)

.AssessBody<ReturnObject>("testName", lambdaFunction)
.AssertBody<ReturnObject>(lambdaFunction)

For the Assess methods, we make the final assertion by using:

.AssertPass()

The results of the assessment process can then be written to the console:

.ToConsole()