Skip to content

Commit

Permalink
addunit tests and update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
hollabaq86 committed Apr 7, 2021
1 parent c447112 commit 5b0c023
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Unreleased
* Add `PhoneNumber` to `Address` (thanks @glennsdavis!)

## 5.4.0
- Add missing `ExpirationMonth`, `ExpirationYear`, and `IsNetworkTokenized` fields in `PaymentMethodNonceDetails` (thanks @glennsdavis for `ExpirationMonth` and `ExpirationYear`!)
- Add `ThreeDSecureAuthenticationInfo` and `ThreeDSecureLookupInfo` classes
Expand Down
52 changes: 52 additions & 0 deletions test/Braintree.Tests/AddressTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Braintree.Exceptions;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Text;
using System.Xml;

namespace Braintree.Tests
{
Expand Down Expand Up @@ -31,5 +34,54 @@ public void Find_FindsErrorsOutOnWhitespaceCustomerId()
{
Assert.Throws<NotFoundException>(() => gateway.Address.Find("customer_id", " "));
}

[Test]
public void ConstructFromXMLResponse()
{
StringBuilder builder = new StringBuilder();
builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.Append("<address>");
builder.Append("<id>id</id>");
builder.Append("<customer-id>custid</customer-id>");
builder.Append("<first-name>Christine</first-name>");
builder.Append("<last-name>Darden</last-name>");
builder.Append("<company>NASA</company>");
builder.Append("<street-address>123 xyz street</street-address>");
builder.Append("<extended-address>floor 2</extended-address>");
builder.Append("<locality>Orlando</locality>");
builder.Append("<region>FL</region>");
builder.Append("<postal-code>11111</postal-code>");
builder.Append("<country-code-alpha2>US</country-code-alpha2>");
builder.Append("<country-code-alpha3>USA</country-code-alpha3>");
builder.Append("<country-code-numeric>1</country-code-numeric>");
builder.Append("<country-name>United States</country-name>");
builder.Append("<phone-number>555-555-5555</phone-number>");
builder.Append("<created-at type='datetime'>2018-10-10T22:46:41Z</created-at>");
builder.Append("<updated-at type='datetime'>2020-10-10T22:46:41Z</updated-at>");
builder.Append("</address>");


XmlDocument doc = new XmlDocument();
doc.LoadXml(builder.ToString());

Address address = new Address(new NodeWrapper(doc).GetNode("//address"));
Assert.AreEqual("id", address.Id);
Assert.AreEqual("custid", address.CustomerId);
Assert.AreEqual("Christine", address.FirstName);
Assert.AreEqual("Darden", address.LastName);
Assert.AreEqual("NASA", address.Company);
Assert.AreEqual("123 xyz street", address.StreetAddress);
Assert.AreEqual("floor 2", address.ExtendedAddress);
Assert.AreEqual("Orlando", address.Locality);
Assert.AreEqual("FL", address.Region);
Assert.AreEqual("11111", address.PostalCode);
Assert.AreEqual("US", address.CountryCodeAlpha2);
Assert.AreEqual("USA", address.CountryCodeAlpha3);
Assert.AreEqual("1", address.CountryCodeNumeric);
Assert.AreEqual("United States", address.CountryName);
Assert.AreEqual("555-555-5555", address.PhoneNumber);
Assert.AreEqual("10/10/2018 22:46:41", address.CreatedAt.ToString());
Assert.AreEqual("10/10/2020 22:46:41", address.UpdatedAt.ToString());
}
}
}

0 comments on commit 5b0c023

Please sign in to comment.