Accelerate Test Creation
We developed a group of features which support the process of test creation. Let’s take a look how BELLATRIX can speed up your test creation by providing predefined response assertions, default authentication modules, JSON and XML schema validations and ready-to-go project templates.
Predefined Response Assertions
The BELLATRIX API library brings many convenient assertion methods on top of RestSharp.
Of course, you can write similar methods yourself using MSTest or NUnit. All BELLATRIX assertions come with full BDD logging and extensibility hooks. We save you lots of time on writing all of these methods yourself.
Assert that the status code is successful.
response.AssertSuccessStatusCode();
Assert that the header named ‘server’ has the value ‘Kestrel’.
response.AssertResponseHeader("server", "Kestrel");
Assert that the native text content (JSON or XML) contains the specified value.
response.AssertContentContains("Metallica");
Assert the response content encoding.
response.AssertContentEncoding("gzip");
Assert C# collections directly.
response.AssertResultEquals(expectedAlbums);
Assert that a specific cookie exists.
response.AssertCookieExists("whoIs");
6+ Authentication Strategies
To save you even more time, BELLATRIX comes with 6 default authentication modules.
You need to place the authentications strategy attribute over the test class and configure it. We use JwtToken authentication. The attribute accepts your text token.
[TestClass]
[JwtAuthenticationStrategy(GlobalConstants.JwtToken)]
public class AuthenticationTests : 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);
}
}
Other authentication strategy attributes:
- HttpBasicAuthenticationStrategy – user and password.
- NtlmAuthenticationStrategy – authenticate with the credentials of the currently logged in user, or impersonate a user.
- OAuth2AuthorizationRequestHeaderAuthenticationStrategy – OAuth 2 authenticator using the authorization request header field.
- OAuth2UriQueryParameterAuthenticationStrategy – OAuth 2 authenticator using URI query parameter.
- SimpleAuthenticationStrategy – userKey, user, passwordKey, password.
Validate JSON and XML Schemas
You can easily validate whether or not your API’s schema stays valid over time with BELLATRIX.
We support XML and JSON schema validation.
var expectedSchema = @"{
""definitions"": {},
""$schema"": ""http://json-schema.org/draft-07/schema#"",
""$id"": ""http://example.com/root.json"",
""type"": ""object"",
""title"": ""The Root Schema"",
""required"": [
""albumId"",
""title"",
""artistId"",
""artist"",
""tracks""
]
}";
response.AssertSchema(expectedSchema);