Skip to content

Commit

Permalink
2.59.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed May 11, 2016
1 parent 461ae41 commit e139909
Show file tree
Hide file tree
Showing 26 changed files with 561 additions and 343 deletions.
7 changes: 2 additions & 5 deletions Braintree.Tests/AddOnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void All_ReturnsAllAddOns()

[Test]
[Category("Unit")]
[ExpectedException(typeof(ConfigurationException))]
public void All_RaisesIfMissingCredentials()
{
gateway = new BraintreeGateway
Expand All @@ -73,11 +74,7 @@ public void All_RaisesIfMissingCredentials()
PrivateKey = "integration_private_key"
};

try {
gateway.AddOn.All();

Assert.Fail("Should throw ConfigurationException");
} catch (ConfigurationException) {}
gateway.AddOn.All();
}
}
}
Expand Down
37 changes: 18 additions & 19 deletions Braintree.Tests/AddressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ public void Find_FindsAddress()

[Test]
[Category("Unit")]
public void Find_FindsErrorsOutOnWhitespaceIds()
[ExpectedException(typeof(NotFoundException))]
public void Find_FindsErrorsOutOnWhitespaceAddressId()
{
try {
gateway.Address.Find(" ", "address_id");
Assert.Fail("Should throw NotFoundException");
} catch (NotFoundException) {}
gateway.Address.Find(" ", "address_id");
}

try {
gateway.Address.Find("customer_id", " ");
Assert.Fail("Should throw NotFoundException");
} catch (NotFoundException) {}
[Test]
[Category("Unit")]
[ExpectedException(typeof(NotFoundException))]
public void Find_FindsErrorsOutOnWhitespaceCustomerId()
{
gateway.Address.Find("customer_id", " ");
}

[Test]
Expand Down Expand Up @@ -216,6 +217,7 @@ public void Update_ReturnsAnErrorResult_ForInconsistenCountry()

[Test]
[Category("Integration")]
[ExpectedException(typeof(NotFoundException))]
public void Delete_DeletesTheAddress()
{
Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
Expand All @@ -229,17 +231,14 @@ public void Delete_DeletesTheAddress()
Address createdAddress = gateway.Address.Create(customer.Id, addressRequest).Target;
Assert.AreEqual(createdAddress.Id, gateway.Address.Find(customer.Id, createdAddress.Id).Id);

Result<Address> result = gateway.Address.Delete(customer.Id, createdAddress.Id);
Assert.IsTrue(result.IsSuccess());
try
{
gateway.Address.Find(customer.Id, createdAddress.Id);
Assert.Fail("Expected NotFoundException.");
}
catch (NotFoundException)
{
// expected
try {
Result<Address> result = gateway.Address.Delete(customer.Id, createdAddress.Id);
Assert.IsTrue(result.IsSuccess());
} catch (NotFoundException) {
Assert.Fail("Unable to delete the created address");
}

gateway.Address.Find(customer.Id, createdAddress.Id);
}

[Test]
Expand Down
40 changes: 22 additions & 18 deletions Braintree.Tests/BraintreeServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,43 @@ public class BraintreeServiceTest
{
[Test]
[Category("Unit")]
[ExpectedException(typeof(Braintree.Exceptions.AuthenticationException))]
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
}
new BraintreeService(new Configuration(Environment.SANDBOX, "dummy", "dummy", "dummy")).Get("/");
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(Braintree.Exceptions.AuthenticationException))]
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
}
new BraintreeService(new Configuration(Environment.PRODUCTION, "dummy", "dummy", "dummy")).Get("/");
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(Braintree.Exceptions.UpgradeRequiredException))]
public void ThrowExceptionIfErrorStatusCodeIsUpgradeRequired()
{
try {
BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 426, null);
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.UpgradeRequiredException) {
// expected
}
BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 426, null);
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(Braintree.Exceptions.TooManyRequestsException))]
public void ThrowExceptionIfErrorStatusCodeIsTooManyRequests()
{
BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 429, null);
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(Braintree.Exceptions.DownForMaintenanceException))]
public void ThrowExceptionIfErrorStatusCodeIsDownForMaintenance()
{
BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 503, null);
}

