Given Conext : Set Up - LiberatorTestTools/RESTore GitHub Wiki

RESTore is based on RestAssured.NET, itself based on the Java tool RestAssured. This version has been continued and enhanced by the Liberator Test Tools team. It is a fluent domain specific language, built to resemble the cucumber syntax, which can be used to test HTTP communications.

new RESTore().Given()

A request begins with a new instance of RESTore. From this, we have a single call which is to a Given method, which will allow access to the basic settings of the call under tests.

A name can be applied to the test and can be used to report on the test in the console or output file

.Name("name of test")

The addition of a proxy, if required to access the endpoint, can be set to use the current AD user or the test can pass a specific username and password to the proxy server:

.Proxy("https://address.of.proxy.server")
.Proxy("https://address.of.proxy.server", username, password)

The user can set the base URL and the port for the request. We can also set the Uri for the endpoint itself - although this is more usual to set this within the WhenContext (see later):

.Host("http://address.of.host")
.Port(portnumber)
.Uri("route/to/end/point")

Most, if not all HTTP requests have a header attached. These are simple to add, either one by one or in a dictionary:

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

Certain requests, especially GET requests, can have query parameters appended to the end of the request that allow the user to pass parameters to queries on the server. These can be added individually or as a dictionary and get added to the requests as query strings.

.Query("key", "value")
.Query(queryDictionary)

We can also add parameters to the request that are not included as part of the query string, such as form parameters.

.Parameter("key", "value")
.Parameters(parameterDictionary)

With a POST, PATCH or PUT we are often in a position where we send a body for the request. We can set this by sending the body as a string, or by passing an object that will be converted to JSON.

.Body("{body: request}")
.Body<MyObject>(objectInstance)

Adding cookies to the request is also easy … as is adding a file to the request.

.Cookie("name", "value")
.Cookies(cookieDictionary)
.File(fileName, contentDispositionName, contentType, content)

The GivenContext is completed by moving to the next step in the fluent chain, which is the WhenContext. We achieve this by simply calling the parameterless method:

.When()
⚠️ **GitHub.com Fallback** ⚠️