This repository has been archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #398 from LukeKirbyDG/bugfix-batchpayments
Changes to BatchPayment to avoid timezone Issue
- Loading branch information
Showing
4 changed files
with
119 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xero.Api.Core.Model; | ||
using Xero.Api.Core.Model.Status; | ||
using Xero.Api.Core.Model.Types; | ||
|
||
namespace CoreTests.Integration.BatchPayments | ||
{ | ||
public abstract class BatchPaymentsTest : ApiWrapperTest | ||
{ | ||
protected BatchPayment Given_a_batch_payment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false) | ||
{ | ||
var batchPayment = CreateBatchPayment(invoiceAmount, date, amount, isReconciled); | ||
|
||
return Api.BatchPayments.Create(batchPayment); | ||
} | ||
|
||
protected BatchPayment CreateBatchPayment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false) | ||
{ | ||
var invoice = Given_an_invoice(invoiceAmount, Account.Code); | ||
var bankCode = BankAccount.Id; | ||
|
||
var payment = new BatchPayment | ||
{ | ||
Account = new Account { Id = bankCode }, | ||
Date = date, | ||
Payments = new List<BatchPaymentPayment> { new BatchPaymentPayment { | ||
Amount = amount, | ||
Invoice = new Invoice { Id = invoice.Id}, | ||
BankAccountNumber = BankAccount.BankAccountNumber, | ||
}} | ||
}; | ||
|
||
if (isReconciled) | ||
{ | ||
payment.IsReconciled = true; | ||
} | ||
|
||
return payment; | ||
} | ||
|
||
private Invoice Given_an_invoice(decimal amount = 100m, string accountCode = "100") | ||
{ | ||
return Api.Create(new Invoice | ||
{ | ||
Contact = new Contact { Name = "Richard" }, | ||
Number = Random.GetRandomString(10), | ||
Type = InvoiceType.AccountsPayable, | ||
Date = DateTime.UtcNow, | ||
DueDate = DateTime.UtcNow.AddDays(90), | ||
LineAmountTypes = LineAmountType.Inclusive, | ||
Status = InvoiceStatus.Authorised, | ||
LineItems = new List<LineItem> | ||
{ | ||
new LineItem | ||
{ | ||
AccountCode = accountCode, | ||
Description = "Good value item", | ||
LineAmount = amount | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} | ||
} |
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,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using Xero.Api.Core.Model; | ||
|
||
namespace CoreTests.Integration.BatchPayments | ||
{ | ||
[TestFixture] | ||
public class Create : BatchPaymentsTest | ||
{ | ||
[TestFixtureSetUp] | ||
public void CreateBatchPaymentsSetUp() | ||
{ | ||
SetUp(); | ||
} | ||
|
||
[Test] | ||
public void create_simple_batch_payment() | ||
{ | ||
var date = DateTime.UtcNow; | ||
const decimal expectedTotal = 32.6m; | ||
const decimal invoiceAmount = 100; | ||
|
||
var batchPayment = Given_a_batch_payment(invoiceAmount, date, expectedTotal); | ||
|
||
Assert.IsNotNull(batchPayment); | ||
|
||
Assert.AreEqual(expectedTotal, batchPayment.Total); | ||
Assert.AreEqual(date.Date, batchPayment.Date); | ||
|
||
|
||
} | ||
|
||
} | ||
} |
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