private static bool TrustAllCertificates(object sender, X509Certificate x509Certificate, X509Chain x509Chain, SslPolicyErrors sslPolicyErrors)
Expand Down
43 changes: 25 additions & 18 deletions Braintree.Tests/ClientTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void Generate_RaisesExceptionIfVerifyCardIsIncludedWithoutCustomerId()
PublicKey = "integration_public_key",
PrivateKey = "integration_private_key"
};
Exception exception = null;
try {
gateway.ClientToken.generate(
new ClientTokenRequest
Expand All @@ -32,11 +33,12 @@ public void Generate_RaisesExceptionIfVerifyCardIsIncludedWithoutCustomerId()
}
}
);
Assert.Fail("Should raise ArgumentException");
} catch (ArgumentException e) {
Match match = Regex.Match(e.Message, @"VerifyCard");
Assert.IsTrue(match.Success);
} catch (Exception tempException) {
exception = tempException;
}
Assert.IsNotNull(exception);
Assert.IsTrue(Regex.Match(exception.Message, @"VerifyCard").Success);
Assert.IsInstanceOfType(typeof(System.ArgumentException), exception);
}

[Test]
Expand All @@ -50,6 +52,7 @@ public void Generate_RaisesExceptionIfMakeDefaultIsIncludedWithoutCustomerId()
PublicKey = "integration_public_key",
PrivateKey = "integration_private_key"
};
Exception exception = null;
try {
gateway.ClientToken.generate(
new ClientTokenRequest
Expand All @@ -60,11 +63,12 @@ public void Generate_RaisesExceptionIfMakeDefaultIsIncludedWithoutCustomerId()
}
}
);
Assert.Fail("Should raise ArgumentException");
} catch (ArgumentException e) {
Match match = Regex.Match(e.Message, @"MakeDefault");
Assert.IsTrue(match.Success);
} catch (Exception tempException) {
exception = tempException;
}
Assert.IsNotNull(exception);
Assert.IsTrue(Regex.Match(exception.Message, @"MakeDefault").Success);
Assert.IsInstanceOfType(typeof(System.ArgumentException), exception);
}

[Test]
Expand All @@ -78,6 +82,7 @@ public void Generate_RaisesExceptionIfFailOnDuplicatePaymentMethodIsIncludedWith
PublicKey = "integration_public_key",
PrivateKey = "integration_private_key"
};
Exception exception = null;
try {
gateway.ClientToken.generate(
new ClientTokenRequest
Expand All @@ -88,11 +93,12 @@ public void Generate_RaisesExceptionIfFailOnDuplicatePaymentMethodIsIncludedWith
}
}
);
Assert.Fail("Should raise ArgumentException");
} catch (ArgumentException e) {
Match match = Regex.Match(e.Message, @"FailOnDuplicatePaymentMethod");
Assert.IsTrue(match.Success);
} catch (Exception tempException) {
exception = tempException;
}
Assert.IsNotNull(exception);
Assert.IsTrue(Regex.Match(exception.Message, @"FailOnDuplicatePaymentMethod").Success);
Assert.IsInstanceOfType(typeof(System.ArgumentException), exception);
}
}

Expand Down Expand Up @@ -331,7 +337,7 @@ public void Generate_ThrowExceptionWhenCustomerNotFound()
};

string encodedClientToken = "";

