Permalink
Browse files

2.4.0

  • Loading branch information...
1 parent b927284 commit c007571e89b22b7826e81413ea9914384f15596e @braintreeps braintreeps committed Jun 24, 2010
@@ -75,6 +75,7 @@
<Compile Include="RequestTest.cs" />
<Compile Include="ResourceCollectionTest.cs" />
<Compile Include="MultipleValueNodeTest.cs" />
+ <Compile Include="TransparentRedirectTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Braintree\Braintree.csproj">
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using NUnit.Framework;
using Braintree;
using Braintree.Exceptions;
@@ -66,7 +67,7 @@ public void Create_CreatesCreditCardForGivenCustomerId()
Assert.AreEqual("05", creditCard.ExpirationMonth);
Assert.AreEqual("2012", creditCard.ExpirationYear);
Assert.AreEqual("Michael Angelo", creditCard.CardholderName);
- Assert.IsTrue(creditCard.Default.Value);
+ Assert.IsTrue(creditCard.IsDefault.Value);
Assert.AreEqual(DateTime.Now.Year, creditCard.CreatedAt.Value.Year);
Assert.AreEqual(DateTime.Now.Year, creditCard.UpdatedAt.Value.Year);
}
@@ -111,7 +112,7 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDe
};
CreditCard creditCard = gateway.CreditCard.Create(request).Target;
- Assert.IsTrue(creditCard.Default.Value);
+ Assert.IsTrue(creditCard.IsDefault.Value);
CreditCardRequest trParams = new CreditCardRequest
{
@@ -125,7 +126,7 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDe
String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate());
CreditCard card = gateway.CreditCard.ConfirmTransparentRedirect(queryString).Target;
- Assert.IsTrue(card.Default.Value);
+ Assert.IsTrue(card.IsDefault.Value);
}
[Test]
@@ -145,7 +146,7 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDe
};
CreditCard creditCard = gateway.CreditCard.Create(request).Target;
- Assert.IsTrue(creditCard.Default.Value);
+ Assert.IsTrue(creditCard.IsDefault.Value);
CreditCardRequest trParams = new CreditCardRequest
{
@@ -155,7 +156,7 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDe
String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate());
CreditCard card = gateway.CreditCard.ConfirmTransparentRedirect(queryString).Target;
- Assert.IsTrue(card.Default.Value);
+ Assert.IsTrue(card.IsDefault.Value);
}
[Test]
@@ -281,8 +282,8 @@ public void Create_SetsDefaultIfSpecified()
CreditCard card1 = gateway.CreditCard.Create(request1).Target;
CreditCard card2 = gateway.CreditCard.Create(request2).Target;
- Assert.IsFalse(gateway.CreditCard.Find(card1.Token).Default.Value);
- Assert.IsTrue(gateway.CreditCard.Find(card2.Token).Default.Value);
+ Assert.IsFalse(gateway.CreditCard.Find(card1.Token).IsDefault.Value);
+ Assert.IsTrue(gateway.CreditCard.Find(card2.Token).IsDefault.Value);
}
[Test]
@@ -302,8 +303,8 @@ public void Update_UpdatesDefaultIfSpecified()
CreditCard card1 = gateway.CreditCard.Create(creditCardCreateRequest).Target;
CreditCard card2 = gateway.CreditCard.Create(creditCardCreateRequest).Target;
- Assert.IsTrue(card1.Default.Value);
- Assert.IsFalse(card2.Default.Value);
+ Assert.IsTrue(card1.IsDefault.Value);
+ Assert.IsFalse(card2.IsDefault.Value);
var creditCardUpdateRequest = new CreditCardRequest
@@ -316,8 +317,8 @@ public void Update_UpdatesDefaultIfSpecified()
gateway.CreditCard.Update(card2.Token, creditCardUpdateRequest);
- Assert.IsFalse(gateway.CreditCard.Find(card1.Token).Default.Value);
- Assert.IsTrue(gateway.CreditCard.Find(card2.Token).Default.Value);
+ Assert.IsFalse(gateway.CreditCard.Find(card1.Token).IsDefault.Value);
+ Assert.IsTrue(gateway.CreditCard.Find(card2.Token).IsDefault.Value);
}
[Test]
@@ -502,7 +503,7 @@ public void Delete_DeletesTheCreditCard()
}
[Test]
- public void verifyValidCreditCard()
+ public void VerifyValidCreditCard()
{
Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
CreditCardRequest request = new CreditCardRequest
@@ -523,7 +524,7 @@ public void verifyValidCreditCard()
}
[Test]
- public void verifyValidCreditCardSpecifyingMerhantAccount()
+ public void VerifyValidCreditCardSpecifyingMerhantAccount()
{
Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
CreditCardRequest request = new CreditCardRequest
@@ -546,7 +547,7 @@ public void verifyValidCreditCardSpecifyingMerhantAccount()
}
[Test]
- public void verifyInvalidCreditCard()
+ public void VerifyInvalidCreditCard()
{
Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
CreditCardRequest request = new CreditCardRequest
@@ -567,5 +568,42 @@ public void verifyInvalidCreditCard()
CreditCardVerification verification = result.CreditCardVerification;
Assert.AreEqual("processor_declined", verification.Status);
}
+
+ [Test]
+ public void Expired()
+ {
+ ResourceCollection<CreditCard> collection = gateway.CreditCard.Expired();
+
+ Assert.IsTrue(collection.MaximumCount > 1);
+
+ List<String> cards = new List<String>();
+ foreach (CreditCard card in collection) {
+ Assert.IsTrue(card.IsExpired.Value);
+ cards.Add(card.Token);
+ }
+
+ HashSet<String> uniqueCards = new HashSet<String>(cards);
+ Assert.AreEqual(uniqueCards.Count, collection.MaximumCount);
+ }
+
+ [Test]
+ public void ExpiringBetween()
+ {
+ DateTime beginning = new DateTime(2010, 1, 1);
+ DateTime end = new DateTime(2010, 12, 31);
+
+ ResourceCollection<CreditCard> collection = gateway.CreditCard.ExpiringBetween(beginning, end);
+
+ Assert.IsTrue(collection.MaximumCount > 1);
+
+ List<String> cards = new List<String>();
+ foreach (CreditCard card in collection) {
+ Assert.AreEqual("2010", card.ExpirationYear);
+ cards.Add(card.Token);
+ }
+
+ HashSet<String> uniqueCards = new HashSet<String>(cards);
+ Assert.AreEqual(uniqueCards.Count, collection.MaximumCount);
+ }
}
}
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
@@ -10,7 +10,7 @@ namespace Braintree.Tests
public class CryptoTest
{
[Test]
- public void hmacHash_ReturnsCorrectHash()
+ public void HmacHash_ReturnsCorrectHash()
{
String actual = new Crypto().HmacHash("secretKey", "hello world");
Assert.AreEqual("D503D7A1A6ADBA1E6474E9FF2C4167F9DFDF4247", actual);
@@ -326,6 +326,62 @@ public void ConfirmTransparentRedirect_UpdatesTheCustomer()
}
[Test]
+ public void Update_UpdatesCustomerAndNestedValuesViaTr()
+ {
+ var createRequest = new CustomerRequest()
+ {
+ FirstName = "Old First",
+ LastName = "Old Last",
+ CreditCard = new CreditCardRequest()
+ {
+ Number = "4111111111111111",
+ ExpirationDate = "10/10",
+ BillingAddress = new CreditCardAddressRequest()
+ {
+ PostalCode = "11111"
+ }
+ }
+ };
+
+ Customer customer = gateway.Customer.Create(createRequest).Target;
+ CreditCard creditCard = customer.CreditCards[0];
+ Address address = creditCard.BillingAddress;
+
+ var trParams = new CustomerRequest()
+ {
+ CustomerId = customer.Id,
+ FirstName = "New First",
+ LastName = "New Last",
+ CreditCard = new CreditCardRequest()
+ {
+ ExpirationDate = "12/12",
+ Options = new CreditCardOptionsRequest()
+ {
+ UpdateExistingToken = creditCard.Token
+ },
+ BillingAddress = new CreditCardAddressRequest()
+ {
+ PostalCode = "44444",
+ Options = new CreditCardAddressOptionsRequest()
+ {
+ UpdateExisting = true
+ }
+ }
+ }
+ };
+
+ String queryString = TestHelper.QueryStringForTR(trParams, new CustomerRequest(), gateway.Customer.TransparentRedirectURLForUpdate());
+ Customer updatedCustomer = gateway.Customer.ConfirmTransparentRedirect(queryString).Target;
+ CreditCard updatedCreditCard = gateway.CreditCard.Find(creditCard.Token);
+ Address updatedAddress = gateway.Address.Find(customer.Id, address.Id);
+
+ Assert.AreEqual("New First", updatedCustomer.FirstName);
+ Assert.AreEqual("New Last", updatedCustomer.LastName);
+ Assert.AreEqual("12/2012", updatedCreditCard.ExpirationDate);
+ Assert.AreEqual("44444", updatedAddress.PostalCode);
+ }
+
+ [Test]
public void Update_UpdatesCustomerWithNewValues()
{
string oldId = Guid.NewGuid().ToString();
@@ -370,6 +426,60 @@ public void Update_UpdatesCustomerWithNewValues()
}
[Test]
+ public void Update_UpdatesCustomerAndNestedValues()
+ {
+ var createRequest = new CustomerRequest()
+ {
+ FirstName = "Old First",
+ LastName = "Old Last",
+ CreditCard = new CreditCardRequest()
+ {
+ Number = "4111111111111111",
+ ExpirationDate = "10/10",
+ BillingAddress = new CreditCardAddressRequest()
+ {
+ PostalCode = "11111"
+ }
+ }
+ };
+
+ Customer customer = gateway.Customer.Create(createRequest).Target;
+ CreditCard creditCard = customer.CreditCards[0];
+ Address address = creditCard.BillingAddress;
+
+ var updateRequest = new CustomerRequest()
+ {
+ FirstName = "New First",
+ LastName = "New Last",
+ CreditCard = new CreditCardRequest()
+ {
+ ExpirationDate = "12/12",
+ Options = new CreditCardOptionsRequest()
+ {
+ UpdateExistingToken = creditCard.Token
+ },
+ BillingAddress = new CreditCardAddressRequest()
+ {
+ PostalCode = "44444",
+ Options = new CreditCardAddressOptionsRequest()
+ {
+ UpdateExisting = true
+ }
+ }
+ }
+ };
+
+ Customer updatedCustomer = gateway.Customer.Update(customer.Id, updateRequest).Target;
+ CreditCard updatedCreditCard = gateway.CreditCard.Find(creditCard.Token);
+ Address updatedAddress = gateway.Address.Find(customer.Id, address.Id);
+
+ Assert.AreEqual("New First", updatedCustomer.FirstName);
+ Assert.AreEqual("New Last", updatedCustomer.LastName);
+ Assert.AreEqual("12/2012", updatedCreditCard.ExpirationDate);
+ Assert.AreEqual("44444", updatedAddress.PostalCode);
+ }
+
+ [Test]
public void Delete_DeletesTheCustomer()
{
String id = Guid.NewGuid().ToString();
@@ -398,8 +508,9 @@ public void Delete_DeletesTheCustomer()
foreach (Customer item in collection) {
items.Add(item.Id);
}
+ HashSet<String> uniqueItems = new HashSet<String>(items);
- Assert.AreEqual(items.Count, collection.MaximumCount);
+ Assert.AreEqual(uniqueItems.Count, collection.MaximumCount);
}
}
}
@@ -536,6 +536,34 @@ public void UpdatePlan()
}
[Test]
+ public void Update_PaymentMethodToken()
+ {
+ Subscription subscription = gateway.Subscription.Create(new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITHOUT_TRIAL.Id,
+ }).Target;
+
+ CreditCard newCreditCard = gateway.CreditCard.Create(new CreditCardRequest
+ {
+ CustomerId = creditCard.CustomerId,
+ Number = "5105105105105100",
+ ExpirationDate = "05/12",
+ CVV = "123",
+ CardholderName = creditCard.CardholderName
+
+ }).Target;
+
+ SubscriptionRequest updateRequest = new SubscriptionRequest { PaymentMethodToken = newCreditCard.Token };
+ Result<Subscription> result = gateway.Subscription.Update(subscription.Id, updateRequest);
+
+ Assert.IsTrue(result.IsSuccess());
+ subscription = result.Target;
+
+ Assert.AreEqual(newCreditCard.Token, subscription.PaymentMethodToken);
+ }
+
+ [Test]
public void UpdateMerchantAccountId()
{
Plan originalPlan = Plan.PLAN_WITHOUT_TRIAL;
@@ -613,15 +641,10 @@ public void Create_WithBadPlanId()
PlanId = "noSuchPlanId"
};
- try
- {
- gateway.Subscription.Create(createRequest);
- Assert.Fail("Expected NotFoundException.");
- }
- catch (NotFoundException)
- {
- // expected
- }
+ Result<Subscription> result = gateway.Subscription.Create(createRequest);
+
+ Assert.IsFalse(result.IsSuccess());
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_PLAN_ID_IS_INVALID, result.Errors.ForObject("subscription").OnField("plan_id")[0].Code);
}
[Test]
@@ -633,15 +656,10 @@ public void Create_WithBadPaymentMethod()
PlanId = Plan.PLAN_WITHOUT_TRIAL.Id
};
- try
- {
- gateway.Subscription.Create(createRequest);
- Assert.Fail("Expected NotFoundException.");
- }
- catch (NotFoundException)
- {
- // expected
- }
+ Result<Subscription> result = gateway.Subscription.Create(createRequest);
+
+ Assert.IsFalse(result.IsSuccess());
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_PAYMENT_METHOD_TOKEN_IS_INVALID, result.Errors.ForObject("subscription").OnField("payment_method_token")[0].Code);
}
[Test]
Oops, something went wrong.

0 comments on commit c007571

Please sign in to comment.