Create Simple GET Request

Learn how create a simple GET request using Bellatrix API library.

Example

[TestClass]
public class CreateSimpleRequestTests : APITest
{
    [TestMethod]
    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

[TestClass]

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.

[TestMethod]

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.