Skip to content

Testing

Sean McIlvenna edited this page Mar 8, 2017 · 2 revisions

Unit Tests

.NET unit tests are located in the Trifolia.Test assembly. A semi-complicated class is used to mock the database layer called MockObjectRepository. MockObjectRepository is an in-memory equiv. to the database. As tests are built, some functionality needs to be added. The Moq package/library is used to mock up the DbSet collections within the MockObjectRepository class. The MockObjectRepository implements IObjectRepository so that classes can be instantiated with a MockObjectRepository instead of a TrifoliaDatabase class.

REST Testing

A SOAP UI project exists in the REST.Test directory. The project was created using the WADL produced by /api/Help/Wadl. Test cases are setup for various scenarios that run the REST operations on an installation of Trifolia. The test cases perform assertions to ensure that the response from the REST API is correct. Test cases that create data should also destroy the data so that the test case can be repeated.

Authentication

When executing the tests, SOAP UI needs to be able to authenticate the REST calls. This is handled via a custom property on the project called "authBearer". The authBearer property should be in the form of "Bearer XXXXX", where XXXX is an OAuth token. You can generate an OAuth token by logging into the installation of Trifolia that you are testing against and going to "My Profile". The "My Profile" page shows you the OAuth token that you are logged in with.

When setting up new tests, an "Authorization" header should be added to the test case with a value of "${#Project#authBearer}". This indicates to the test case to pull the value for the Authorization header from the project's authBearer property.

Endpoint

When testing on various environments, the endpoint needs to be changed. This can be easily changed on each test by opening the Test Suite and clicking the "URL" button at the top of the Test Suite screen.

The endpoints available in the drop-down are derived from the "Service Endpoints" tab in the project's "api" service definition. The "api" service definition's "Service Endpoints" tab is another way of changing the endpoint/URL for multiple tests/requests.

Clone this wiki locally