Exception exception = null;
try
{
encodedClientToken += gateway.ClientToken.generate(
Expand All @@ -340,11 +346,12 @@ public void Generate_ThrowExceptionWhenCustomerNotFound()
CustomerId = "NON_EXISTENT_CUSTOMER_ID"
}
);
Assert.Fail("Should raise ArgumentException");
} catch (ArgumentException e) {
Match match = Regex.Match(e.Message, @"customer_id");
Assert.IsTrue(match.Success);
} catch (Exception tempException) {
exception = tempException;
}
}
Assert.IsNotNull(exception);
Assert.IsTrue(Regex.Match(exception.Message, @"customer_id").Success);
Assert.IsInstanceOfType(typeof(System.ArgumentException), exception);
}
}
}
112 changes: 75 additions & 37 deletions Braintree.Tests/ConfigurationTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using NUnit.Framework;
using Braintree;
using Braintree.Exceptions;
Expand All @@ -12,63 +13,55 @@ public class ConfigurationTest
{
[Test]
[Category("Unit")]
[ExpectedException(typeof(ConfigurationException))]
public void ConfigurationMissingEnvironment_ThrowsConfigurationException()
{
try {
Environment environment = null;
new Configuration(
environment,
"integration_merchant_id",
"integration_public_key",
"integration_private_key"
);
Assert.Fail("Should throw ConfigurationException");
} catch (ConfigurationException) {}
Environment environment = null;
new Configuration(
environment,
"integration_merchant_id",
"integration_public_key",
"integration_private_key"
);
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(ConfigurationException))]
public void ConfigurationMissingMerchantId_ThrowsConfigurationException()
{
try {
new Configuration(
Environment.DEVELOPMENT,
null,
"integration_public_key",
"integration_private_key"
);
Assert.Fail("Should throw ConfigurationException");
} catch (ConfigurationException) {}
new Configuration(
Environment.DEVELOPMENT,
null,
"integration_public_key",
"integration_private_key"
);
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(ConfigurationException))]
public void ConfigurationMissingPublicKey_ThrowsConfigurationException()
{
try {
new Configuration(
Environment.DEVELOPMENT,
"integration_merchant_id",
null,
"integration_private_key"
);
Assert.Fail("Should throw ConfigurationException");
} catch (ConfigurationException) {}
new Configuration(
Environment.DEVELOPMENT,
"integration_merchant_id",
null,
"integration_private_key"
);
}

[Test]
[Category("Unit")]
[ExpectedException(typeof(ConfigurationException))]
public void ConfigurationMissingPrivateKey_ThrowsConfigurationException()
{
try {
new Configuration(
Environment.DEVELOPMENT,
"integration_merchant_id",
"integration_public_key",
null
);
Assert.Fail("Should throw ConfigurationException");
} catch (ConfigurationException) {}
new Configuration(
Environment.DEVELOPMENT,
"integration_merchant_id",
"integration_public_key",
null
);
}

[Test]
Expand Down Expand Up @@ -208,5 +201,50 @@ public void Timeout_ReturnsTheSetValue()

Assert.AreEqual(1, configuration.Timeout);
}

[Test]
[Category("Unit")]
public void HttpWebRequestFactory_ReturnsDefaultIfNotSpecified()
{
Configuration configuration = new Configuration(
Environment.DEVELOPMENT,
"integration_merchant_id",
"integration_public_key",
"integration_private_key"
);

Assert.IsNotNull(configuration.HttpWebRequestFactory);

HttpWebRequest httpWebRequest = WebRequest.Create("http://webrequest.com") as HttpWebRequest;
Assert.IsInstanceOfType(httpWebRequest.GetType(), configuration.HttpWebRequestFactory(configuration.Environment.GatewayURL + "/merchants/integration_merchant_id"));
}

[Test]
[Category("Unit")]
public void HttpWebRequestFactory_AcceptsCustomDelegate()
{
Configuration configuration = new Configuration(
Environment.DEVELOPMENT,
"integration_merchant_id",
"integration_public_key",
"integration_private_key"
);

configuration.HttpWebRequestFactory =
delegate(String requestUriString)
{
var webRequest = WebRequest.Create(requestUriString) as HttpWebRequest;
webRequest.AddRange(1024);
return webRequest;
};

Assert.IsNotNull(configuration.HttpWebRequestFactory);

var btWebRequest = configuration.HttpWebRequestFactory(configuration.Environment.GatewayURL + "/merchants/integration_merchant_id");
HttpWebRequest httpWebRequest = WebRequest.Create("http://webrequest.com") as HttpWebRequest;

Assert.IsInstanceOfType(httpWebRequest.GetType(), btWebRequest);
StringAssert.Contains("1024", btWebRequest.Headers["Range"]);
}
}
}
Loading

0 comments on commit e139909

Please sign in to comment.