From 086e7992fe678e4a00df58369aec2cfcbacea27c Mon Sep 17 00:00:00 2001 From: amhed Date: Thu, 18 Jul 2013 12:51:29 -0400 Subject: [PATCH] Adding example of string constants to pass parameters with ease --- source/XeroApi.ConsoleTests/Program.cs | 43 +++- .../Model/Constants/InvoiceStatusCodes.cs | 30 +++ .../XeroApi/Model/Constants/InvoiceTypes.cs | 15 ++ .../Model/Constants/LineItemTaxTypes.cs | 201 ++++++++++++++++++ source/XeroApi/XeroApi.csproj | 3 + 5 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 source/XeroApi/Model/Constants/InvoiceStatusCodes.cs create mode 100644 source/XeroApi/Model/Constants/InvoiceTypes.cs create mode 100644 source/XeroApi/Model/Constants/LineItemTaxTypes.cs diff --git a/source/XeroApi.ConsoleTests/Program.cs b/source/XeroApi.ConsoleTests/Program.cs index a2110a4..a777848 100644 --- a/source/XeroApi.ConsoleTests/Program.cs +++ b/source/XeroApi.ConsoleTests/Program.cs @@ -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 @@ -61,6 +62,7 @@ static void ExerciseOrganisation(Repository repository) TestFindingTrackingCategories(repository); TestFindingItemsUsingLinqSyntax(repository, organisation); TestCreatingInvoiceWithValidationErrors(repository); + TestCreatingInvoiceWithValuesFromStringConstants(repository); TestAttachmentFromByteArray(repository); TestAttachmentsAgainstPurchaseInvoice(repository); @@ -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 { @@ -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.. diff --git a/source/XeroApi/Model/Constants/InvoiceStatusCodes.cs b/source/XeroApi/Model/Constants/InvoiceStatusCodes.cs new file mode 100644 index 0000000..fd369f5 --- /dev/null +++ b/source/XeroApi/Model/Constants/InvoiceStatusCodes.cs @@ -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"; } + } + } +} diff --git a/source/XeroApi/Model/Constants/InvoiceTypes.cs b/source/XeroApi/Model/Constants/InvoiceTypes.cs new file mode 100644 index 0000000..b437810 --- /dev/null +++ b/source/XeroApi/Model/Constants/InvoiceTypes.cs @@ -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"; } + } + } +} diff --git a/source/XeroApi/Model/Constants/LineItemTaxTypes.cs b/source/XeroApi/Model/Constants/LineItemTaxTypes.cs new file mode 100644 index 0000000..ef28e8f --- /dev/null +++ b/source/XeroApi/Model/Constants/LineItemTaxTypes.cs @@ -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"; } + } + } + } +} diff --git a/source/XeroApi/XeroApi.csproj b/source/XeroApi/XeroApi.csproj index 3ba7606..313b379 100644 --- a/source/XeroApi/XeroApi.csproj +++ b/source/XeroApi/XeroApi.csproj @@ -66,6 +66,9 @@ + + +