-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38422af
commit 9f108ee
Showing
26 changed files
with
810 additions
and
1,762 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
/** | ||
* wallee SDK | ||
* | ||
* This library allows to interact with the wallee payment service. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
@@ -32,155 +14,61 @@ | |
namespace Wallee.Test | ||
{ | ||
/// <summary> | ||
/// Class for testing ChargeAttemptService | ||
/// ChargeAttemptService tests | ||
/// </summary> | ||
[TestFixture] | ||
public class ChargeAttemptServiceTests | ||
{ | ||
|
||
private readonly long SpaceId = 405; | ||
private readonly string ApplicationUserID = "512"; | ||
private readonly string AuthenticationKey = "FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ="; | ||
|
||
private Configuration Configuration; | ||
private ChargeAttemptService ChargeAttemptService; | ||
private TransactionCreate TransactionPayload; | ||
private TransactionService TransactionService; | ||
private TransactionService transactionService; | ||
private ChargeAttemptService chargeAttemptService; | ||
private CardProcessingService cardProcessingService; | ||
|
||
/// <summary> | ||
/// Setup before each unit test | ||
/// </summary> | ||
[SetUp] | ||
public void Init() | ||
{ | ||
if (this.Configuration == null) { | ||
this.Configuration = new Configuration(this.ApplicationUserID, this.AuthenticationKey); | ||
} | ||
|
||
if (this.ChargeAttemptService == null){ | ||
this.ChargeAttemptService = new ChargeAttemptService(this.Configuration); | ||
} | ||
|
||
if (this.TransactionService == null) | ||
{ | ||
this.TransactionService = new TransactionService(this.Configuration); | ||
} | ||
transactionService = new TransactionService(Constants.Config); | ||
chargeAttemptService = new ChargeAttemptService(Constants.Config); | ||
cardProcessingService = new CardProcessingService(Constants.Config); | ||
} | ||
|
||
/// <summary> | ||
/// Clean up after each unit test | ||
/// </summary> | ||
[TearDown] | ||
public void Cleanup() | ||
{ | ||
|
||
} | ||
|
||
// <summary> | ||
// Get transaction payload | ||
// <summary> | ||
private TransactionCreate GetTransactionPayload() | ||
{ | ||
if (this.TransactionPayload == null) | ||
{ | ||
// Line item | ||
LineItemCreate lineItem1 = new LineItemCreate( | ||
name: "Red T-Shirt", | ||
uniqueId: "5412", | ||
type: LineItemType.PRODUCT, | ||
quantity: 1, | ||
amountIncludingTax: (decimal)29.95 | ||
) | ||
{ | ||
Sku = "red-t-shirt-123" | ||
}; | ||
|
||
// Customer Billing Address | ||
AddressCreate billingAddress = new AddressCreate | ||
{ | ||
City = "Winterthur", | ||
Country = "CH", | ||
EmailAddress = "[email protected]", | ||
FamilyName = "Customer", | ||
GivenName = "Good", | ||
Postcode = "8400", | ||
PostalState = "ZH", | ||
OrganizationName = "Test GmbH", | ||
MobilePhoneNumber = "+41791234567", | ||
Salutation = "Ms" | ||
}; | ||
|
||
this.TransactionPayload = new TransactionCreate(new List<LineItemCreate>() { lineItem1 }) | ||
{ | ||
Currency = "CHF", | ||
AutoConfirmationEnabled = true, | ||
BillingAddress = billingAddress, | ||
ShippingAddress = billingAddress, | ||
Language = "en-US" | ||
}; | ||
} | ||
return this.TransactionPayload; | ||
} | ||
|
||
/// <summary> | ||
/// Test an instance of ChargeAttemptService | ||
/// </summary> | ||
[Test] | ||
public void InstanceTest() | ||
{ | ||
Assert.IsInstanceOf<ChargeAttemptService>(ChargeAttemptService, "instance is a ChargeAttemptService"); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Test Count | ||
/// </summary> | ||
public void CountTest() | ||
{ | ||
// TODO uncomment below to test the method and replace null with proper value | ||
//long? spaceId = null; | ||
//EntityQueryFilter filter = null; | ||
//var response = ChargeAttemptService.Count(spaceId, filter); | ||
//Assert.IsInstanceOf<long?> (response, "response is long?"); | ||
} | ||
|
||
/// <summary> | ||
/// Test Read | ||
/// </summary> | ||
public void ReadTest() | ||
{ | ||
// TODO uncomment below to test the method and replace null with proper value | ||
//long? spaceId = null; | ||
//long? id = null; | ||
//var response = ChargeAttemptService.Read(spaceId, id); | ||
//Assert.IsInstanceOf<ChargeAttempt> (response, "response is ChargeAttempt"); | ||
} | ||
|
||
/// <summary> | ||
/// Test Search | ||
/// Search() should find charge attempts by given criteria | ||
/// </summary> | ||
[Test] | ||
public void SearchTest() | ||
{ | ||
try{ | ||
Transaction transaction = this.TransactionService.Create(this.SpaceId, this.GetTransactionPayload()); | ||
|
||
EntityQueryFilter entityQueryFilter = new EntityQueryFilter(EntityQueryFilterType.LEAF); | ||
entityQueryFilter.FieldName = "charge.transaction.id"; | ||
entityQueryFilter.Value = transaction.Id; | ||
entityQueryFilter.Operator = CriteriaOperator.EQUALS; | ||
|
||
EntityQuery entityQuery = new EntityQuery(); | ||
entityQuery.Filter = entityQueryFilter; | ||
|
||
var response = this.ChargeAttemptService.Search(this.SpaceId, entityQuery); | ||
Assert.IsInstanceOf<List<ChargeAttempt>> (response, "response is List<ChargeAttempt>"); | ||
} catch (Wallee.Client.ApiException e){ | ||
Console.WriteLine("IOException source: {0}", e.Message); | ||
} | ||
|
||
var transactionCreate = Constants.GetTransactionCreate(); | ||
transactionCreate.TokenizationMode = TokenizationMode.FORCE_CREATION; | ||
transactionCreate.CustomersPresence = CustomersPresence.NOT_PRESENT; | ||
transactionCreate.CompletionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED; | ||
var transaction = transactionService.Create(Constants.SpaceId, transactionCreate); | ||
|
||
var transactionProcessed = cardProcessingService.Process(Constants.SpaceId, transaction.Id, | ||
Constants.TestCardPaymentMethodConfigurationId, Constants.FakeCardData); | ||
|
||
Assert.AreEqual(TransactionState.AUTHORIZED, transactionProcessed.State, "State must be AUTHORIZED"); | ||
|
||
var queryFilter = new EntityQueryFilter(EntityQueryFilterType.LEAF){ | ||
FieldName = "charge.transaction.id", | ||
Value = transaction.Id, | ||
Operator = CriteriaOperator.EQUALS | ||
}; | ||
var attemptsFound = chargeAttemptService.Search(Constants.SpaceId, new EntityQuery(){ | ||
Filter = queryFilter | ||
}); | ||
|
||
Assert.That(attemptsFound.Count > 0, "Should find a charge attempt"); | ||
attemptsFound.ForEach(attempt => { | ||
Assert.AreEqual(transaction.Id, attempt.LinkedTransaction, "Transaction ids should match"); | ||
}); | ||
} | ||
|
||
} | ||
|
||
} | ||
// TODO write more API tests | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Collections.Generic; | ||
|
||
using Wallee.Model; | ||
using Wallee.Service; | ||
using Wallee.Client; | ||
|
||
namespace Wallee.Test | ||
{ | ||
public class Constants | ||
{ | ||
private static readonly string ApplicationUserId = "512"; | ||
private static readonly string AuthenticationKey = "FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ="; | ||
public static readonly Configuration Config = new Configuration(ApplicationUserId, AuthenticationKey); | ||
|
||
public static readonly long SpaceId = 405; | ||
public static readonly long TestCardPaymentMethodConfigurationId = 1352; | ||
public static readonly long TestIsrInvoicePaymentMethodConfigurationId = 8656; | ||
public static readonly string TestCustomerId = "7311742"; | ||
|
||
public static readonly AuthenticatedCardDataCreate FakeCardData = new AuthenticatedCardDataCreate("4111111111111111"){ | ||
ExpiryDate = "2026-12" | ||
}; | ||
|
||
// <summary> | ||
// Get transaction payload | ||
// <summary> | ||
public static TransactionCreate GetTransactionCreate() | ||
{ | ||
var lineItem1 = new LineItemCreate( | ||
name: "Red T-Shirt", | ||
uniqueId: "5412", | ||
type: LineItemType.PRODUCT, | ||
quantity: 1, | ||
amountIncludingTax: 88.95m | ||
) | ||
{ | ||
Sku = "red-t-shirt-123" | ||
}; | ||
|
||
var address = new AddressCreate | ||
{ | ||
City = "Winterthur", | ||
Country = "CH", | ||
EmailAddress = "[email protected]", | ||
FamilyName = "Customer", | ||
GivenName = "Good", | ||
Postcode = "8400", | ||
PostalState = "ZH", | ||
OrganizationName = "Test GmbH", | ||
MobilePhoneNumber = "+41791234567", | ||
Salutation = "Ms" | ||
}; | ||
|
||
return new TransactionCreate(new List<LineItemCreate>() { lineItem1 }) | ||
{ | ||
Currency = "CHF", | ||
AutoConfirmationEnabled = true, | ||
BillingAddress = address, | ||
ShippingAddress = address, | ||
Language = "en-GB" | ||
}; | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.