Skip to content

Endpoint responses should be available as resources during unit testing instead of hard coding as a string in each unit test #476

@Jericho

Description

@Jericho

This is quite similar to the enhancement @ivan-pavlik and I worked on some time ago to unit test the webhook parser: we created one JSON file for each webhook and also created a resource RESX file pointing at all these JSON files. This allowed us to remove all the hardcoded JSON data from the unit tests and replace them with references to resources such as:

var parsedEvent = ParseWebhookEvent<ContactCenterAssetCreatedEvent>(Resource.contact_center_asset_created_webhook);

I intend to be the same for all endpoints. Meaning: create a file containing the JSON data returned by each endpoint, create a resource file pointing to all these new files and finally simplify unit tests like so:

// Example of a unit test that references a CONST with hardcoded JSON
private const string SINGLE_ACCOUNT_JSON = @"{
	""id"": 123456789,
	""account_name"": ""Test Account"",
	""owner_email"": ""owner@example.com"",
	""account_type"": ""Pro"",
	""seats"": 10,
	""subscription_start_time"": ""2021-01-01T00:00:00Z"",
	""subscription_end_time"": ""2021-12-31T23:59:59Z"",
	""created_at"": ""2020-01-01T00:00:00Z""
}";

var mockHttp = new MockHttpMessageHandler();
mockHttp.Expect(HttpMethod.Post, Utils.GetZoomApiUri("accounts"))
	.Respond("application/json", SINGLE_ACCOUNT_JSON);


// New test will look something like this (notice the absence of the CONST)
var mockHttp = new MockHttpMessageHandler();
mockHttp.Expect(HttpMethod.Post, Utils.GetZoomApiUri("accounts"))
	.Respond("application/json", EndpointsResource.get_single_account);

I will create a new resource for all the "endpoint-related" json files, and I will also rename the current Resource.resx to WebhooksResource.resx.

Metadata

Metadata

Assignees

Labels

EnhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions