Create Simple GET Request
Learn how create a simple GET request using BELLATRIX API library.
Example
[TestFixture]
public class CreateSimpleRequestTests : APITest
{
[Test]
public void GetAlbumById()
{
var request = new RestRequest("api/Albums/10");
var client = App.GetApiClientService();
var response = client.Get<Albums>(request);
Assert.AreEqual(10, response.Data.AlbumId);
}
}
Explanations
[TestFixture]
This is the main attribute that you need to mark each class that contains MSTest tests.
public class CreateSimpleRequestTests : APITest
All API BELLATRIX test classes should inherit from the APItest base class. This way you can use all built-in BELLATRIX tools and functionality.
[Test]
All MSTest tests should be marked with the TestMethod attribute.
var request = new RestRequest("api/Albums/10");
The base URL of your application is set in testFrameworkSettings.json under apiSettings sections- baseUrl. For creating a request you need to point the second part of the URL.
var client = App.GetApiClientService();
Use BELLATRIX App class to get a web client instance. We use it to make requests.
var response = client.Get<Albums>(request);
Use generic Get method to make a GET request. In the **<> **brackets we place the type of the response. BELLATRIX will automatically convert the JSON or XML response to the specified type.
Assert.AreEqual(10, response.Data.AlbumId);
After you have the response object, you can make all kinds of assertions.