-
Notifications
You must be signed in to change notification settings - Fork 34
Unit testing
Alex edited this page Jul 6, 2020
·
3 revisions
To run unit-tests, real world APNS certificates must be provided. This could be done in two ways:
- Create
./dotAPNS/dotAPNS.Tests/env.json
file with the following contents:
{
"dotapns_tests_p8_path": "REPLACE_TO_PATH_OF_YOUR_P8_CERTIFICATE_FILE",
"dotapns_tests_p8_contents" : "REPLACE_WITH_YOUR_P8_CERTIFICATE_CONTENTS",
"dotapns_tests_p12_base64enc" : "REPLACE_WITH_YOUR_P12_CERTIFICATE_RAW_CERT_DATA_BASE64ENCODED"
}
To get raw base64-encoded data from your .p12 certificate, the following code may be used:
var cert = new X509Certificate2("path/to/my/cert.p12");
var bytes = cert.GetRawCertData();
string base64 = Convert.ToBase64String(bytes);
Console.WriteLine(base64);
- Instead of specifying contents in env.json file, environment variables can be used:
dotapns_tests_p8_path
dotapns_tests_p8_contents
dotapns_tests_p12_base64enc
When setting them, please make sure to properly escape the values. The correct way to escape them depends on the environment you use. If you face difficulties, consider using the env.json file as it requires no escaping.
Note: CI system of this repository (https://travis-ci.org/alexalok/dotAPNS/) sets these environment variables during builds automatically. The instruction below should be used only when testing locally.