Skip to content
This repository was archived by the owner on Nov 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions source/XeroApi.ConsoleTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System.IO;
using System.Linq;
using DevDefined.OAuth.Utility;
using XeroApi.Model;
using XeroApi.Model;
using XeroApi.Model.Constants;
using XeroApi.Model.Reporting;

namespace XeroApi.ConsoleApp
Expand Down Expand Up @@ -61,6 +62,7 @@ static void ExerciseOrganisation(Repository repository)
TestFindingTrackingCategories(repository);
TestFindingItemsUsingLinqSyntax(repository, organisation);
TestCreatingInvoiceWithValidationErrors(repository);
TestCreatingInvoiceWithValuesFromStringConstants(repository);
TestAttachmentFromByteArray(repository);
TestAttachmentsAgainstPurchaseInvoice(repository);

Expand Down Expand Up @@ -359,7 +361,7 @@ private static void TestFindingInvoicesByContactName(Repository repository, Cont
private static void TestCreatingInvoiceWithValidationErrors(Repository repository)
{
// Try and create an invoice - but using incorrect data. This should hopefully be rejected by the Xero API
Invoice invoiceToCreate = new Invoice
var invoiceToCreate = new Invoice
{
Contact = new Contact
{
Expand Down Expand Up @@ -392,6 +394,43 @@ private static void TestCreatingInvoiceWithValidationErrors(Repository repositor
}
}

private static void TestCreatingInvoiceWithValuesFromStringConstants(Repository repository)
{
var contact = repository.Contacts.FirstOrDefault() ?? new Contact
{
Name = "Test Contact",
};

// Try and create an invoice with correct data. But using values that would be passed in as strings from helper class
var invoiceToCreate = new Invoice
{
Type = InvoiceTypes.AccountsReceivable,
Status = InvoiceStatusCodes.Draft,
Contact = contact,
Date = DateTime.Today,
DueDate = DateTime.Today.AddDays(30),
LineAmountTypes = LineAmountType.NoTax,
LineItems = new LineItems
{
new LineItem
{
Description = "New Item",
Quantity = 1,
UnitAmount = 300,
TaxType = LineItemTaxTypes.NewZealand.ZeroRated
}
}
};

Console.WriteLine("Creating an invoice that should cause a validation error...");
var createdInvoice = repository.Create(invoiceToCreate);

if (createdInvoice.ValidationStatus == ValidationStatus.OK)
{
Console.WriteLine("Invoice created successfully");
}
}

private static void TestFindingItemsUsingLinqSyntax(Repository repository, Organisation organisation)
{
// Try the linq syntax to select items with sales details..
Expand Down
30 changes: 30 additions & 0 deletions source/XeroApi/Model/Constants/InvoiceStatusCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace XeroApi.Model.Constants
{
public class InvoiceStatusCodes
{
public static string Draft
{
get { return "DRAFT"; }
}
public static string Submitted
{
get { return "SUBMITTED"; }
}
public static string Deleted
{
get { return "DELETED"; }
}
public static string Authorised
{
get { return "AUTHORISED"; }
}
public static string Paid
{
get { return "PAID"; }
}
public static string Voided
{
get { return "VOIDED"; }
}
}
}
15 changes: 15 additions & 0 deletions source/XeroApi/Model/Constants/InvoiceTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace XeroApi.Model.Constants
{
public class InvoiceTypes
{
public static string AccountsPayable
{
get { return "ACCPAY"; }
}

public static string AccountsReceivable
{
get { return "ACCREC"; }
}
}
}
201 changes: 201 additions & 0 deletions source/XeroApi/Model/Constants/LineItemTaxTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
namespace XeroApi.Model.Constants
{
public class LineItemTaxTypes
{
public class NewZealand
{
public static string Input
{
get { return "INPUT"; }
}
public static string Input2
{
get { return "INPUT2"; }
}
public static string None
{
get { return "NONE"; }
}
public static string ZeroRated
{
get { return "ZERORATED"; }
}
public static string Output
{
get { return "OUTPUT"; }
}
public static string Output2
{
get { return "OUTPUT2"; }
}
}

public class UnitedKingdom
{
public static string Capexinput
{
get { return "CAPEXINPUT"; }
}
public static string Capexoutput
{
get { return "CAPEXOUTPUT"; }
}
public static string Capexinput2
{
get { return "CAPEXINPUT2"; }
}
public static string Capexoutput2
{
get { return "CAPEXOUTPUT2"; }
}
public static string Eczrinput
{
get { return "ECZRINPUT"; }
}
public static string Eczroutput
{
get { return "ECZROUTPUT"; }
}
public static string Exemptinput
{
get { return "EXEMPTINPUT"; }
}
public static string Exemptoutput
{
get { return "EXEMPTOUTPUT"; }
}
public static string Input
{
get { return "INPUT"; }
}
public static string Input2
{
get { return "INPUT2"; }
}
public static string None
{
get { return "NONE"; }
}
public static string Output
{
get { return "OUTPUT"; }
}
public static string Output2
{
get { return "OUTPUT2"; }
}
public static string Rrinput
{
get { return "RRINPUT"; }
}
public static string Rroutput
{
get { return "RROUTPUT"; }
}
public static string Srinput
{
get { return "SRINPUT"; }
}
public static string Sroutput
{
get { return "SROUTPUT"; }
}
public static string ZeroRatedInput
{
get { return "ZERORATEDINPUT"; }
}
public static string ZeroRatedOutput
{
get { return "ZERORATEDOUTPUT"; }
}
}

public class Australia
{
public static string Output
{
get { return "OUTPUT"; }
}
public static string Input
{
get { return "INPUT"; }
}
public static string Capexinput
{
get { return "CAPEXINPUT"; }
}
public static string Exemptexport
{
get { return "EXEMPTEXPORT"; }
}
public static string Exemptexpenses
{
get { return "EXEMPTEXPENSES"; }
}
public static string Exemptcapital
{
get { return "EXEMPTCAPITAL"; }
}
public static string Exemptoutput
{
get { return "EXEMPTOUTPUT"; }
}
public static string Inputtaxed
{
get { return "INPUTTAXED"; }
}
public static string Basexcluded
{
get { return "BASEXCLUDED"; }
}
public static string Gstoncapimports
{
get { return "GSTONCAPIMPORTS"; }
}
public static string Gstonimports
{
get { return "GSTONIMPORTS"; }
}
}

public class Global
{
public static string Input
{
get { return "INPUT"; }
}
public static string None
{
get { return "NONE"; }
}
public static string Output
{
get { return "OUTPUT"; }
}
public static string Gstonimports
{
get { return "GSTONIMPORTS"; }
}
}

public class UnitedStates
{
public static string Input
{
get { return "INPUT"; }
}
public static string None
{
get { return "NONE"; }
}
public static string Output
{
get { return "OUTPUT"; }
}
public static string Gstonimports
{
get { return "GSTONIMPORTS"; }
}
}
}
}
3 changes: 3 additions & 0 deletions source/XeroApi/XeroApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<Compile Include="Model\Attachment.cs" />
<Compile Include="Model\BankTransaction.cs" />
<Compile Include="Model\BrandingTheme.cs" />
<Compile Include="Model\Constants\InvoiceStatusCodes.cs" />
<Compile Include="Model\Constants\InvoiceTypes.cs" />
<Compile Include="Model\Constants\LineItemTaxTypes.cs" />
<Compile Include="Model\ContactGroup.cs" />
<Compile Include="Model\CreditNote.cs" />
<Compile Include="Model\Currency.cs" />
Expand Down