forked from braintree/braintree_dotnet
/
BraintreeServiceTest.cs
56 lines (51 loc) · 1.94 KB
/
BraintreeServiceTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using NUnit.Framework;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace Braintree.Tests
{
[TestFixture]
public class BraintreeServiceTest
{
[Test]
public void SandboxSSLCertificateSuccessful()
{
try {
new BraintreeService(new Configuration(Environment.SANDBOX, "dummy", "dummy", "dummy")).Get("/");
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.AuthenticationException) {
// expected
}
}
[Test]
public void ProductionSSLCertificateSuccessful()
{
ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificates;
try {
new BraintreeService(new Configuration(Environment.PRODUCTION, "dummy", "dummy", "dummy")).Get("/");
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.AuthenticationException) {
// expected
}
}
[Test]
public void ThrowExceptionIfErrorStatusCodeIsUpgradeRequired()
{
try {
BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 426, null);
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.UpgradeRequiredException) {
// expected
}
}
private static bool TrustAllCertificates(object sender, X509Certificate x509Certificate, X509Chain x509Chain, SslPolicyErrors sslPolicyErrors)
{
// to work around this bug which is yet to be released in mono
// https://bugzilla.novell.com/show_bug.cgi?id=606002
return true;
}
}
}