Repository: XeroAPI/Xero-Net
Branch: master
Commit: 9dd5645f3cc4
Files: 799
Total size: 9.7 MB
Directory structure:
gitextract_xmz3hwlp/
├── .gitignore
├── CoreTests/
│ ├── ApiWrapperTest.cs
│ ├── App.config
│ ├── CoreTests.csproj
│ ├── Integration/
│ │ ├── Accounts/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ ├── Allocations/
│ │ │ └── Add.cs
│ │ ├── Attachments/
│ │ │ └── Attachments.cs
│ │ ├── BankTransactionTest.cs
│ │ ├── BankTransactions/
│ │ │ ├── BankTransactionTest.cs
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ ├── BankTransfers/
│ │ │ ├── BankTransfersTest.cs
│ │ │ ├── Create.cs
│ │ │ └── Find.cs
│ │ ├── BatchPayment/
│ │ │ ├── BatchPaymentsTest.cs
│ │ │ └── Create.cs
│ │ ├── ContactGroups/
│ │ │ ├── Add_Contact.cs
│ │ │ ├── ContactGroupsTest.cs
│ │ │ ├── Create.cs
│ │ │ ├── Delete.cs
│ │ │ ├── Find.cs
│ │ │ ├── Remove_Contact.cs
│ │ │ └── Update.cs
│ │ ├── Contacts/
│ │ │ ├── ContactsTest.cs
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ ├── CreditNotes/
│ │ │ ├── Create.cs
│ │ │ ├── CreditNotesTest.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ ├── ExpenseClaims/
│ │ │ ├── Create.cs
│ │ │ ├── ExpenseClaimTest.cs
│ │ │ └── Update.cs
│ │ ├── Files/
│ │ │ ├── Associations/
│ │ │ │ └── AssociationTest.cs
│ │ │ ├── Files/
│ │ │ │ └── AddFileTest.cs
│ │ │ ├── Folders/
│ │ │ │ └── AddFolderTest.cs
│ │ │ ├── Inbox/
│ │ │ │ └── InboxTest.cs
│ │ │ └── Support/
│ │ │ ├── DataItem.cs
│ │ │ ├── DiskFile.cs
│ │ │ ├── File.cs
│ │ │ └── FilesTest.cs
│ │ ├── General/
│ │ │ ├── Errors.cs
│ │ │ ├── FindingAllItems.cs
│ │ │ └── QueryStrings.cs
│ │ ├── HistoryAndNotes/
│ │ │ ├── CreateNotes.cs
│ │ │ ├── Find.cs
│ │ │ └── HistoryAndNotesTest.cs
│ │ ├── Invoices/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ ├── InvoicesTest.cs
│ │ │ ├── OnlineInvoiceUrl.cs
│ │ │ └── SummarizeErrors.cs
│ │ ├── Items/
│ │ │ ├── Create.cs
│ │ │ ├── Delete.cs
│ │ │ ├── TrackedItems/
│ │ │ │ ├── Create.cs
│ │ │ │ ├── Find.cs
│ │ │ │ ├── TrackedInventoryTest.cs
│ │ │ │ ├── Update.cs
│ │ │ │ └── Using_tracked_items.cs
│ │ │ └── Update.cs
│ │ ├── Journals/
│ │ │ └── Find.cs
│ │ ├── LinkedTransactions/
│ │ │ ├── Create.cs
│ │ │ ├── Delete.cs
│ │ │ ├── Find.cs
│ │ │ ├── LinkedTransactionTest.cs
│ │ │ └── Update.cs
│ │ ├── ManualJournals/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ ├── ManualJournalsTest.cs
│ │ │ └── Update.cs
│ │ ├── Organisation/
│ │ │ └── Find.cs
│ │ ├── Overpayments/
│ │ │ └── Find.cs
│ │ ├── Payments/
│ │ │ ├── Create.cs
│ │ │ ├── CreateForeignCurrency.cs
│ │ │ ├── Delete.cs
│ │ │ ├── Find.cs
│ │ │ └── PaymentsTest.cs
│ │ ├── Pdf/
│ │ │ └── Get.cs
│ │ ├── Prepayments/
│ │ │ └── Find.cs
│ │ ├── PurchaseOrders/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ ├── Receipts/
│ │ │ ├── Create.cs
│ │ │ ├── ReceiptTest.cs
│ │ │ └── Update.cs
│ │ ├── Reports/
│ │ │ └── Find.cs
│ │ ├── Setup/
│ │ │ └── Create.cs
│ │ ├── TaxRates/
│ │ │ ├── Create.cs
│ │ │ ├── TaxRateTest.cs
│ │ │ └── Update.cs
│ │ └── TrackingCategories/
│ │ ├── AddTrackingOption.cs
│ │ ├── Adding/
│ │ │ └── CreateTrackingCategories.cs
│ │ ├── ArchiveTrackingCategory.cs
│ │ ├── CreateTrackingCategories.cs
│ │ ├── Delete.cs
│ │ ├── GetTrackingCategories.cs
│ │ ├── GetTrackingCategoriesIncludingArchieved.cs
│ │ ├── Options/
│ │ │ └── AddTrackingOption.cs
│ │ ├── TrackingCategoriesTest.cs
│ │ ├── UpdateTrackingCategory.cs
│ │ └── UpdateTrackingOptions.cs
│ ├── README.md
│ ├── Random.cs
│ ├── Resources/
│ │ └── cert/
│ │ └── public_privatekey.txt
│ ├── Unit/
│ │ ├── Contacts.cs
│ │ ├── ExceptionTests.cs
│ │ ├── FourDecimalPlaces.cs
│ │ ├── QueryStrings.cs
│ │ ├── RateLimiterTest.cs
│ │ ├── SalesTaxBasisTypeTest.cs
│ │ ├── SalesTaxPeriodTypeTest.cs
│ │ ├── SummarizeErrors.cs
│ │ ├── TrackingCategories.cs
│ │ └── UrlEncoder.cs
│ └── packages.config
├── PayrollTests.AU/
│ ├── ApiWrapperTest.cs
│ ├── App.config
│ ├── Integration/
│ │ ├── Employees/
│ │ │ ├── Create.cs
│ │ │ ├── EmployeesTest.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ ├── LeaveApplications/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── LeaveApplicationTest.cs
│ │ ├── PayItems/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── PayItemsTest.cs
│ │ ├── PayrollCalendars/
│ │ │ ├── Create.cs
│ │ │ └── Find.cs
│ │ ├── Payrun/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── PayrunTest.cs
│ │ ├── Settings/
│ │ │ └── Find.cs
│ │ ├── SuperFundProducts/
│ │ │ └── Find.cs
│ │ ├── SuperFunds/
│ │ │ ├── Create.cs
│ │ │ └── Update.cs
│ │ ├── TimeSheets/
│ │ │ ├── Create.cs
│ │ │ ├── Find.cs
│ │ │ └── TimesheetTest.cs
│ │ └── ValidationErrors/
│ │ └── AUPayrollValidationErrors.cs
│ ├── PayrollTests.AU.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── README.md
│ ├── Resources/
│ │ └── cert/
│ │ └── public_privatekey.txt
│ └── packages.config
├── PayrollTests.US/
│ ├── ApiWrapperTest.cs
│ ├── App.config
│ ├── Integration/
│ │ ├── Employees/
│ │ │ ├── Create.cs
│ │ │ ├── EmployeesTest.cs
│ │ │ ├── Find.cs
│ │ │ └── Update.cs
│ │ └── PaySchedules/
│ │ ├── Create.cs
│ │ ├── Find.cs
│ │ └── PaySchedulesTest.cs
│ ├── PayrollTests.US.csproj
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── README.md
│ ├── Resources/
│ │ └── cert/
│ │ └── public_privatekey.txt
│ └── packages.config
├── README.md
├── UpgradeLog.htm
├── Xero.Api/
│ ├── Common/
│ │ ├── CoreData.cs
│ │ ├── Extensions.cs
│ │ ├── HasUpdatedDate.cs
│ │ ├── IHasAttachment.cs
│ │ ├── IHasId.cs
│ │ ├── IPageableEndpoint.cs
│ │ ├── IXeroReadEndpoint.cs
│ │ ├── MimeTypes.cs
│ │ ├── QueryGenerator.cs
│ │ ├── XeroApi.cs
│ │ ├── XeroReadEndpoint.cs
│ │ ├── XeroRequest.cs
│ │ └── XeroResponse.cs
│ ├── Core/
│ │ ├── Endpoints/
│ │ │ ├── AccountsEndpoint.cs
│ │ │ ├── AllocationEndpoint.cs
│ │ │ ├── AssociationsEndpoint.cs
│ │ │ ├── AttachmentsEndpoint.cs
│ │ │ ├── BankTransactionsEndpoint.cs
│ │ │ ├── BankTransfersEndpoint.cs
│ │ │ ├── Base/
│ │ │ │ ├── FourDecimalPlacesEndpoint.cs
│ │ │ │ ├── IXeroCreateEndpoint.cs
│ │ │ │ ├── IXeroUpdateEndpoint.cs
│ │ │ │ ├── XeroCreateEndpoint.cs
│ │ │ │ └── XeroUpdateEndpoint.cs
│ │ │ ├── BatchPaymentsEndpoint.cs
│ │ │ ├── BrandingThemesEndpoint.cs
│ │ │ ├── ContactGroupEndpoint.cs
│ │ │ ├── ContactsEndpoint.cs
│ │ │ ├── CreditNotesEndpoint.cs
│ │ │ ├── CurrenciesEndpoint.cs
│ │ │ ├── EmployeesEndpoint.cs
│ │ │ ├── ExpenseClaimsEndpoint.cs
│ │ │ ├── FilesEndpoint.cs
│ │ │ ├── FoldersEndpoint.cs
│ │ │ ├── HistoryAndNotesEndpoint.cs
│ │ │ ├── InboxEndpoint.cs
│ │ │ ├── InvoicesEndpoint.cs
│ │ │ ├── ItemsEndpoint.cs
│ │ │ ├── JournalsEndpoint.cs
│ │ │ ├── LinkedTransactionsEndpoint.cs
│ │ │ ├── ManualJournalsEndpoint.cs
│ │ │ ├── OrganisationEndpoint.cs
│ │ │ ├── OverpaymentsEndpoint.cs
│ │ │ ├── PaymentsEndpoint.cs
│ │ │ ├── PdfEndpoint.cs
│ │ │ ├── PrepaymentsEndpoint.cs
│ │ │ ├── PurchaseOrdersEndpoint.cs
│ │ │ ├── ReceiptsEndpoint.cs
│ │ │ ├── RepeatingInvoicesEndpoint.cs
│ │ │ ├── ReportsEndpoint.cs
│ │ │ ├── SetupEndpoint.cs
│ │ │ ├── TaxRatesEndpoint.cs
│ │ │ ├── TrackingCategoriesEndpoint.cs
│ │ │ └── UsersEndpoint.cs
│ │ ├── File/
│ │ │ └── BinaryFile.cs
│ │ ├── IXeroCoreApi.cs
│ │ ├── Model/
│ │ │ ├── Account.cs
│ │ │ ├── Address.cs
│ │ │ ├── Allocation.cs
│ │ │ ├── AllocationBase.cs
│ │ │ ├── Association.cs
│ │ │ ├── Attachment.cs
│ │ │ ├── Balance.cs
│ │ │ ├── Balances.cs
│ │ │ ├── BankTransaction.cs
│ │ │ ├── BankTransfer.cs
│ │ │ ├── BatchPayment.cs
│ │ │ ├── BatchPaymentContactDefaults.cs
│ │ │ ├── BatchPaymentPayment.cs
│ │ │ ├── BrandingTheme.cs
│ │ │ ├── Contact.cs
│ │ │ ├── ContactCisSetting.cs
│ │ │ ├── ContactGroup.cs
│ │ │ ├── ContactPerson.cs
│ │ │ ├── ContactTrackingCategory.cs
│ │ │ ├── CreditNote.cs
│ │ │ ├── CreditNoteAllocation.cs
│ │ │ ├── Currency.cs
│ │ │ ├── Employee.cs
│ │ │ ├── EnumExtensions.cs
│ │ │ ├── ExpenseClaim.cs
│ │ │ ├── ExternalLink.cs
│ │ │ ├── File.cs
│ │ │ ├── FilePage.cs
│ │ │ ├── FilesUser.cs
│ │ │ ├── Folder.cs
│ │ │ ├── HistoryRecord.cs
│ │ │ ├── Invoice.cs
│ │ │ ├── Item.cs
│ │ │ ├── ItemDetails.cs
│ │ │ ├── ItemTracking.cs
│ │ │ ├── ItemTrackingCategory.cs
│ │ │ ├── Journal.cs
│ │ │ ├── Line.cs
│ │ │ ├── LineItem.cs
│ │ │ ├── LinkedTransaction.cs
│ │ │ ├── ManualJournal.cs
│ │ │ ├── OnlineInvoice.cs
│ │ │ ├── Option.cs
│ │ │ ├── Organisation.cs
│ │ │ ├── OrganisationCisSetting.cs
│ │ │ ├── Overpayment.cs
│ │ │ ├── OverpaymentAllocation.cs
│ │ │ ├── Payment.cs
│ │ │ ├── PaymentTerms.cs
│ │ │ ├── Phone.cs
│ │ │ ├── Prepayment.cs
│ │ │ ├── PrepaymentAllocation.cs
│ │ │ ├── PurchaseDetails.cs
│ │ │ ├── PurchaseOrder.cs
│ │ │ ├── Receipt.cs
│ │ │ ├── RepeatingInvoice.cs
│ │ │ ├── Reports/
│ │ │ │ ├── Report.cs
│ │ │ │ ├── ReportAttribute.cs
│ │ │ │ ├── ReportCell.cs
│ │ │ │ ├── ReportCellAttribute.cs
│ │ │ │ ├── ReportField.cs
│ │ │ │ └── ReportRow.cs
│ │ │ ├── SalesDetails.cs
│ │ │ ├── Schedule.cs
│ │ │ ├── Setup/
│ │ │ │ ├── AccountImportResult.cs
│ │ │ │ ├── ContactImportResult.cs
│ │ │ │ ├── ConversionBalance.cs
│ │ │ │ ├── ConversionDate.cs
│ │ │ │ ├── ConversionDetails.cs
│ │ │ │ ├── ImportSummary.cs
│ │ │ │ ├── OrganisationImportResult.cs
│ │ │ │ └── Setup.cs
│ │ │ ├── Status/
│ │ │ │ ├── AccountStatus.cs
│ │ │ │ ├── BankTransactionStatus.cs
│ │ │ │ ├── BatchPaymentStatus.cs
│ │ │ │ ├── ContactStatus.cs
│ │ │ │ ├── EmployeeStatus.cs
│ │ │ │ ├── ExpenseClaimStatus.cs
│ │ │ │ ├── InvoiceStatus.cs
│ │ │ │ ├── LinkedTransactionStatus.cs
│ │ │ │ ├── ManualJournalStatus.cs
│ │ │ │ ├── OrganisationStatus.cs
│ │ │ │ ├── OverpaymentStatus.cs
│ │ │ │ ├── PaymentStatus.cs
│ │ │ │ ├── PrepaymentStatus.cs
│ │ │ │ ├── PurchaseOrderStatus.cs
│ │ │ │ ├── ReceiptStatus.cs
│ │ │ │ ├── TaxRateStatus.cs
│ │ │ │ ├── TrackingCategoryStatus.cs
│ │ │ │ ├── TrackingOptionStatus.cs
│ │ │ │ └── ValidationStatus.cs
│ │ │ ├── TaxComponent.cs
│ │ │ ├── TaxRate.cs
│ │ │ ├── Terms.cs
│ │ │ ├── TrackingCategory.cs
│ │ │ ├── Types/
│ │ │ │ ├── AccountClassType.cs
│ │ │ │ ├── AccountType.cs
│ │ │ │ ├── AddressType.cs
│ │ │ │ ├── AttachmentEndpointType.cs
│ │ │ │ ├── BankAccountType.cs
│ │ │ │ ├── BankTransactionType.cs
│ │ │ │ ├── BatchPaymentType.cs
│ │ │ │ ├── BudgetSummaryTimeframeType.cs
│ │ │ │ ├── CreditNoteType.cs
│ │ │ │ ├── ExternalLinkType.cs
│ │ │ │ ├── HistoryAndNotesEndpointCreateType.cs
│ │ │ │ ├── HistoryAndNotesEndpointRetrieveType.cs
│ │ │ │ ├── InvoiceType.cs
│ │ │ │ ├── LineAmountType.cs
│ │ │ │ ├── LinkedTransactionType.cs
│ │ │ │ ├── NamedReportType.cs
│ │ │ │ ├── ObjectGroupType.cs
│ │ │ │ ├── ObjectType.cs
│ │ │ │ ├── OrganisationClass.cs
│ │ │ │ ├── OrganisationEdition.cs
│ │ │ │ ├── OrganisationType.cs
│ │ │ │ ├── OrganisationVersion.cs
│ │ │ │ ├── OverpaymentType.cs
│ │ │ │ ├── PaymentTermType.cs
│ │ │ │ ├── PaymentType.cs
│ │ │ │ ├── PdfEndpointType.cs
│ │ │ │ ├── PhoneType.cs
│ │ │ │ ├── PrepaymentType.cs
│ │ │ │ ├── ReportRowType.cs
│ │ │ │ ├── ReportTaxType.cs
│ │ │ │ ├── SalesTaxBasisType.cs
│ │ │ │ ├── SalesTaxPeriodType.cs
│ │ │ │ ├── SourceType.cs
│ │ │ │ ├── SystemAccountType.cs
│ │ │ │ ├── UnitType.cs
│ │ │ │ └── UserRole.cs
│ │ │ └── User.cs
│ │ ├── Request/
│ │ │ ├── AccountsRequest.cs
│ │ │ ├── BankTransactionsRequest.cs
│ │ │ ├── BankTransfersRequest.cs
│ │ │ ├── BatchPaymentsRequest.cs
│ │ │ ├── ContactGroupsRequest.cs
│ │ │ ├── ContactsRequest.cs
│ │ │ ├── CreditNotesRequest.cs
│ │ │ ├── CurrenciesRequest.cs
│ │ │ ├── EmployeesRequest.cs
│ │ │ ├── ExpenseClaimsRequest.cs
│ │ │ ├── FilesRequest.cs
│ │ │ ├── HistoryRecordsRequest.cs
│ │ │ ├── InvoicesRequest.cs
│ │ │ ├── ItemsRequest.cs
│ │ │ ├── LinkedTransactionsRequest.cs
│ │ │ ├── ManualJournalsRequest.cs
│ │ │ ├── OnlineInvoicesRequest.cs
│ │ │ ├── PaymentsRequest.cs
│ │ │ ├── PurchaseOrdersRequest.cs
│ │ │ ├── ReceiptsRequest.cs
│ │ │ ├── SetupRequest.cs
│ │ │ ├── TaxRatesRequest.cs
│ │ │ └── TrackingCategoriesRequest.cs
│ │ ├── Response/
│ │ │ ├── AccountsResponse.cs
│ │ │ ├── AttachmentsResponse.cs
│ │ │ ├── BankTransactionsResponse.cs
│ │ │ ├── BankTransfersResponse.cs
│ │ │ ├── BatchPaymentsResponse.cs
│ │ │ ├── BrandingThemesResponse.cs
│ │ │ ├── ContactCisSettingsResponse.cs
│ │ │ ├── ContactGroupsResponse.cs
│ │ │ ├── ContactsResponse.cs
│ │ │ ├── CreditNotesResponse.cs
│ │ │ ├── CurrenciesResponse.cs
│ │ │ ├── EmployeesResponse.cs
│ │ │ ├── ExpenseClaimsResponse.cs
│ │ │ ├── FilesResponse.cs
│ │ │ ├── FoldersResponse.cs
│ │ │ ├── HistoryRecordsResponse.cs
│ │ │ ├── InboxResponse.cs
│ │ │ ├── InvoicesResponse.cs
│ │ │ ├── ItemsResponse.cs
│ │ │ ├── JournalsResponse.cs
│ │ │ ├── LinkedTransactionsResponse.cs
│ │ │ ├── ManualJournalsResponse.cs
│ │ │ ├── OnlineInvoicesResponse.cs
│ │ │ ├── OptionsResponse.cs
│ │ │ ├── OrganisationCisSettingsResponse.cs
│ │ │ ├── OrganisationResponse.cs
│ │ │ ├── OverpaymentsResponse.cs
│ │ │ ├── PaymentsResponse.cs
│ │ │ ├── PrepaymentsResponse.cs
│ │ │ ├── PurchaseOrdersResponse.cs
│ │ │ ├── ReceiptsResponse.cs
│ │ │ ├── RepeatingInvoicesResponse.cs
│ │ │ ├── ReportsResponse.cs
│ │ │ ├── SetupResponse.cs
│ │ │ ├── TaxRatesResponse.cs
│ │ │ ├── TrackingCategoriesResponse.cs
│ │ │ └── UsersResponse.cs
│ │ └── XeroCoreApi.cs
│ ├── Infrastructure/
│ │ ├── Exceptions/
│ │ │ ├── ApiException.cs
│ │ │ ├── BadRequestException.cs
│ │ │ ├── NotAvailableException.cs
│ │ │ ├── NotFoundException.cs
│ │ │ ├── RateExceededException.cs
│ │ │ ├── UnauthorizedException.cs
│ │ │ ├── ValidationException.cs
│ │ │ └── XeroApiException.cs
│ │ ├── Http/
│ │ │ ├── HttpClient.cs
│ │ │ ├── Response.cs
│ │ │ └── XeroHttpClient.cs
│ │ ├── Interfaces/
│ │ │ ├── IAuthenticationToken.cs
│ │ │ ├── IAuthenticator.cs
│ │ │ ├── IConsumer.cs
│ │ │ ├── IJsonObjectMapper.cs
│ │ │ ├── ITokenStore.cs
│ │ │ ├── IUser.cs
│ │ │ ├── IXeroRequest.cs
│ │ │ ├── IXeroResponse.cs
│ │ │ └── IXmlObjectMapper.cs
│ │ ├── Model/
│ │ │ ├── DataContractBase.cs
│ │ │ ├── ValidationError.cs
│ │ │ └── Warning.cs
│ │ ├── OAuth/
│ │ │ ├── ApiUser.cs
│ │ │ ├── Consumer.cs
│ │ │ ├── OAuthException.cs
│ │ │ ├── OAuthTokens.cs
│ │ │ ├── Signing/
│ │ │ │ ├── HmacSha1Signer.cs
│ │ │ │ └── RsaSha1Signer.cs
│ │ │ ├── Token.cs
│ │ │ └── UnexpectedOauthResponseException.cs
│ │ ├── RateLimiter/
│ │ │ ├── IRateLimiter.cs
│ │ │ └── RateLimiter.cs
│ │ └── ThirdParty/
│ │ ├── Dust/
│ │ │ ├── ConsumerKey.cs
│ │ │ ├── Core/
│ │ │ │ ├── Request.cs
│ │ │ │ ├── SignatureBaseString.cs
│ │ │ │ └── SignatureBaseStringParts/
│ │ │ │ ├── Earl/
│ │ │ │ │ └── EarlPart.cs
│ │ │ │ ├── Parameters/
│ │ │ │ │ ├── Name.cs
│ │ │ │ │ ├── Nonce/
│ │ │ │ │ │ ├── DefaultNonceSequence.cs
│ │ │ │ │ │ └── NonceSequence.cs
│ │ │ │ │ ├── OAuthParameters.cs
│ │ │ │ │ ├── Parameter.cs
│ │ │ │ │ ├── ParameterEncoding.cs
│ │ │ │ │ ├── ParameterPart.cs
│ │ │ │ │ ├── Parameters.cs
│ │ │ │ │ ├── RequestParameters.cs
│ │ │ │ │ └── Timestamp/
│ │ │ │ │ ├── DefaultTimestampSequence.cs
│ │ │ │ │ └── TimestampSequence.cs
│ │ │ │ └── Verb/
│ │ │ │ └── VerbPart.cs
│ │ │ ├── HmacSha1.cs
│ │ │ ├── Http/
│ │ │ │ └── AuthorizationHeader.cs
│ │ │ ├── Lang/
│ │ │ │ └── ObjectExtensions.cs
│ │ │ ├── RsaSha1.cs
│ │ │ └── TokenKey.cs
│ │ ├── HttpUtility/
│ │ │ ├── HttpEncoder.cs
│ │ │ ├── HttpUtility.cs
│ │ │ └── UrlEncoder.cs
│ │ └── ServiceStack.Text/
│ │ ├── AssemblyUtils.cs
│ │ ├── CollectionExtensions.cs
│ │ ├── Common/
│ │ │ ├── DateTimeSerializer.cs
│ │ │ ├── DeserializeArray.cs
│ │ │ ├── DeserializeBuiltin.cs
│ │ │ ├── DeserializeCollection.cs
│ │ │ ├── DeserializeDictionary.cs
│ │ │ ├── DeserializeDynamic.cs
│ │ │ ├── DeserializeKeyValuePair.cs
│ │ │ ├── DeserializeListWithElements.cs
│ │ │ ├── DeserializeSpecializedCollections.cs
│ │ │ ├── DeserializeType.cs
│ │ │ ├── DeserializeTypeRef.cs
│ │ │ ├── DeserializeTypeRefJson.cs
│ │ │ ├── DeserializeTypeRefJsv.cs
│ │ │ ├── DeserializeTypeUtils.cs
│ │ │ ├── ITypeSerializer.cs
│ │ │ ├── JsDelegates.cs
│ │ │ ├── JsReader.cs
│ │ │ ├── JsState.cs
│ │ │ ├── JsWriter.cs
│ │ │ ├── ParseUtils.cs
│ │ │ ├── StaticParseMethod.cs
│ │ │ ├── WriteDictionary.cs
│ │ │ ├── WriteLists.cs
│ │ │ └── WriteType.cs
│ │ ├── Controller/
│ │ │ ├── CommandProcessor.cs
│ │ │ └── PathInfo.cs
│ │ ├── CsvAttribute.cs
│ │ ├── CsvConfig.cs
│ │ ├── CsvSerializer.cs
│ │ ├── CsvStreamExtensions.cs
│ │ ├── CsvWriter.cs
│ │ ├── DateTimeExtensions.cs
│ │ ├── DynamicJson.cs
│ │ ├── DynamicProxy.cs
│ │ ├── Env.cs
│ │ ├── HashSet.cs
│ │ ├── ITracer.cs
│ │ ├── ITypeSerializer.Generic.cs
│ │ ├── JsConfig.cs
│ │ ├── JsConfigScope.cs
│ │ ├── Json/
│ │ │ ├── JsonReader.Generic.cs
│ │ │ ├── JsonTypeSerializer.cs
│ │ │ ├── JsonUtils.cs
│ │ │ └── JsonWriter.Generic.cs
│ │ ├── JsonObject.cs
│ │ ├── JsonSerializer.Generic.cs
│ │ ├── JsonSerializer.cs
│ │ ├── Jsv/
│ │ │ ├── JsvDeserializeType.cs
│ │ │ ├── JsvReader.Generic.cs
│ │ │ ├── JsvSerializer.Generic.cs
│ │ │ ├── JsvTypeSerializer.cs
│ │ │ └── JsvWriter.Generic.cs
│ │ ├── JsvFormatter.cs
│ │ ├── ListExtensions.cs
│ │ ├── MapExtensions.cs
│ │ ├── Marc/
│ │ │ ├── Link.cs
│ │ │ ├── ObjectAccessor.cs
│ │ │ └── TypeAccessor.cs
│ │ ├── QueryStringSerializer.cs
│ │ ├── Reflection/
│ │ │ └── StaticAccessors.cs
│ │ ├── ReflectionExtensions.cs
│ │ ├── StreamExtensions.cs
│ │ ├── StringExtensions.cs
│ │ ├── Support/
│ │ │ ├── AssemblyTypeDefinition.cs
│ │ │ ├── DoubleConverter.cs
│ │ │ └── TypePair.cs
│ │ ├── SystemTime.cs
│ │ ├── TextExtensions.cs
│ │ ├── Tracer.cs
│ │ ├── TranslateListWithElements.cs
│ │ ├── TypeConfig.cs
│ │ ├── TypeSerializer.Generic.cs
│ │ ├── TypeSerializer.cs
│ │ ├── WebRequestExtensions.cs
│ │ └── XmlSerializer.cs
│ ├── Payroll/
│ │ ├── America/
│ │ │ ├── Endpoints/
│ │ │ │ ├── EmployeesEndpoint.cs
│ │ │ │ ├── PayItemsEndpoint.cs
│ │ │ │ ├── PayRunsEndpoint.cs
│ │ │ │ ├── PaySchedulesEndpoint.cs
│ │ │ │ ├── PayStubsEndpoint.cs
│ │ │ │ ├── SettingsEndpoint.cs
│ │ │ │ ├── TimesheetsEndpoint.cs
│ │ │ │ └── WorkLocationsEndpoint.cs
│ │ │ ├── Model/
│ │ │ │ ├── Account.cs
│ │ │ │ ├── Address.cs
│ │ │ │ ├── BankAccount.cs
│ │ │ │ ├── BenefitLine.cs
│ │ │ │ ├── BenefitType.cs
│ │ │ │ ├── DeductionLine.cs
│ │ │ │ ├── DeductionType.cs
│ │ │ │ ├── EarningsLine.cs
│ │ │ │ ├── EarningsType.cs
│ │ │ │ ├── Employee.cs
│ │ │ │ ├── HomeAddress.cs
│ │ │ │ ├── MailingAddress.cs
│ │ │ │ ├── OpeningBalances.cs
│ │ │ │ ├── PayItems.cs
│ │ │ │ ├── PayRun.cs
│ │ │ │ ├── PaySchedule.cs
│ │ │ │ ├── PayStub.cs
│ │ │ │ ├── PayTemplate.cs
│ │ │ │ ├── PaymentMethod.cs
│ │ │ │ ├── ReimbursementLine.cs
│ │ │ │ ├── ReimbursementType.cs
│ │ │ │ ├── SalaryAndWage.cs
│ │ │ │ ├── Settings.cs
│ │ │ │ ├── TimeOffType.cs
│ │ │ │ ├── Timesheet.cs
│ │ │ │ ├── TimesheetLine.cs
│ │ │ │ ├── Types/
│ │ │ │ │ ├── AccountType.cs
│ │ │ │ │ ├── BenefitCategoryType.cs
│ │ │ │ │ ├── CalculationType.cs
│ │ │ │ │ ├── DeductionCategoryType.cs
│ │ │ │ │ ├── EarningsCategoryType.cs
│ │ │ │ │ ├── EmploymentBasisType.cs
│ │ │ │ │ ├── PaymentMethodType.cs
│ │ │ │ │ ├── RateType.cs
│ │ │ │ │ ├── SalaryWagesType.cs
│ │ │ │ │ ├── ScheduleType.cs
│ │ │ │ │ ├── State.cs
│ │ │ │ │ ├── TimeOffCategoryType.cs
│ │ │ │ │ └── UnitType.cs
│ │ │ │ └── WorkLocation.cs
│ │ │ ├── Request/
│ │ │ │ ├── EmployeesRequest.cs
│ │ │ │ ├── PayItemsRequest.cs
│ │ │ │ ├── PayRunsRequest.cs
│ │ │ │ ├── PaySchedulesRequest.cs
│ │ │ │ ├── PayStubsRequest.cs
│ │ │ │ ├── TimesheetsRequest.cs
│ │ │ │ └── WorkLocationsRequest.cs
│ │ │ └── Response/
│ │ │ ├── EmployeesResponse.cs
│ │ │ ├── PayItemsResponse.cs
│ │ │ ├── PayRunsResponse.cs
│ │ │ ├── PaySchedulesResponse.cs
│ │ │ ├── PayStubsResponse.cs
│ │ │ ├── SettingsResponse.cs
│ │ │ ├── TimesheetsResponse.cs
│ │ │ └── WorkLocationsResponse.cs
│ │ ├── AmericanPayroll.cs
│ │ ├── Australia/
│ │ │ ├── Endpoints/
│ │ │ │ ├── EmployeesEndpoint.cs
│ │ │ │ ├── LeaveApplicationsEndpoint.cs
│ │ │ │ ├── PayItemsEndpoint.cs
│ │ │ │ ├── PayRunsEndpoint.cs
│ │ │ │ ├── PayrollCalendarsEndpoint.cs
│ │ │ │ ├── PayslipsEndpoint.cs
│ │ │ │ ├── SettingsEndpoint.cs
│ │ │ │ ├── SuperFundProductsEndpoint.cs
│ │ │ │ ├── SuperFundsEndpoint.cs
│ │ │ │ └── TimesheetsEndpoint.cs
│ │ │ ├── Model/
│ │ │ │ ├── Account.cs
│ │ │ │ ├── BankAccount.cs
│ │ │ │ ├── DeductionLine.cs
│ │ │ │ ├── DeductionType.cs
│ │ │ │ ├── EarningsLine.cs
│ │ │ │ ├── EarningsRate.cs
│ │ │ │ ├── Employee.cs
│ │ │ │ ├── HomeAddress.cs
│ │ │ │ ├── LeaveAccuralLine.cs
│ │ │ │ ├── LeaveApplication.cs
│ │ │ │ ├── LeaveBalance.cs
│ │ │ │ ├── LeaveEarningsLine.cs
│ │ │ │ ├── LeaveLine.cs
│ │ │ │ ├── LeavePeriod.cs
│ │ │ │ ├── LeaveType.cs
│ │ │ │ ├── OpeningBalances.cs
│ │ │ │ ├── PayItems.cs
│ │ │ │ ├── PayRun.cs
│ │ │ │ ├── PayTemplate.cs
│ │ │ │ ├── PayrollCalendar.cs
│ │ │ │ ├── Payslip.cs
│ │ │ │ ├── PayslipEarningsLine.cs
│ │ │ │ ├── ReimbursementLine.cs
│ │ │ │ ├── ReimbursementType.cs
│ │ │ │ ├── Settings.cs
│ │ │ │ ├── Status/
│ │ │ │ │ ├── EmploymentStatus.cs
│ │ │ │ │ ├── LeavePeriodStatus.cs
│ │ │ │ │ ├── ResidencyStatusType.cs
│ │ │ │ │ └── TimesheetStatus.cs
│ │ │ │ ├── SuperFund.cs
│ │ │ │ ├── SuperFundProduct.cs
│ │ │ │ ├── SuperLine.cs
│ │ │ │ ├── SuperMembership.cs
│ │ │ │ ├── SuperannuationLine.cs
│ │ │ │ ├── TaxDeclaration.cs
│ │ │ │ ├── TaxLine.cs
│ │ │ │ ├── Timesheet.cs
│ │ │ │ ├── TimesheetEarningsLine.cs
│ │ │ │ ├── TimesheetLine.cs
│ │ │ │ └── Types/
│ │ │ │ ├── CalendarType.cs
│ │ │ │ ├── DeductionCalculationType.cs
│ │ │ │ ├── EarningsRateCalculationType.cs
│ │ │ │ ├── EarningsType.cs
│ │ │ │ ├── EmploymentBasisType.cs
│ │ │ │ ├── LeaveCalculationType.cs
│ │ │ │ ├── LeaveContributionType.cs
│ │ │ │ ├── PaymentFrequencyType.cs
│ │ │ │ ├── RateType.cs
│ │ │ │ ├── State.cs
│ │ │ │ ├── SuperannuationCalculationType.cs
│ │ │ │ ├── SuperannuationContributionType.cs
│ │ │ │ ├── SuperfundType.cs
│ │ │ │ └── TaxFileNumberExemptionType.cs
│ │ │ ├── Request/
│ │ │ │ ├── EmployeesRequest.cs
│ │ │ │ ├── LeaveApplicationsRequest.cs
│ │ │ │ ├── PayItemsRequest.cs
│ │ │ │ ├── PayRunsRequest.cs
│ │ │ │ ├── PayrollCalendarsRequest.cs
│ │ │ │ ├── PayslipRequest.cs
│ │ │ │ ├── SuperFundsRequest.cs
│ │ │ │ └── TimesheetsRequest.cs
│ │ │ └── Response/
│ │ │ ├── EmployeesResponse.cs
│ │ │ ├── LeaveApplicationsResponse.cs
│ │ │ ├── PayItemsResponse.cs
│ │ │ ├── PayRunsResponse.cs
│ │ │ ├── PayrollCalendarResponse.cs
│ │ │ ├── PayslipsResponse.cs
│ │ │ ├── SettingsResponse.cs
│ │ │ ├── SuperFundProductsResponse.cs
│ │ │ ├── SuperFundsResponse.cs
│ │ │ └── TimesheetsResponse.cs
│ │ ├── AustralianPayroll.cs
│ │ └── Common/
│ │ ├── Model/
│ │ │ ├── Account.cs
│ │ │ ├── NumberOfUnits.cs
│ │ │ ├── PayNotice.cs
│ │ │ ├── PayRun.cs
│ │ │ ├── PayrollSettingsTrackingCategories.cs
│ │ │ ├── Status/
│ │ │ │ └── PayRunStatus.cs
│ │ │ └── TrackingCategory.cs
│ │ ├── PayrollApi.cs
│ │ └── PayrollEndpoint.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── README.md
│ ├── Serialization/
│ │ └── DefaultMapper.cs
│ ├── Xero.Api.csproj
│ └── packages.config
├── Xero.Api.Example.Applications/
│ ├── Partner/
│ │ ├── AmericanPayroll.cs
│ │ ├── AustralianPayroll.cs
│ │ ├── Core.cs
│ │ ├── PartnerAuthenticator.cs
│ │ ├── PartnerMvcAuthenticator.cs
│ │ └── Settings.cs
│ ├── Private/
│ │ ├── AmericanPayroll.cs
│ │ ├── AustralianPayroll.cs
│ │ ├── Core.cs
│ │ ├── PrivateAuthenticator.cs
│ │ └── Settings.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Public/
│ │ ├── AmericanPayroll.cs
│ │ ├── AustralianPayroll.cs
│ │ ├── Core.cs
│ │ ├── IMvcAuthenticator.cs
│ │ ├── PublicAuthenticator.cs
│ │ ├── PublicMvcAuthenticator.cs
│ │ ├── RenewTokenException.cs
│ │ └── Settings.cs
│ ├── TokenStoreAuthenticator.cs
│ └── Xero.Api.Example.Applications.csproj
├── Xero.Api.Example.Counts/
│ ├── App.config
│ ├── Lister.cs
│ ├── Program.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── README.md
│ ├── Resources/
│ │ └── cert/
│ │ └── public_privatekey.txt
│ └── Xero.Api.Example.Counts.csproj
├── Xero.Api.Example.Creation/
│ ├── ApiDataCreation.cs
│ ├── App.config
│ ├── Creator/
│ │ ├── Creator.cs
│ │ ├── Name.cs
│ │ └── PlaceName.cs
│ ├── Program.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── README.md
│ ├── Resources/
│ │ └── cert/
│ │ └── public_privatekey.txt
│ ├── Xero.Api.Example.Creation.csproj
│ └── data/
│ ├── Descriptions.txt
│ ├── Given.txt
│ ├── Surnames.txt
│ ├── place_index.txt
│ └── street_index.txt
├── Xero.Api.Example.MVC/
│ ├── App_Start/
│ │ ├── FilterConfig.cs
│ │ ├── RouteConfig.cs
│ │ └── WebApiConfig.cs
│ ├── Content/
│ │ └── Site.css
│ ├── Controllers/
│ │ ├── HomeController.cs
│ │ └── OrganisationController.cs
│ ├── Global.asax
│ ├── Global.asax.cs
│ ├── Helpers/
│ │ └── XeroApiHelper.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── README.md
│ ├── Stores/
│ │ ├── MemoryAccessTokenStore.cs
│ │ └── MemoryRequestTokenStore.cs
│ ├── Views/
│ │ ├── Home/
│ │ │ ├── Authorize.cshtml
│ │ │ ├── Connect.cshtml
│ │ │ ├── Index.cshtml
│ │ │ └── NoAuthorized.cshtml
│ │ ├── Organisation/
│ │ │ └── Index.cshtml
│ │ ├── Shared/
│ │ │ ├── Error.cshtml
│ │ │ └── _Layout.cshtml
│ │ ├── Web.config
│ │ └── _ViewStart.cshtml
│ ├── Web.Debug.config
│ ├── Web.Release.config
│ ├── Web.config
│ ├── Xero.Api.Example.MVC.csproj
│ ├── Xero.Api.Example.MVC.sln
│ └── packages.config
├── Xero.Api.Example.Mocks/
│ ├── App.config
│ ├── ContactManagerAndTests/
│ │ ├── ContactManager.cs
│ │ └── ContactManagerTests.cs
│ ├── Lister.cs
│ ├── Program.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── Xero.Api.Example.Mocks.csproj
│ └── packages.config
├── Xero.Api.Example.TokenStores/
│ ├── Dapper/
│ │ └── Dapper.cs
│ ├── MemoryTokenStore.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ ├── SqliteTokenStore.cs
│ ├── Xero.Api.Example.TokenStores.csproj
│ ├── app.config
│ └── packages.config
├── Xero.Api.sln
├── build.bat
├── minimal.nuspec
└── nuget.nuspec
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################
/packages
*/bin/Debug
*/obj/Debug
*/bin
_ReSharper*
*.user
*.suo
*.pfx
*.pem
*.cer
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Pp]ackages/
out/
*.orig
*.nupkg
/.vs
*.DotSettings
*.lnk
================================================
FILE: CoreTests/ApiWrapperTest.cs
================================================
using System.Linq;
using Xero.Api.Core;
using Xero.Api.Core.Model;
namespace CoreTests
{
public class ApiWrapperTest
{
public ApiWrapperTest()
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
}
private IXeroCoreApi _api;
protected Account BankAccount { get; set; }
protected Account Account { get; set; }
protected IXeroCoreApi Api
{
get { return _api ?? (_api = CreateCoreApi()); }
}
private static IXeroCoreApi CreateCoreApi()
{
return new Xero.Api.Example.Applications.Private.Core
{
UserAgent = "Xero Api - Integration tests"
};
}
protected void SetUp()
{
BankAccount = Given_a_bank_account();
Account = Given_an_account();
}
protected Account Given_a_bank_account()
{
return Api.Accounts.Where("Type == \"BANK\"").Find().First();
}
protected Account Given_an_account()
{
return Api.Accounts.Where("Type != \"BANK\"").Find().First();
}
}
}
================================================
FILE: CoreTests/App.config
================================================
================================================
FILE: CoreTests/CoreTests.csproj
================================================
Debug
AnyCPU
{6E24F214-40CC-4891-8028-A068CD7CD4BD}
Library
Properties
CoreTests
CoreTests
v4.5.1
512
..\
AnyCPU
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
5
false
AnyCPU
pdbonly
true
bin\Release\
TRACE
prompt
4
false
Always
Always
Designer
..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll
False
..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll
False
..\packages\NUnit.2.6.3\lib\nunit.framework.dll
..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll
False
..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll
False
{d799e8cc-0917-465d-80df-f8355201d13f}
Xero.Api.Example.Applications
{2EB9F8BA-CCFF-4B43-99A0-5130D368C78F}
Xero.Api
================================================
FILE: CoreTests/Integration/Accounts/Create.cs
================================================
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.Accounts
{
[TestFixture]
public class Create : ApiWrapperTest
{
[Test]
public void create_account()
{
Assert.DoesNotThrow(() => Api.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.Overheads,
Description = "Consultant charges",
Name = "Consultation " + Random.GetRandomString(10)
}));
}
[Test]
public void create_bank_account()
{
Assert.DoesNotThrow(() => Api.Create(new Account
{
Code = Random.GetRandomString(10),
Name = "Cheque " + Random.GetRandomString(10),
Type = AccountType.Bank,
BankAccountNumber = "02-3467-474288",
}));
}
[Test]
public void incorrect_types_are_rejected()
{
Assert.Throws(() => Api.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.Expense,
Description = "Income from other sales",
Name = "Other Sales",
TaxType = "OUTPUT2"
}));
}
}
}
================================================
FILE: CoreTests/Integration/Accounts/Find.cs
================================================
using System;
using System.Linq;
using System.Runtime.Hosting;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Accounts
{
[TestFixture]
public class Find : ApiWrapperTest
{
[Test]
public void find_by_value()
{
var type = Api.Accounts
.Where("Type == \"OVERHEADS\"")
.Find()
.ToList().First().Type;
Assert.AreEqual(AccountType.Overheads, type);
}
[Test]
public void find_by_id()
{
var expected = Api.Accounts
.Where("Type == \"REVENUE\"")
.Find()
.First()
.Id;
var id = Api.Accounts.Find(expected).Id;
Assert.AreEqual(expected, id);
}
[Test]
public void finding_a_non_system_account_has_null_SystemAccount()
{
var newNonSystemAccount = Api.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.OtherIncome,
Description = "Consultation " + Random.GetRandomString(10),
Name = "Consultation " + Random.GetRandomString(10)
});
var account = Api.Accounts.Find(newNonSystemAccount.Id);
Assert.AreEqual(null, account.SystemAccount);
}
[Test]
public void find_accounts_ifmodifiedsince()
{
var newNonSystemAccount = Api.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.OtherIncome,
Description = "Consultation " + Random.GetRandomString(10),
Name = "Consultation " + Random.GetRandomString(10)
});
var accounts = Api.Accounts
.ModifiedSince(DateTime.Now.AddMinutes(-1))
.Find();
Assert.True(accounts.Any());
}
}
}
================================================
FILE: CoreTests/Integration/Accounts/Update.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Accounts
{
public class Update : ApiWrapperTest
{
[Test]
public void Update_account()
{
var expectedDescription = "Updated Account" + Guid.NewGuid();
var account = CreateAccount();
account.Description = expectedDescription;
Api.Accounts.Update(account);
var updated = Api.Accounts.Find(account.Id);
Assert.True(updated.Description == expectedDescription);
}
[Test]
public void Archive_account()
{
var account = CreateAccount();
Api.Accounts.Update(new Account
{
Id = account.Id,
Status = AccountStatus.Archived
});
var updated = Api.Accounts.Find(account.Id);
Assert.True(updated.Status == AccountStatus.Archived);
}
private Account CreateAccount()
{
var code = "1234" + Guid.NewGuid();
return Api.Accounts.Create(new Account
{
Code = code.Substring(0, 10),
Name = "New Account " + Guid.NewGuid(),
Type = AccountType.Sales
});
}
}
}
================================================
FILE: CoreTests/Integration/Allocations/Add.cs
================================================
using System;
using System.Linq;
using CoreTests.Integration.Invoices;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Allocations
{
[TestFixture]
public class Add : ApiWrapperTest
{
[Test]
public void allocation_to_invoice()
{
var creditNote = new CreditNotes.CreditNotesTest().Given_an_authorised_creditnote(CreditNoteType.AccountsReceivable);
var invoice = new Create().Given_an_authorised_invoice(InvoiceType.AccountsReceivable);
var expected = Math.Min(creditNote.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
var result = Api.Allocations.Add(new Allocation
{
AppliedAmount = expected,
CreditNote = creditNote,
Invoice = invoice
});
Assert.AreEqual(expected, result.Amount);
Assert.AreEqual(invoice.Id, result.Invoice.Id);
Assert.AreEqual(creditNote.Id, result.CreditNote.Id);
}
[Test]
public void allocation_to_invoice_minimal()
{
var creditNote = new CreditNotes.CreditNotesTest().Given_an_authorised_creditnote();
var invoice = new Create().Given_an_authorised_invoice();
var expected = Math.Min(creditNote.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
var result = Api.Allocations.Add(new Allocation
{
AppliedAmount = expected,
CreditNote = new CreditNote { Id = creditNote.Id },
Invoice = new Invoice { Id = invoice.Id }
});
Assert.AreEqual(expected, result.Amount);
Assert.AreEqual(invoice.Id, result.Invoice.Id);
Assert.AreEqual(creditNote.Id, result.CreditNote.Id);
}
[Test]
public void allocation_on_creditnote()
{
var creditNote = new CreditNotes.CreditNotesTest().Given_an_authorised_creditnote();
var invoice = new Create().Given_an_authorised_invoice();
var expected = Math.Min(creditNote.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
Api.Allocations.Add(new Allocation
{
AppliedAmount = expected,
CreditNote = new CreditNote { Id = creditNote.Id },
Invoice = new Invoice { Id = invoice.Id }
});
creditNote = Api.CreditNotes.Find(creditNote.Id);
Assert.AreEqual(1, creditNote.Allocations.Count);
Assert.AreEqual(expected, creditNote.Allocations.First().Amount);
}
[Test]
public void allocation_on_prepayment()
{
var transaction = new BankTransactions.BankTransactionTest().Given_a_bank_transaction(BankTransactionType.SpendPrepayment);
var invoice = new Create().Given_an_authorised_invoice();
var expected = Math.Min(transaction.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
Api.Allocations.Add(new PrepaymentAllocation
{
AppliedAmount = expected,
Prepayment = new Prepayment { Id = transaction.PrepaymentID.GetValueOrDefault() },
Invoice = new Invoice { Id = invoice.Id }
});
var prepayment = Api.Prepayments.Find(transaction.PrepaymentID.GetValueOrDefault());
Assert.AreEqual(1, prepayment.Allocations.Count);
Assert.AreEqual(expected, prepayment.Allocations.First().Amount);
}
[Test]
public void allocation_on_overpayment()
{
var transaction = new BankTransactions.BankTransactionTest().Given_an_overpayment(BankTransactionType.SpendOverpayment);
var invoice = new Create().Given_an_authorised_invoice();
var expected = Math.Min(transaction.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
Api.Allocations.Add(new OverpaymentAllocation
{
AppliedAmount = expected,
Overpayment = new Overpayment { Id = transaction.OverpaymentID.GetValueOrDefault() },
Invoice = new Invoice { Id = invoice.Id }
});
var overpayment = Api.Overpayments.Find(transaction.OverpaymentID.GetValueOrDefault());
Assert.AreEqual(1, overpayment.Allocations.Count);
Assert.AreEqual(expected, overpayment.Allocations.First().Amount);
}
[Test]
public void Credit_notes_show_up_on_invoices()
{
var creditNote = new CreditNotes.CreditNotesTest().Given_an_authorised_creditnote();
var invoice = new Create().Given_an_authorised_invoice();
var amount = Math.Min(creditNote.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
Api.Allocations.Add(new Allocation
{
AppliedAmount = amount,
CreditNote = new CreditNote { Id = creditNote.Id },
Invoice = new Invoice { Id = invoice.Id }
});
invoice = Api.Invoices.Find(invoice.Id);
Assert.AreEqual(1, invoice.CreditNotes.Count);
Assert.AreEqual(creditNote.Id, invoice.CreditNotes.First().Id);
}
[Test]
public void Prepayments_show_on_invoices()
{
var transaction = new BankTransactions.BankTransactionTest().Given_a_bank_transaction(BankTransactionType.SpendPrepayment);
var invoice = new Create().Given_an_authorised_invoice();
var expected = Math.Min(transaction.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
Api.Allocations.Add(new PrepaymentAllocation
{
AppliedAmount = expected,
Prepayment = new Prepayment { Id = transaction.PrepaymentID.GetValueOrDefault() },
Invoice = new Invoice { Id = invoice.Id }
});
invoice = Api.Invoices.Find(invoice.Id);
Assert.AreEqual(1, invoice.Prepayments.Count);
Assert.AreEqual(transaction.PrepaymentID.GetValueOrDefault(), invoice.Prepayments.First().Id);
}
[Test]
public void Overpayments_show_on_invoices()
{
var transaction = new BankTransactions.BankTransactionTest().Given_an_overpayment(BankTransactionType.SpendOverpayment);
var invoice = new Create().Given_an_authorised_invoice();
var expected = Math.Min(transaction.Total.GetValueOrDefault(), invoice.Total.GetValueOrDefault());
Api.Allocations.Add(new OverpaymentAllocation
{
AppliedAmount = expected,
Overpayment = new Overpayment { Id = transaction.OverpaymentID.GetValueOrDefault() },
Invoice = new Invoice { Id = invoice.Id }
});
invoice = Api.Invoices.Find(invoice.Id);
Assert.AreEqual(1, invoice.Overpayments.Count);
Assert.AreEqual(transaction.OverpaymentID.GetValueOrDefault(), invoice.Overpayments.First().Id);
}
}
}
================================================
FILE: CoreTests/Integration/Attachments/Attachments.cs
================================================
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
using File = System.IO.File;
namespace CoreTests.Integration.Attachments
{
public class Attachments : ApiWrapperTest
{
private const string ImagePath = @"resources\images\connect_xero_button_blue.png";
private const string ImageWithSpacesPath = @"resources\images\connect_xero_button_blue - Copy.png";
[Test]
public void adding_attachment_to_invoice()
{
var attachment = Given_attachment_on_invoice();
Assert.IsTrue(attachment.Id != Guid.Empty);
}
[Test]
public void listing_attachments()
{
var id = Given_invoice_with_no_attachments();
CreateAttachment(id, AttachmentEndpointType.Invoices);
var attachments = Api.Attachments.List(AttachmentEndpointType.Invoices, id).ToList();
Assert.IsTrue(attachments.Any());
Assert.IsTrue(attachments.First().Id != Guid.Empty);
}
[Test]
public void getting_attachment()
{
var id = Given_invoice_with_no_attachments();
var sourceFile = new FileInfo(ImagePath);
var attachment = CreateAttachment(id, AttachmentEndpointType.Invoices, sourceFile);
Assert.AreEqual(attachment.ContentLength, sourceFile.Length);
Assert.AreEqual(attachment.FileName, sourceFile.Name);
}
[Test]
public void saving_attachments()
{
var sourceFile = new FileInfo(ImagePath);
var id = Given_invoice_with_no_attachments();
var attachment = CreateAttachment(id, AttachmentEndpointType.Invoices);
attachment = GetAttachment(id, AttachmentEndpointType.Invoices, attachment.FileName);
var path = Path.GetTempFileName();
attachment.Save(path);
var targetFile = new FileInfo(path);
Assert.AreEqual(sourceFile.Length, targetFile.Length);
// Clean up after yourself!
File.Delete(path);
}
[Test]
public void saving_attachment_online_invoice_accrec()
{
var attachment = Given_attachment_on_invoice(true);
Assert.AreEqual(true, attachment.IncludeOnline);
}
[Test]
public void saving_attachment_online_invoice_accpay()
{
var attachment = Given_attachment_on_invoice();
Assert.AreEqual(false, attachment.IncludeOnline);
}
[Test]
public void saving_attachment_online_credit_note()
{
var attachment = Given_attachment_on_credit_note(true);
Assert.AreEqual(true, attachment.IncludeOnline);
}
[Test]
public void saving_attachment_credit_note()
{
var attachment = Given_attachment_on_credit_note();
Assert.AreEqual(false, attachment.IncludeOnline);
}
[Test]
public void can_save_attachments_with_spaces_in_the_name()
{
var attachment = Given_an_attachment_with_a_space_in_the_name_on_an_invoice();
Assert.AreEqual(false, attachment.IncludeOnline);
}
private Attachment Given_attachment_on_invoice(bool includeOnline = false)
{
return CreateAttachment(Given_invoice_with_no_attachments(includeOnline), AttachmentEndpointType.Invoices, includeOnline);
}
private Attachment Given_an_attachment_with_a_space_in_the_name_on_an_invoice(bool includeOnline = false)
{
return CreateAttachment(Given_invoice_with_no_attachments(includeOnline), AttachmentEndpointType.Invoices, new FileInfo(ImageWithSpacesPath), includeOnline);
}
private Attachment Given_attachment_on_credit_note(bool includeOnline = false)
{
return CreateAttachment(Given_credit_note_with_no_attachments(), AttachmentEndpointType.CreditNotes, includeOnline);
}
private Attachment CreateAttachment(Guid id, AttachmentEndpointType type, bool includeOnline = false)
{
return CreateAttachment(id, type, new FileInfo(ImagePath), includeOnline);
}
private Attachment CreateAttachment(Guid id, AttachmentEndpointType type, FileInfo sourceFile, bool includeOnline = false)
{
return Api.Attachments.AddOrReplace(new Attachment(sourceFile), type, id, includeOnline);
}
private Attachment GetAttachment(Guid id, AttachmentEndpointType type, string fileName)
{
return Api.Attachments.Get(type, id, fileName);
}
private Guid Given_invoice_with_no_attachments(bool accRec = false)
{
return Api.Create(new Invoice
{
Contact = new Contact { Name = "Richard" },
Type = accRec ? InvoiceType.AccountsReceivable : InvoiceType.AccountsPayable,
LineItems = new List
{
new LineItem
{
Description = "Nothing to see",
LineAmount = 100.0m
}
}
}).Id;
}
private Guid Given_credit_note_with_no_attachments()
{
return Api.CreditNotes.Create(new CreditNote
{
Contact = new Contact {Name = "Apple Computers Ltd"},
Type = CreditNoteType.AccountsReceivable,
LineAmountTypes = LineAmountType.Exclusive,
LineItems = new List
{
new LineItem
{
AccountCode = "720",
Description = "MacBook - White",
UnitAmount = 1995.00m
}
}
}).Id;
}
}
}
================================================
FILE: CoreTests/Integration/BankTransactionTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace Tests.Integration.BankTransactions
{
public class BankTransactionTest : ApiWrapperTest
{
public BankTransaction NewBankTransaction()
{
var newBankTransaction = new BankTransaction
{
Type = BankTransactionType.Spend,
Contact = new Contact { Name = "ABC Bank" },
LineItems = new List
{
new LineItem
{
Description = "Yearly Bank Account Fee",
Quantity = 1m,
UnitAmount = 20.00m,
AccountCode = "404"
}
},
BankAccount = new Account { Id = FindBankAccountGuid() }
};
return newBankTransaction;
}
public Guid FindBankAccountGuid()
{
var bankAccount = Api.Accounts.Where("Type == \"BANK\"").Find().FirstOrDefault();
if (bankAccount != null)
{
return bankAccount.Id;
}
return Guid.Empty;
}
}
}
================================================
FILE: CoreTests/Integration/BankTransactions/BankTransactionTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.BankTransactions
{
public class BankTransactionTest : ApiWrapperTest
{
public BankTransaction Given_a_bank_transaction()
{
return Given_a_bank_transaction(BankTransactionType.Spend);
}
public BankTransaction Given_a_bank_transaction(BankTransactionType type)
{
return Api.Create(new BankTransaction
{
Type = type,
Contact = new Contact { Name = "ABC Bank" },
LineItems = new List
{
new LineItem
{
Description = "Yearly Bank Account Fee",
Quantity = 1m,
UnitAmount = 20.00m,
AccountCode = "404"
}
},
BankAccount = new Account { Id = FindBankAccountGuid() }
});
}
public BankTransaction Given_an_overpayment(BankTransactionType type)
{
return Api.Create(new BankTransaction
{
Type = type,
Contact = new Contact { Name = "ABC Bank" },
LineAmountTypes = LineAmountType.NoTax,
LineItems = new List
{
new LineItem
{
Description = "Yearly Bank Account Fee",
UnitAmount = 20.00m,
AccountCode = "800"
}
},
BankAccount = new Account { Id = FindBankAccountGuid() }
});
}
public Guid FindBankAccountGuid()
{
var bankAccount = Api.Accounts.Where("Type == \"BANK\"").Find().FirstOrDefault();
if (bankAccount != null)
{
return bankAccount.Id;
}
return Guid.Empty;
}
}
}
================================================
FILE: CoreTests/Integration/BankTransactions/Create.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.BankTransactions
{
[TestFixture]
public class Create : BankTransactionTest
{
[Test]
public void create_bank_transactions()
{
var name = Given_a_bank_transaction()
.Contact
.Name;
Assert.AreEqual("ABC Bank", name);
}
}
}
================================================
FILE: CoreTests/Integration/BankTransactions/Find.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.BankTransactions
{
[TestFixture]
public class Find : BankTransactionTest
{
[Test]
public void find_bank_transactions_where_filter()
{
Assert.DoesNotThrow(() => Api.BankTransactions
.Where("Type == \"SPEND\"")
.And("Status == \"AUTHORISED\"")
.Find());
}
[Test]
public void find_bank_transactions_ifmodifiedsince()
{
Given_a_bank_transaction();
var bankTransaction = Api.BankTransactions
.ModifiedSince(DateTime.Today.AddDays(-1).Date)
.Find();
Assert.IsNotNull(bankTransaction);
}
[Test]
public void find_bank_transactions_individual()
{
var expected = Given_a_bank_transaction().Id;
var id = Api.BankTransactions.Find(expected).Id;
Assert.AreEqual(expected, id);
}
[Test]
public void find_by_page()
{
Given_a_bank_transaction();
var bankTrans = Api.BankTransactions.Page(1).Find();
Assert.Greater(bankTrans.Count(), 0);
}
}
}
================================================
FILE: CoreTests/Integration/BankTransactions/Update.cs
================================================
using System.Collections.Generic;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.BankTransactions
{
[TestFixture]
public class Update : BankTransactionTest
{
[Test]
public void update_bank_transaction()
{
var bt = Given_a_bank_transaction();
var updatedTransaction = Api.Update(new BankTransaction
{
Id = bt.Id,
BankAccount = new Account { Id = FindBankAccountGuid() },
LineItems = new List
{
new LineItem
{
UnitAmount = 100m,
Quantity = 2m,
Description = bt.LineItems[0].Description,
AccountCode = bt.LineItems[0].AccountCode
}
}
});
Assert.AreEqual(100, updatedTransaction.LineItems[0].UnitAmount);
Assert.AreEqual(2, updatedTransaction.LineItems[0].Quantity);
Assert.AreEqual(200, updatedTransaction.LineItems[0].LineAmount);
}
}
}
================================================
FILE: CoreTests/Integration/BankTransfers/BankTransfersTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.BankTransfers
{
public abstract class BankTransfersTest : ApiWrapperTest
{
public BankTransfer Given_a_bank_transfer(Decimal amount)
{
var accountIds = get_bankaccount_ids();
var newBankTransfer = new BankTransfer
{
FromBankAccount = new Account { Id = accountIds[0] },
ToBankAccount = new Account { Id = accountIds[1] },
Amount = amount
};
return Api.Create(newBankTransfer);
}
public IList get_bankaccount_ids()
{
return Api.Accounts.Where("Type == \"BANK\"")
.Find()
.Select(p => p.Id)
.ToList();
}
}
}
================================================
FILE: CoreTests/Integration/BankTransfers/Create.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.BankTransfers
{
[TestFixture]
public class Create : BankTransfersTest
{
[Test]
public void create_bank_transfer()
{
const decimal expected = 10m;
var accounts = get_bankaccount_ids();
var bankTransfer = Given_a_bank_transfer(expected);
Assert.AreEqual(expected, bankTransfer.Amount);
Assert.AreEqual(accounts[0], bankTransfer.FromBankAccount.Id);
Assert.AreEqual(accounts[1], bankTransfer.ToBankAccount.Id);
}
}
}
================================================
FILE: CoreTests/Integration/BankTransfers/Find.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.BankTransfers
{
[TestFixture]
public class Find : BankTransfersTest
{
[Test]
public void find_bank_transfers()
{
Given_a_bank_transfer(10m);
var allTransfers = Api.BankTransfers.Find();
Assert.Greater(allTransfers.Count(), 0);
}
[Test]
public void find_bank_transfers_individual()
{
var expected = Given_a_bank_transfer(25m).Id;
var id = Api.BankTransfers.Find(expected).Id;
Assert.AreEqual(expected, id);
}
[Test]
public void find_bank_transfers_ifmodifiedsince()
{
Given_a_bank_transfer(25m);
var date = DateTime.Today.AddDays(-4);
var bankTransfers = Api.BankTransfers.ModifiedSince(date).Find();
Assert.Greater(bankTransfers.Count(), 0);
}
}
}
================================================
FILE: CoreTests/Integration/BatchPayment/BatchPaymentsTest.cs
================================================
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 { 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
{
new LineItem
{
AccountCode = accountCode,
Description = "Good value item",
LineAmount = amount
}
}
});
}
}
}
================================================
FILE: CoreTests/Integration/BatchPayment/Create.cs
================================================
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);
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/Add_Contact.cs
================================================
using NUnit.Framework;
using System;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.ContactGroups
{
[TestFixture]
public class Add_Contact : ContactGroupsTest
{
[Test]
public void Can_I_add_a_contact_to_a_contactgroup()
{
var contactgroup = Given_a_contactgroup();
Api.ContactGroups[contactgroup.Id].Add(Given_a_contact());
}
[Test]
public void But_not_with_a_group_like_this()
{
Assert.Throws(() =>
{
Api.ContactGroups[Guid.Empty].Add(Given_a_contact());
});
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/ContactGroupsTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.ContactGroups
{
public abstract class ContactGroupsTest : ApiWrapperTest
{
// need a contact in the system to use contact groups with.
protected Contact Given_a_contact()
{
var contact = Api.Create(new Contact
{
Name = "Peter " + Guid.NewGuid().ToString("N")
});
return contact;
}
protected ContactGroup Given_a_contactgroup()
{
var group = Api.ContactGroups.Add(new ContactGroup
{
Name = "Nice People " + Guid.NewGuid()
});
return group;
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/Create.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.ContactGroups
{
[TestFixture]
public class Create : ContactGroupsTest
{
[Test]
public void Can_I_create_a_contactgroup()
{
var name= Given_a_contactgroup().Name;
Assert.IsTrue(name.StartsWith("Nice People"));
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/Delete.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.ContactGroups
{
[TestFixture]
public class Delete : ContactGroupsTest
{
[Test]
public void Can_I_remove_the_contactgroup()
{
var contactgroup = Given_a_contactgroup();
contactgroup.Status = "DELETED";
var group = Api.Update(contactgroup);
Assert.IsTrue(group.Status == "DELETED" );
}
[Test]
public void Can_I_empty_the_contactgroup_of_contacts()
{
var contactgroup = Given_a_contactgroup();
List contacts = new List();
contacts.Add(Given_a_contact());
contacts.Add(Given_a_contact());
contacts.Add(Given_a_contact());
contacts.Add(Given_a_contact());
contacts.Add(Given_a_contact());
Api.ContactGroups[contactgroup.Id].AddRange(contacts);
Api.ContactGroups[contactgroup.Id].Clear();
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/Find.cs
================================================
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.ContactGroups
{
[TestFixture]
public class Find : ContactGroupsTest
{
[Test]
public void Can_Find_Contact_Group()
{
var contactGroup = Given_a_contactgroup();
var foundContactGroup = Api.ContactGroups.Find(contactGroup.Id);
Assert.IsTrue(foundContactGroup.Name.StartsWith("Nice People"));
}
[Test]
public void Can_Find_Contacts_in_Contact_Group()
{
var contactGroup = Given_a_contactgroup();
var contact = Given_a_contact();
Api.ContactGroups[contactGroup.Id].Add(contact);
var foundContactGroup = Api.ContactGroups.Find(contactGroup.Id);
Assert.IsTrue(foundContactGroup.Name.StartsWith("Nice People"));
Assert.IsTrue(foundContactGroup.Contacts.FirstOrDefault().Name.StartsWith("Peter"));
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/Remove_Contact.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace CoreTests.Integration.ContactGroups
{
[TestFixture]
public class Remove_Contact : ContactGroupsTest
{
[Test]
public void Can_remove_a_contact_from_a_contact_group()
{
var contactgroup = Given_a_contactgroup();
var contact = Given_a_contact();
Api.ContactGroups[contactgroup.Id].Add(contact);
Api.ContactGroups[contactgroup.Id].Remove(contact.Id);
}
}
}
================================================
FILE: CoreTests/Integration/ContactGroups/Update.cs
================================================
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.ContactGroups
{
[TestFixture]
public class Update : ContactGroupsTest
{
[Test]
public void Can_I_change_the_name_of_a_contactgroup()
{
var contactgroup = Given_a_contactgroup();
var newName = "Marketing Group" + Guid.NewGuid();
contactgroup.Name = newName;
var result = Api.Update(contactgroup);
Assert.IsTrue(result.Name.StartsWith("Marketing Group"));
}
[Test]
protected void Can_I_append_contacts_to_a_contactgroup()
{
var contactgroup = Given_a_contactgroup();
List assign_1_contacts = new List();
assign_1_contacts.Add(Given_a_contact());
Api.ContactGroups[contactgroup.Id].AddRange(assign_1_contacts);
List assign_4_more_contacts = new List();
assign_4_more_contacts.Add(Given_a_contact());
assign_4_more_contacts.Add(Given_a_contact());
assign_4_more_contacts.Add(Given_a_contact());
assign_4_more_contacts.Add(Given_a_contact());
Api.ContactGroups[contactgroup.Id].AddRange(assign_4_more_contacts);
}
}
}
================================================
FILE: CoreTests/Integration/Contacts/ContactsTest.cs
================================================
using System;
using System.Linq;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.Contacts
{
public abstract class ContactsTest : ApiWrapperTest
{
private TrackingCategory trackingCat;
private bool wasTCCreated = false;
protected Contact Given_a_contact()
{
var contact = Api.Create(new Contact
{
Name = "Peter " + Random.GetRandomString(10)
});
return contact;
}
protected TrackingCategory findOrCreateTC(string OptionName, string TCName)
{
trackingCat = Api.TrackingCategories.GetAll().FirstOrDefault();
if (trackingCat == null || trackingCat.Options.FirstOrDefault() == null)
{
var option1 = new Option()
{
Id = Guid.Empty,
Name = OptionName,
Status = TrackingOptionStatus.Active
};
trackingCat = Api.TrackingCategories.Create(new TrackingCategory()
{
Name = TCName,
Status = TrackingCategoryStatus.Active
});
Api.TrackingCategories[trackingCat.Id].Add(option1);
trackingCat = Api.TrackingCategories.GetByID(trackingCat.Id);
wasTCCreated = true;
}
return trackingCat;
}
protected void deleteCreatedTC(TrackingCategory tc)
{
if (wasTCCreated)
{
Api.TrackingCategories.Delete(trackingCat);
wasTCCreated = false;
}
}
}
}
================================================
FILE: CoreTests/Integration/Contacts/Create.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.Contacts
{
[TestFixture]
public class Create : ContactsTest
{
[Test]
public void create_contact()
{
var name = Given_a_contact().Name;
Assert.IsTrue(name.StartsWith("Peter"));
}
[Test]
public void create_many_contact()
{
var contacts = Api.Create(new List
{
new Contact
{
Name = "John " + Random.GetRandomString(10)
},
new Contact
{
Name = "Paul" + Random.GetRandomString(10)
},
new Contact
{
Name = "George" + Random.GetRandomString(10)
},
new Contact
{
Name = "Ringo" + Random.GetRandomString(10)
}
});
Assert.AreEqual(4, contacts.Count());
}
[Test]
public void create_complex_contact()
{
Api.Contacts.SummarizeErrors(true);
var expectedAccountNumber = "AccountNumber" + Random.GetRandomString(10);
var contact = Api.Create(new Contact
{
Name = "24 locks " + Random.GetRandomString(10),
FirstName = "Ben",
LastName = "Bowden",
EmailAddress = "ben.bowden@24locks.com",
AccountNumber = expectedAccountNumber,
ContactPersons = new List
{
new ContactPerson
{
FirstName = "John",
LastName = "Smith",
EmailAddress = "john.smith@24locks.com",
IncludeInEmails = true
}
}
});
Assert.AreEqual("Ben", contact.FirstName);
Assert.AreEqual("John", contact.ContactPersons[0].FirstName);
Assert.AreEqual(expectedAccountNumber, contact.AccountNumber);
}
[Test]
public void create_contact_with_tracking()
{
//Test will create a Tracking Category and use it if there are none available.
var TCName = "Luke Skywalker" + Guid.NewGuid();
var OptionName = "Yoda " + Guid.NewGuid();
var trackingCat = findOrCreateTC(TCName, OptionName);
var contact = Api.Create(new Contact
{
Name = "24 locks " + Random.GetRandomString(10),
FirstName = "Ben",
LastName = "Bowden",
EmailAddress = "ben.bowden@24locks.com",
PurchasesTrackingCategories = new List(){
new PurchasesTrackingCategory()
{
Name = trackingCat.Name,
Option = trackingCat.Options.FirstOrDefault().Name
}
},
ContactPersons = new List
{
new ContactPerson
{
FirstName = "John",
LastName = "Smith",
EmailAddress = "john.smith@24locks.com",
IncludeInEmails = true
}
}
});
deleteCreatedTC(trackingCat);
Assert.AreEqual("Ben", contact.FirstName);
Assert.AreEqual("John", contact.ContactPersons[0].FirstName);
Assert.True(TCName == contact.PurchasesTrackingCategories.FirstOrDefault().Name || trackingCat.Name == contact.PurchasesTrackingCategories.FirstOrDefault().Name);
Assert.True(OptionName == contact.PurchasesTrackingCategories.FirstOrDefault().Option || contact.PurchasesTrackingCategories.FirstOrDefault().Option == trackingCat.Options.FirstOrDefault().Name);
}
}
}
================================================
FILE: CoreTests/Integration/Contacts/Find.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.Contacts
{
[TestFixture]
public class Find : ContactsTest
{
[Test]
public void find_by_page()
{
Given_a_contact();
Assert.True(Api.Contacts.Page(1).Find().Any());
}
[Test]
public void find_by_id()
{
var expected = Given_a_contact().Id;
var id = Api.Contacts
.Find(expected)
.Id;
Assert.AreEqual(expected, id);
}
[Test]
public void find_by_id_list()
{
var created = Given_a_contact();
var contacts = Api.Contacts.Ids(new[] { created.Id }).Find().ToList();
Assert.AreEqual(1, contacts.Count());
Assert.AreEqual(created.Id, contacts.First().Id);
}
[Test]
public void find_by_value()
{
var expected = Given_a_contact().Name;
var name = Api.Contacts
.Where(string.Format("Name == \"{0}\"", expected))
.Find()
.Select(p => p.Name);
Assert.True(name.All(p => p == expected));
}
[Test]
public void find_by_contains_value()
{
var expected = Given_a_contact().Name;
var contacts = Api.Contacts
.Where(string.Format("Name.Contains(\"{0}\")", expected))
.Find()
.Select(p => p.Name);
Assert.True(contacts.All(p => p.Contains(expected)));
}
[Test]
public void find_by_status()
{
Given_a_contact();
var status = Api.Contacts
.Where("ContactStatus == \"ACTIVE\"")
.Find()
.Select(p => p.ContactStatus);
Assert.True(status.All(p => p == ContactStatus.Active));
}
[Test]
public void find_by_updated_date()
{
var expected = Given_a_contact().Id;
var date = DateTime.Today.AddDays(-5);
var contacts = Api.Contacts
.ModifiedSince(date)
.OrderByDescending("UpdatedDateUTC")
.Find()
.Select(p => p.Id)
.ToList();
Assert.Greater(contacts.Count(), 0);
Assert.Contains(expected, contacts);
}
[Test]
public void find_by_dateRange()
{
var expected = Given_a_contact().Id;
var fromDate = DateTime.Today.AddDays(-1);
var toDate = DateTime.Today.AddDays(1);
var contacts = Api.Contacts
.Where(string.Format("UpdatedDateUTC >= DateTime.Parse(\"{0}\")", fromDate.ToString("yyyy-MM-dd")))
.And(string.Format("UpdatedDateUTC <= DateTime.Parse(\"{0}\")", toDate.ToString("yyyy-MM-dd")))
.OrderByDescending("UpdatedDateUTC")
.Find()
.Select(p => p.Id)
.ToList();
Assert.Greater(contacts.Count(), 0);
Assert.Contains(expected, contacts);
}
}
}
================================================
FILE: CoreTests/Integration/Contacts/Update.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Contacts
{
public class Update : ContactsTest
{
[Test]
public void update_contact()
{
var id = Given_a_contact().Id;
var changes = new Contact
{
Id = id,
ContactNumber = "ID001" + Guid.NewGuid().ToString("N"),
Name = "ABC Limited " + Guid.NewGuid().ToString("N"),
FirstName = "John",
LastName = "Smith",
EmailAddress = "john.smith@gmail.com",
BankAccountDetails = "01-0123-0123456-00",
TaxNumber = "12-345-678",
AccountsReceivableTaxType = "OUTPUT",
AccountsPayableTaxType = "INPUT",
DefaultCurrency = "NZD",
Addresses = new List
{
new Address
{
AddressType = AddressType.PostOfficeBox,
AddressLine1 = "P O Box 123",
City = "Wellington",
PostalCode = "6011"
}
}
};
var updated = Api.Update(changes);
Assert.IsTrue(updated.Name.StartsWith("ABC"));
Assert.IsTrue(updated.ContactNumber.StartsWith("ID001"));
Assert.AreEqual("John", updated.FirstName);
Assert.AreEqual("Smith", updated.LastName);
Assert.AreEqual("john.smith@gmail.com", updated.EmailAddress);
Assert.AreEqual("01-0123-0123456-00", updated.BankAccountDetails);
Assert.AreEqual("NZD", updated.DefaultCurrency);
Assert.AreEqual("Wellington", updated.Addresses.Single(p => p.AddressType == AddressType.PostOfficeBox).City);
}
}
}
================================================
FILE: CoreTests/Integration/CreditNotes/Create.cs
================================================
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.CreditNotes
{
[TestFixture]
public class Create : CreditNotesTest
{
[Test]
public void create_creditnote()
{
const CreditNoteType expected = CreditNoteType.AccountsReceivable;
var type = Given_a_creditnote(type: expected).Type;
Assert.AreEqual(expected, type);
}
}
}
================================================
FILE: CoreTests/Integration/CreditNotes/CreditNotesTest.cs
================================================
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.CreditNotes
{
public class CreditNotesTest : ApiWrapperTest
{
public CreditNote Given_an_authorised_creditnote(CreditNoteType type = CreditNoteType.AccountsPayable)
{
return Given_a_creditnote(type: type, status: InvoiceStatus.Authorised);
}
public CreditNote Given_a_draft_creditnote(CreditNoteType type = CreditNoteType.AccountsPayable)
{
return Given_a_creditnote(type: type);
}
public CreditNote Given_a_creditnote(string contactName = "Apple Computers Ltd", CreditNoteType type = CreditNoteType.AccountsPayable, InvoiceStatus status = InvoiceStatus.Draft)
{
return Api.CreditNotes.Create(new CreditNote
{
Contact = new Contact { Name = contactName },
Type = type,
Date = DateTime.UtcNow,
LineAmountTypes = LineAmountType.Exclusive,
Status = status,
LineItems = new List
{
new LineItem
{
AccountCode = "720",
Description = "MacBook - White",
UnitAmount = 1995.00m
}
}
});
}
}
}
================================================
FILE: CoreTests/Integration/CreditNotes/Find.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.CreditNotes
{
[TestFixture]
public class Find : CreditNotesTest
{
[Test]
public void find_all_creditnotes()
{
Given_a_creditnote();
Assert.True(Api.CreditNotes.Find().Any());
}
[Test]
public void find_by_id()
{
var expected = Given_a_creditnote().Id;
var id = Api.CreditNotes.Find(expected).Id;
Assert.AreEqual(expected, id);
}
[Test]
public void find_by_value()
{
Given_a_creditnote();
var creditnote = Api.CreditNotes
.Where("Type == \"ACCPAYCREDIT\"")
.Find()
.First()
.Type;
Assert.AreEqual(CreditNoteType.AccountsPayable, creditnote);
}
[Test]
public void find_orderby_value()
{
Given_a_creditnote();
var creditNote = Api.CreditNotes
.OrderBy("Type")
.Find()
.First()
.Type;
Assert.AreEqual(CreditNoteType.AccountsPayable, creditNote);
}
}
}
================================================
FILE: CoreTests/Integration/CreditNotes/Update.cs
================================================
using System.Collections.Generic;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.CreditNotes
{
[TestFixture]
public class Update : CreditNotesTest
{
[Test]
public void delete_draft_creditnote()
{
const InvoiceStatus expected = InvoiceStatus.Deleted;
var creditnote = Given_a_creditnote();
creditnote.Status = expected;
var status = Api.Update(creditnote).Status;
Assert.AreEqual(expected, status);
}
[Test]
public void update_creditnote_lineitems()
{
var creditnote = Given_a_creditnote();
var updatedCreditnote = Api.Update(new CreditNote
{
Id = creditnote.Id,
LineItems = new List
{
new LineItem
{
Description = creditnote.LineItems[0].Description,
Quantity = 2m,
UnitAmount = 100m,
AccountCode = creditnote.LineItems[0].AccountCode
}
}
});
Assert.AreEqual(100m, updatedCreditnote.LineItems[0].UnitAmount);
Assert.AreEqual(2m, updatedCreditnote.LineItems[0].Quantity);
Assert.AreEqual(200m, updatedCreditnote.LineItems[0].LineAmount);
}
}
}
================================================
FILE: CoreTests/Integration/ExpenseClaims/Create.cs
================================================
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.ExpenseClaims
{
[TestFixture]
public class Create : ExpenseClaimTest
{
[Test]
public void create_expense_claim()
{
var user = Api.Users.Find().First();
var receipt1 = Given_a_receipt(user.Id, Random.GetRandomString(10), Random.GetRandomString(30), 20m, "420");
var receipt2 = Given_a_receipt(user.Id, Random.GetRandomString(10), Random.GetRandomString(30), 50m, "420");
var claim = Given_an_expense_claim(user.Id, receipt1.Id, receipt2.Id);
Assert.AreEqual(70m, claim.Total);
}
}
}
================================================
FILE: CoreTests/Integration/ExpenseClaims/ExpenseClaimTest.cs
================================================
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.ExpenseClaims
{
public abstract class ExpenseClaimTest : ApiWrapperTest
{
public Receipt Given_a_receipt(Guid userId, string contactName, string description, decimal amount, string account)
{
return Api.Create(new Receipt
{
Date = DateTime.UtcNow.Date,
Contact = new Contact { Name = contactName },
LineAmountTypes = LineAmountType.Inclusive,
Status = ReceiptStatus.Draft,
LineItems = new List
{
new LineItem
{
Description = description,
UnitAmount = amount,
AccountCode = account
}
},
Total = amount,
User = new User
{
Id = userId
}
});
}
public ExpenseClaim Given_an_expense_claim(Guid userId, Guid receiptId1, Guid receiptId2)
{
return Api.Create(new ExpenseClaim
{
User = new User
{
Id = userId
},
Receipts = new List
{
new Receipt
{
Id = receiptId1
},
new Receipt
{
Id = receiptId2
},
}
});
}
}
}
================================================
FILE: CoreTests/Integration/ExpenseClaims/Update.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.ExpenseClaims
{
[TestFixture]
public class Update : ExpenseClaimTest
{
[Test]
public void authorise_expense_claim()
{
var user = Api.Users.Find().First();
var receipt1 = Given_a_receipt(user.Id, Random.GetRandomString(10), Random.GetRandomString(30), 20m, "420");
var receipt2 = Given_a_receipt(user.Id, Random.GetRandomString(10), Random.GetRandomString(30), 50m, "420");
var claim = Given_an_expense_claim(user.Id, receipt1.Id, receipt2.Id);
var authorised = Api.Update(
new ExpenseClaim
{
Id = claim.Id,
Status = ExpenseClaimStatus.Authorised
});
Assert.AreEqual(ExpenseClaimStatus.Authorised, authorised.Status);
}
[Test]
public void void_expense_claim()
{
var user = Api.Users.Find().First();
var receipt1 = Given_a_receipt(user.Id, Random.GetRandomString(10), Random.GetRandomString(30), 20m, "420");
var receipt2 = Given_a_receipt(user.Id, Random.GetRandomString(10), Random.GetRandomString(30), 50m, "420");
var claim = Given_an_expense_claim(user.Id, receipt1.Id, receipt2.Id);
var authorised = Api.Update(
new ExpenseClaim
{
Id = claim.Id,
Status = ExpenseClaimStatus.Authorised
});
var voided = Api.Update(
new ExpenseClaim
{
Id = authorised.Id,
Status = ExpenseClaimStatus.Voided
});
Assert.AreEqual(ExpenseClaimStatus.Voided, voided.Status);
}
}
}
================================================
FILE: CoreTests/Integration/Files/Associations/AssociationTest.cs
================================================
using System;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Files.Associations
{
[TestFixture]
public class AssociationTest : ApiWrapperTest
{
private Guid FindAFileId()
{
var file = Api.Files.Find().FirstOrDefault();
return file == null ? Guid.Empty : file.Id;
}
private Guid FindAnInvoiceId()
{
var invoice = Api.Invoices.Find().FirstOrDefault();
return invoice == null ? Guid.Empty : invoice.Id;
}
[Test]
public void AssociationsForFile()
{
Assert.DoesNotThrow(() =>
{
var fileId = FindAFileId();
var list = Api.Associations.Find(fileId);
Debug.WriteLine("Found {0} associations for file {1}.", list.Count(), fileId);
});
}
[Test]
public void AssociationsForObject()
{
Assert.DoesNotThrow(() =>
{
var objectId = FindAnInvoiceId();
var list = Api.Associations.FindForObject(objectId);
Debug.WriteLine("Found {0} associations for object {0}.", list.Count(), objectId);
});
}
// This is not a great test - but it needs to run in sequence and clean up after itself
// (if it happens to be working with an association that should already exist, then we have a problem...)
[Test]
public void AssociationCreateFindAndDelete()
{
var fileId = FindAFileId();
var objectId = FindAnInvoiceId();
Assert.DoesNotThrow(() =>
{
var toCreate = new Association
{
FileId = fileId,
ObjectId = objectId,
ObjectGroup = ObjectGroupType.Invoice
};
var created = Api.Associations.Create(toCreate);
Debug.WriteLine("Created {0}", created);
});
Assert.DoesNotThrow(() =>
{
var found = Api.Associations.Find(fileId, objectId);
Debug.WriteLine("Found {0}", found);
});
Assert.DoesNotThrow(() =>
{
var toDelete = new Association
{
FileId = fileId,
ObjectId = objectId,
ObjectGroup = ObjectGroupType.Invoice
};
Api.Associations.Delete(toDelete);
Debug.WriteLine("Deleted {0}", toDelete);
});
}
}
}
================================================
FILE: CoreTests/Integration/Files/Files/AddFileTest.cs
================================================
using System;
using System.Collections;
using System.Net;
using CoreTests.Integration.Files.Support;
using NUnit.Framework;
using Xero.Api.Core.Model;
using File = Xero.Api.Core.Model.File;
namespace CoreTests.Integration.Files.Files
{
[TestFixture]
public class AddFileTest : FilesTest
{
[Test]
public void can_get_all_files_like_this()
{
var result = Api.Files.Find();
Assert.True(result != null);
}
[Test]
public void can_get_the_content_of_a_file_like_this()
{
var filename = "My Test File " + Guid.NewGuid() + ".png";
var inboxId = Api.Inbox.InboxFolder.Id;
var id = Given_a_file_in(inboxId, filename);
var content = Api.Files.GetContent(id,"image/png");
Assert.IsTrue(StructuralComparisons.StructuralEqualityComparer.Equals(content,exampleFile));
}
[Test]
public void can_remove_a_file_like_this()
{
var inboxId = Api.Inbox.InboxFolder.Id;
var result = Given_a_file_in(inboxId, "Test " + Guid.NewGuid() + ".png");
Api.Files.Remove(result);
var notfound= Api.Files[result];
Assert.IsNull(notfound);
}
[Test]
public void can_rename_a_file_like_this()
{
var inboxId = Api.Inbox.InboxFolder.Id;
var result = Given_a_file_in(inboxId, "Test " + Guid.NewGuid() + ".png");
var copy = Api.Files[result];
var NewName = "someother name";
var updateResult = Api.Files.Rename(copy.Id, NewName);
Assert.IsTrue(updateResult.Name == NewName);
}
[Test]
public void can_move_a_file_like_this()
{
var inboxId = Api.Inbox.InboxFolder.Id;
var result = Given_a_file_in(inboxId, "Test " + Guid.NewGuid() + ".png");
var newFolder = Api.Folders.Add("stuff");
var updateResult = Api.Files.Move(result, newFolder.Id);
Assert.IsTrue(updateResult.FolderId == newFolder.Id);
}
[Test]
public void cannot_add_a_file_with_bad_filename_charactors()
{
var inboxId = Api.Inbox.InboxFolder.Id;
char[] badchar = System.IO.Path.GetInvalidFileNameChars();
var filename = "Inbox file " + badchar[0] + badchar[3] + badchar[2] + ".png"; ;
Assert.Throws(() =>
{
Api.Files.Add( inboxId, create_file_with_name(filename), exampleFile);
});
}
private File create_file_with_name(string filename)
{
return new Xero.Api.Core.Model.File()
{
Name = filename,
FileName = filename,
Mimetype = "image/png",
User = new FilesUser()
{
FirstName = "Bart",
LastName = "Simpson",
FullName = "Bart Simpson",
Name = "Bart@gmail.com"
}
};
}
}
}
================================================
FILE: CoreTests/Integration/Files/Folders/AddFolderTest.cs
================================================
using System;
using CoreTests.Integration.Files.Support;
using NUnit.Framework;
namespace CoreTests.Integration.Files.Folders
{
public class AddFolderTest : FilesTest
{
[Test]
public void can_create_a_folder_like_this()
{
var result = Api.Folders.Add("Test Folder" + Guid.NewGuid());
}
[Test]
public void can_get_all_folders_like_this()
{
var allFolders = Api.Folders.Folders;
Assert.True(allFolders[0].Name == "Inbox");
Assert.True(allFolders[1].Name == "Contracts");
}
[Test]
public void can_remove_a_folder_like_this()
{
var folder = Api.Folders.Add("Test Folder" + Guid.NewGuid());
Api.Folders.Remove(folder.Id); // Hint ->folder is empty
}
}
}
================================================
FILE: CoreTests/Integration/Files/Inbox/InboxTest.cs
================================================
using System;
using CoreTests.Integration.Files.Support;
using NUnit.Framework;
using Xero.Api.Core.Model;
using File = Xero.Api.Core.Model.File;
namespace CoreTests.Integration.Files.Inbox
{
[TestFixture]
public class InboxTest : FilesTest
{
[Test]
public void can_get_the_inbox_like_this()
{
var inbox = Api.Inbox.InboxFolder;
Assert.IsTrue(inbox.Name == "Inbox");
Assert.IsTrue(inbox.IsInbox);
}
[Test]
public void can_add_a_file_to_inbox_like_this()
{
var filename = "Inbox file " + Guid.NewGuid() + ".png";
var result = Api.Inbox.Add(create_file_with_name(filename), exampleFile);
var file = Api.Files[result.Id];
Assert.IsTrue(file.Mimetype == "image/png");
Assert.IsTrue(file.Name == filename);
}
[Test]
public void can_remove_a_file_like_this()
{
var inboxId = Api.Inbox.InboxFolder.Id;
var result = Given_a_file_in(inboxId, "Test " + Guid.NewGuid() + ".png");
Api.Inbox.Remove(result);
var notfound = Api.Inbox[result];
Assert.IsNull(notfound);
}
private File create_file_with_name(string filename)
{
return new Xero.Api.Core.Model.File()
{
Name = filename,
FileName = filename,
Mimetype = "image/png",
User = new FilesUser()
{
FirstName = "Bart",
LastName = "Simpson",
FullName = "Bart Simpson",
Name = "Bart@gmail.com"
}
};
}
}
}
================================================
FILE: CoreTests/Integration/Files/Support/DataItem.cs
================================================
using System;
using System.IO;
namespace CoreTests.Integration.Files.Support
{
public class DataItem : IDisposable
{
public String ContentType { get; set; }
public Stream Content { get; private set; }
public DataItem(FileInfo file, String contentType = "unknown")
{
Content = file.OpenRead();
ContentType = contentType;
}
public DataItem(Byte[] data, String contentType = "unknown")
{
ContentType = contentType;
Content = new MemoryStream(data);
}
public void Dispose()
{
if (Content != null)
{
Content.Close();
}
}
}
}
================================================
FILE: CoreTests/Integration/Files/Support/DiskFile.cs
================================================
using System.IO;
namespace CoreTests.Integration.Files.Support
{
public class DiskFile : File
{
public string Name { get; private set; }
public string Path { get; private set; }
public int ContentLength { get; private set; }
public DiskFile(string name)
: this(name, name)
{ }
public DiskFile(string name, string path)
{
Name = name;
Path = string.Format("resources\\images\\{0}", path);
ContentLength = (int)new FileInfo(Path).Length;
}
}
}
================================================
FILE: CoreTests/Integration/Files/Support/File.cs
================================================
namespace CoreTests.Integration.Files.Support
{
public interface File
{
string Name { get; }
string Path { get; }
int ContentLength { get; }
}
}
================================================
FILE: CoreTests/Integration/Files/Support/FilesTest.cs
================================================
using System;
using System.IO;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.Files.Support
{
public class FilesTest : ApiWrapperTest
{
protected byte[] exampleFile;
private const string ImagePath = @"connect_xero_button_blue.png";
public FilesTest()
{
exampleFile = GetFileBytes("xero", ImagePath);
}
private Xero.Api.Core.Model.File create_file_with_name(string filename)
{
return new Xero.Api.Core.Model.File()
{
Name = filename,
FileName = filename,
Mimetype = "image/png",
User = new FilesUser()
{
FirstName = "Bart",
LastName = "Simpson",
FullName = "Bart Simpson",
Name = "Bart@gmail.com"
}
};
}
protected Guid Given_a_file_in(Guid folderId, string filename)
{
var file = create_file_with_name(filename);
return Given_a_file_in(folderId, file);
}
protected Guid Given_a_file_in(Guid folderId)
{
var filename = "Test" + Guid.NewGuid() + ".png";
return Given_a_file_in(folderId, create_file_with_name(filename));
}
protected Guid Given_a_file_in(Guid folderId,Xero.Api.Core.Model.File file )
{
var result = Api.Files.Add(folderId, file, exampleFile);
return result.Id ;
}
internal static byte[] GetFileBytes(string name, string fileName)
{
var file = new FileInfo(new DiskFile(name, fileName).Path);
var data = new DataItem(file);
byte[] bytes;
using (var ms = new MemoryStream())
{
data.Content.CopyTo(ms);
bytes = ms.ToArray();
}
return bytes;
}
}
}
================================================
FILE: CoreTests/Integration/General/Errors.cs
================================================
using System.Collections.Generic;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.General
{
[TestFixture]
public class Errors : ApiWrapperTest
{
[Test]
public void not_found()
{
Assert.Throws(() => Api.Invoices.Find("ThisIsNotThere"));
}
[Test]
public void bad_query()
{
Assert.Throws(() => Api.Invoices.Where("Bob == Robert").Find());
}
[Test]
public void validation_error()
{
Assert.Throws(() => Api.Invoices.Create(new Invoice
{
LineItems = new List
{
new LineItem
{
LineAmount = 101.01M
}
}
}));
}
}
}
================================================
FILE: CoreTests/Integration/General/FindingAllItems.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.General
{
[TestFixture]
public class FindingAllItems : ApiWrapperTest
{
[Test]
public void get_accounts()
{
Assert.DoesNotThrow(() => Api.Accounts.Find());
}
[Test]
public void get_bank_transactions()
{
Assert.DoesNotThrow(() => Api.BankTransactions.Find());
}
[Test]
public void get_bank_transfers()
{
Assert.DoesNotThrow(() => Api.BankTransfers.Find());
}
[Test]
public void get_branding_themes()
{
Assert.DoesNotThrow(() => Api.BrandingThemes.Find());
}
[Test]
public void get_contacts()
{
Assert.DoesNotThrow(() => Api.Contacts.Find());
}
[Test]
public void get_credit_notes()
{
Assert.DoesNotThrow(() => Api.CreditNotes.Find());
}
[Test]
public void get_currencies()
{
Assert.DoesNotThrow(() => Api.Currencies.Find());
}
[Test]
public void get_employees()
{
Assert.DoesNotThrow(() => Api.Employees.Find());
}
[Test]
public void get_expense_claims()
{
Assert.DoesNotThrow(() => Api.ExpenseClaims.Find());
}
[Test]
public void get_invoices()
{
Assert.DoesNotThrow(() => Api.Invoices.Find());
}
[Test]
public void get_items()
{
Assert.DoesNotThrow(() => Api.Items.Find());
}
[Test]
public void get_journals()
{
Assert.DoesNotThrow(() => Api.Journals.Find());
}
[Test]
public void get_manual_journals()
{
Assert.DoesNotThrow(() => Api.ManualJournals.Find());
}
[Test]
public void get_payments()
{
Assert.DoesNotThrow(() => Api.Payments.Find());
}
[Test]
public void get_receipts()
{
Assert.DoesNotThrow(() => Api.Receipts.Find());
}
[Test]
public void get_repeating_invoices()
{
Assert.DoesNotThrow(() => Api.RepeatingInvoices.Find());
}
[Test]
public void get_tax_rates()
{
Assert.DoesNotThrow(() => Api.TaxRates.Find());
}
[Test]
public void get_tracking_categories()
{
Assert.DoesNotThrow(() => Api.TrackingCategories.Find());
}
[Test]
public void get_users()
{
Assert.DoesNotThrow(() => Api.Users.Find());
}
}
}
================================================
FILE: CoreTests/Integration/General/QueryStrings.cs
================================================
using System;
using NUnit.Framework;
namespace CoreTests.Integration.General
{
[TestFixture]
public class QueryStrings : ApiWrapperTest
{
[Test]
public void query_string_is_as_expected()
{
Assert.DoesNotThrow(() => Api.Invoices.Where("Status == \"ACTIVE\"").Find());
}
[Test]
public void complex_query_string_is_as_expected()
{
var startDate = DateTime.UtcNow.AddDays(-30).Date.ToString("yyyy-MM-dd");
var endDate = DateTime.UtcNow.Date.ToString("yyyy-MM-dd");
Assert.DoesNotThrow(() => Api.Invoices.Where("Status == \"ACTIVE\"")
.And(string.Format("DueDate >= DateTime.Parse(\"{0}\")", startDate))
.And(string.Format("DueDate <= DateTime.Parse(\"{0}\")", endDate))
.OrderByDescending("DueDate").Find());
}
[Test]
public void contact_query_string_is_as_expected()
{
Assert.DoesNotThrow(() => Api.Contacts.IncludeArchived(true).Find());
}
}
}
================================================
FILE: CoreTests/Integration/HistoryAndNotes/CreateNotes.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.HistoryAndNotes
{
public class CreateNotes : HistoryAndNotesTest
{
[Test]
public void Can_create_notes()
{
const string details = "Details";
Given_a_contact();
Given_a_note_with_these_details(details);
When_I_retrieve_history_and_notes_for_the_contact();
Then_there_is_a_note_with_the_correct_details(details);
}
}
}
================================================
FILE: CoreTests/Integration/HistoryAndNotes/Find.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.HistoryAndNotes
{
public class Find : HistoryAndNotesTest
{
[Test]
public void Can_fetch_history_and_notes()
{
Given_a_contact();
When_I_retrieve_history_and_notes_for_the_contact();
Then_there_are_some_history_records();
}
}
}
================================================
FILE: CoreTests/Integration/HistoryAndNotes/HistoryAndNotesTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.HistoryAndNotes
{
public class HistoryAndNotesTest : ApiWrapperTest
{
private Contact _contact;
private IEnumerable _historyRecords;
protected void Given_a_contact()
{
_contact = Api.Contacts.Create(new Contact { Name = Guid.NewGuid().ToString() });
}
protected void Given_a_note_with_these_details(string details)
{
Api.HistoryAndNotes.CreateNote(HistoryAndNotesEndpointCreateType.Contacts, _contact.Id,
new HistoryRecord
{
Details = details
});
}
protected void When_I_retrieve_history_and_notes_for_the_contact()
{
_historyRecords = Api.HistoryAndNotes.Find(HistoryAndNotesEndpointRetrieveType.Contacts, _contact.Id);
}
protected void Then_there_are_some_history_records()
{
Assert.True(_historyRecords.Any(), "Expected some history records to be returned, but there were none");
}
protected void Then_there_is_a_note_with_the_correct_details(string details)
{
Assert.True(_historyRecords.Any(it => it.Details == details), "Expected a note with the expected details to be returned but it was not");
}
}
}
================================================
FILE: CoreTests/Integration/Invoices/Create.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Invoices
{
[TestFixture]
public class Create : InvoicesTest
{
[Test]
public void simple_create_works()
{
var invoice = Given_an_invoice();
Assert.True(invoice.Id != Guid.Empty);
}
[Test]
public void description_only_items_work()
{
const InvoiceType expected = InvoiceType.AccountsPayable;
var type = Given_a_description_only_invoice().Type;
Assert.AreEqual(expected, type);
}
[Test]
public void accounts_receivable()
{
const InvoiceType expected = InvoiceType.AccountsReceivable;
var type = Given_a_description_only_invoice(expected).Type;
Assert.AreEqual(expected, type);
}
[Test]
public void lineItemId_is_returned()
{
var invoce = Given_an_invoice();
Assert.NotNull(invoce.LineItems.FirstOrDefault().LineItemId);
}
[Test]
public void multiple_lineitems()
{
var invoice = Api.Create(new Invoice
{
Contact = new Contact { Name = "ABC Limited" },
Type = InvoiceType.AccountsReceivable,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
UnitAmount = 25.6m,
Quantity = 1m
},
new LineItem
{
AccountCode = "200",
Description = "Another good value item",
UnitAmount = 125.65m,
Quantity = 5m
}
}
});
Assert.True(invoice.Id != Guid.Empty);
Assert.AreEqual(InvoiceType.AccountsReceivable, invoice.Type);
Assert.AreEqual(2, invoice.LineItems.Count());
}
[Test]
public void multiple_invoices()
{
var invoices = Api.Create(new[]
{
new Invoice
{
Contact = new Contact { Name = "ABC Limited" },
Type = InvoiceType.AccountsReceivable,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
UnitAmount = 25.6m,
Quantity = 1m
}
}
},
new Invoice
{
Contact = new Contact { Name = "Jack" },
Type = InvoiceType.AccountsReceivable,
LineItems = new List
{
new LineItem
{
AccountCode = "150",
Description = "Other Sales Item",
UnitAmount = 120.5m,
Quantity = 5m
}
}
}
}).ToList();
Assert.AreEqual(2, invoices.Count());
Assert.AreEqual(2, invoices.Select(p => p.Id).Count());
}
[Test]
public void high_precision_unit()
{
var invoice = Api.Create(
new Invoice
{
Contact = new Contact { Name = "ABC Limited" },
Type = InvoiceType.AccountsReceivable,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
UnitAmount = 25.6591m,
Quantity = 1m
}
}
});
Assert.AreEqual(25.6591m, invoice.LineItems.First().UnitAmount);
}
[Test]
public void low_precision_unit()
{
var invoices = Api.Invoices.UseFourDecimalPlaces(false).Create(new[]
{
new Invoice
{
Contact = new Contact { Name = "ABC Limited" },
Type = InvoiceType.AccountsReceivable,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
UnitAmount = 25.6591m,
Quantity = 1m
}
}
}
}).ToList();
Assert.AreEqual(25.66m, invoices.First().LineItems.First().UnitAmount);
}
[Test]
public void full_example_line_items_with_tracking_categories()
{
const string name = "Region";
const string option = "North";
const string currency = "NZD";
const string url = "http://accounting20.com/";
var category = new Guid("351953c4-8127-4009-88c3-f9cd8c9cbe9f");
var dueDate = DateTime.Now.AddDays(30).Date;
var paymentDate = DateTime.Now.AddDays(20).Date;
var reference = "Ref:" + Random.GetRandomString(10);
var invoices = Api.Invoices.Create(new[]
{
new Invoice
{
Contact = new Contact { Name = "Ariki Properties" },
DueDate = dueDate,
ExpectedPaymentDate = paymentDate,
Type = InvoiceType.AccountsReceivable,
LineAmountTypes = LineAmountType.Inclusive,
CurrencyCode = currency,
Number = Random.GetRandomString(10),
Reference = reference,
BrandingThemeId = new Guid("4c82c365-35cb-467f-bb11-dce1f2f2f67c"),
Url = url,
Status = InvoiceStatus.Submitted,
TotalTax = 10.89m,
SubTotal = 87.11m,
Total = 98.00m,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "3 copies of OS X 10.6 Snow Leopard",
UnitAmount = 59.00m,
Quantity = 3m,
TaxAmount = 19.97m,
TaxType = "OUTPUT2",
LineAmount = 177.00m,
Tracking = new ItemTracking
{
new ItemTrackingCategory
{
Id = category,
Name = name,
Option = option
}
}
},
new LineItem
{
AccountCode = "200",
Description = "Returned Apple Keyboard with Numeric Keypad (faulty)",
UnitAmount = -79.00m,
Quantity = 1m,
TaxAmount = -8.78m,
TaxType = "OUTPUT2",
}
}
}
}).ToList();
var invoice = Api.Invoices.Find(invoices.First().Id);
Assert.AreEqual(category, invoice.LineItems.First().Tracking[0].Id);
Assert.AreEqual(name, invoice.LineItems.First().Tracking[0].Name);
Assert.AreEqual(option, invoice.LineItems.First().Tracking[0].Option);
Assert.AreEqual(dueDate, invoice.DueDate);
Assert.AreEqual(paymentDate, invoice.ExpectedPaymentDate);
Assert.AreEqual(reference, invoice.Reference);
Assert.AreEqual(currency, invoice.CurrencyCode);
Assert.AreEqual(url, invoice.Url);
}
[Test]
public void lineitems_without_account_code()
{
var item = Api.Items
.Where("Code.StartsWith(\"Woo-hoo\")")
.And("Description != null")
.Find()
.FirstOrDefault();
if (item == null)
{
Assert.False(false, "No items");
}
var invoice = Api.Create(new Invoice
{
Contact = new Contact { Name = "ABC Limited" },
Type = InvoiceType.AccountsReceivable,
LineItems = new List
{
new LineItem
{
Description = item.Description,
ItemCode = item.Code
}
}
});
Assert.True(invoice.Id != Guid.Empty);
Assert.AreEqual(InvoiceType.AccountsReceivable, invoice.Type);
Assert.AreEqual(1, invoice.LineItems.Count());
}
}
}
================================================
FILE: CoreTests/Integration/Invoices/Find.cs
================================================
using System;
using System.Collections;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Invoices
{
[TestFixture]
public class Find : InvoicesTest
{
[Test]
public void find_by_page()
{
Given_an_invoice();
var invoices = Api.Invoices.Page(1).Find();
Assert.Greater(invoices.Count(), 0);
}
[Test]
public void find_by_id()
{
var expected = Given_an_invoice().Id;
var id = Api.Invoices.Find(expected).Id;
Assert.AreEqual(expected, id);
}
[Test]
public void find_by_id_list()
{
var created = Given_an_invoice();
var invoices = Api.Invoices.Ids(new[] {created.Id}).Find().ToList();
Assert.AreEqual(1, invoices.Count());
Assert.AreEqual(created.Id, invoices.First().Id);
}
[Test]
public void find_by_statuses_list()
{
var created = Given_an_invoice();
var invoices = Api.Invoices.Statuses(new[] {created.Status}).Find().ToList();
Assert.True(invoices.Any(it => it.Id == created.Id));
}
[Test]
public void find_by_contact_id_list()
{
var created = Given_an_invoice();
var invoices = Api.Invoices.ContactIds(new[] {created.Contact.Id}).Find().ToList();
Assert.True(invoices.Any(it => it.Id == created.Id));
}
[Test]
public void find_by_invoice_number_list()
{
var created = Given_an_invoice(invoiceNumber: Guid.NewGuid().ToString());
var invoices = Api.Invoices.InvoiceNumbers(new[] {created.Number}).Find().ToList();
Assert.True(invoices.Any(it => it.Id == created.Id));
}
[Test]
public void find_by_mixture_of_query_param_lists()
{
var created = Given_an_invoice(invoiceNumber: Guid.NewGuid().ToString());
var invoices = Api.Invoices
.Ids(new [] {created.Id})
.ContactIds(new [] { created.Contact.Id })
.Statuses(new [] {created.Status})
.InvoiceNumbers(new [] {created.Number})
.Find().ToList();
Assert.True(invoices.Any(it => it.Id == created.Id));
}
[Test]
public void find_by_value()
{
Given_an_invoice();
var invoices = Api.Invoices
.Where("Type == \"ACCREC\"")
.Find()
.ToList();
Assert.True(invoices.Any());
Assert.True(invoices.All(p => p.Type == InvoiceType.AccountsReceivable));
}
[Test]
public void find_by_due_date()
{
Given_an_invoice();
var today = DateTime.UtcNow;
var invoices = Api.Invoices
.Where(string.Format("DueDate > DateTime({0},{1},{2})", today.Year, today.Month, today.Day ))
.Find()
.ToList();
Assert.True(invoices.Any());
}
[Test]
public void order_by_type()
{
var invoices = Api.Invoices.OrderByDescending("Type").Find();
Assert.AreEqual(InvoiceType.AccountsReceivable, invoices.First().Type);
}
}
}
================================================
FILE: CoreTests/Integration/Invoices/InvoicesTest.cs
================================================
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.Invoices
{
public abstract class InvoicesTest : ApiWrapperTest
{
public Invoice Given_an_draft_invoice(InvoiceType type = InvoiceType.AccountsPayable)
{
return Given_an_invoice(type);
}
public Invoice Given_an_authorised_invoice(InvoiceType type = InvoiceType.AccountsPayable)
{
return Given_an_invoice(type, InvoiceStatus.Authorised);
}
public Invoice Given_an_invoice(InvoiceType type = InvoiceType.AccountsPayable, InvoiceStatus status = InvoiceStatus.Draft, string invoiceNumber = null)
{
return Api.Create(new Invoice
{
Contact = new Contact { Name = "ABC Bank" },
Type = type,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = status,
Number = invoiceNumber,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
LineAmount = 100m
}
}
});
}
public Invoice Given_a_description_only_invoice(InvoiceType type = InvoiceType.AccountsPayable)
{
return Api.Create(new Invoice
{
Contact = new Contact { Name = "Richard" },
Type = type,
LineItems = new List
{
new LineItem
{
Description = "This is description only",
LineAmount = 100m
}
}
});
}
}
}
================================================
FILE: CoreTests/Integration/Invoices/OnlineInvoiceUrl.cs
================================================
using NUnit.Framework;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Invoices
{
[TestFixture]
public class OnlineInvoiceUrl : InvoicesTest
{
[Test]
public void find_the_online_invoice_url_for_an_accrec_invoice()
{
var invoice = Given_an_invoice(InvoiceType.AccountsReceivable, InvoiceStatus.Authorised);
var onlineInvoiceUrl = Api.Invoices.RetrieveOnlineInvoiceUrl(invoice.Id);
Assert.True(!string.IsNullOrEmpty(onlineInvoiceUrl.OnlineInvoiceUrl));
}
}
}
================================================
FILE: CoreTests/Integration/Invoices/SummarizeErrors.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.Invoices
{
[TestFixture]
public class SummarizeErrors : InvoicesTest
{
[Test]
public void summariseErrors_gives_200()
{
var invoices = Given_a_bad_invoice(summariseErrors: false);
Assert.True(invoices.Count(p => p.ValidationStatus == ValidationStatus.Error) == 1);
Assert.True(invoices.Count(p => p.ValidationStatus == ValidationStatus.Ok) == 1);
}
[Test] public void errors_gives_validation_exception()
{
Assert.Throws(() => Given_a_bad_invoice());
}
private IEnumerable Given_a_bad_invoice(InvoiceType type = InvoiceType.AccountsPayable, InvoiceStatus status = InvoiceStatus.Draft, bool summariseErrors = true)
{
Api.Invoices.SummarizeErrors(summariseErrors);
return Api.Create(new[]
{
new Invoice
{
Contact = new Contact {Name = "ABC Bank"},
Type = type,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = status,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
LineAmount = 100m
}
}
},
new Invoice
{
Contact = new Contact
{
Name = "ABC Bank",
EmailAddress = "this_is_!_valid"
},
Type = type,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = status,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item",
LineAmount = 100m
}
}
}
});
}
}
}
================================================
FILE: CoreTests/Integration/Items/Create.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.Items
{
[TestFixture]
public class Create : ApiWrapperTest
{
[Test]
public void create_simple_item()
{
var code = "Woo-hoo " + Random.GetRandomString(10);
var item = Api.Create(new Item
{
Code = code
});
Assert.IsTrue(Guid.Empty != item.Id);
Assert.AreEqual(code, item.Code);
}
[Test]
public void create_full_item()
{
var code = "Woo-hoo " + Random.GetRandomString(10);
var item = Api.Create(new Item
{
Code = code,
Description = "Buy cheap sell high",
SalesDetails = new SalesDetails
{
AccountCode = "200",
UnitPrice = 25.00m
},
PurchaseDetails = new PurchaseDetails
{
AccountCode = "200",
UnitPrice = 15.0m
}
});
}
}
}
================================================
FILE: CoreTests/Integration/Items/Delete.cs
================================================
using System;
using CoreTests.Integration.Items.TrackedItems;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.Items
{
[TestFixture]
public class Delete : TrackedInventoryTest
{
[Test]
public void you_can_delete_an_item()
{
Given_a_tracked_item();
Api.Items.Delete(CreatedItem);
Its_not_there_when_I_try_to_find_it(CreatedItem);
}
[Test]
public void but_not_if_its_involved_in_a_transaction()
{
Given_a_tracked_item();
Given_an_ACCPAY_invoice_using_the_item_with_code(CreatedItem.Code);
When_I_try_to_Delete_it_400s();
}
[Test]
public void and_it_will_404_if_you_try_to_delete_a_item_thats_not_there()
{
CreatedItem = new Item
{
Id = Guid.NewGuid()
};
When_I_try_to_Delete_it_404s();
}
private void When_I_try_to_Delete_it_404s()
{
Assert.Throws(() => Api.Items.Delete(CreatedItem));
}
private void When_I_try_to_Delete_it_400s()
{
Assert.Throws(() => Api.Items.Delete(CreatedItem));
}
private void Its_not_there_when_I_try_to_find_it(Item theItem)
{
Assert.Throws(() => Api.Items.Find(theItem.Id));
}
}
}
================================================
FILE: CoreTests/Integration/Items/TrackedItems/Create.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.Items.TrackedItems
{
public class Create : TrackedInventoryTest
{
[Test]
public void Can_create_an_item_with_minimal_properties()
{
Given_an_inventory_account();
Given_a_direct_cost_account();
var item = Api.Items.Create(new Item
{
Code = "Tracked Item " + Random.GetRandomString(10),
InventoryAssetAccountCode = InventoryAccountCode,
PurchaseDetails = new PurchaseDetails
{
COGSAccountCode = DirectCostsAccountCode
}
});
Assert.True(item.IsTrackedAsInventory,
"Expected the item to be tracked as inventory, but IsTrackedAsInventory is false");
}
[Test]
public void Can_create_an_item_with_full_details()
{
Given_an_inventory_account();
Given_a_direct_cost_account();
Given_a_revenue_account();
var code = "Tracked Item " + Random.GetRandomString(10);
var item = Api.Items.Create(new Item
{
Code = code,
Description = "Sell me",
PurchaseDescription = "Purchase me",
PurchaseDetails = new PurchaseDetails
{
UnitPrice = 75.5555m,
TaxType = "INPUT2",
COGSAccountCode = DirectCostsAccountCode
},
SalesDetails = new SalesDetails
{
UnitPrice = 1020.5555m,
AccountCode = RevenueAccountCode,
TaxType = "OUTPUT2"
},
Name = "Full Tracked Item",
InventoryAssetAccountCode = InventoryAccountCode,
IsSold = true,
IsPurchased = true
});
Assert.True(item.Id != Guid.Empty);
Assert.True(item.IsTrackedAsInventory = true);
Assert.AreEqual(item.Code, code,
string.Format("Expected the create item's code '{0}' to equal '{1}', but were not equal", item.Code,
code));
}
}
}
================================================
FILE: CoreTests/Integration/Items/TrackedItems/Find.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.Items.TrackedItems
{
public class Find : TrackedInventoryTest
{
[Test]
public void Can_get_tracked_item_by_id()
{
Given_a_tracked_item();
var trackedItem = Api.Items.Find(CreatedItem.Id);
Assert.AreEqual(CreatedItem.Id, trackedItem.Id, "Expected the ID of the created item and retrieved item to be the same but weren't");
Assert.True(trackedItem.IsTrackedAsInventory, "Expected the retrieved items IsTrackedAsInventory value to be true, but was false");
}
}
}
================================================
FILE: CoreTests/Integration/Items/TrackedItems/TrackedInventoryTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Items.TrackedItems
{
public class TrackedInventoryTest : ApiWrapperTest
{
protected Item CreatedItem;
protected Invoice CreatedAccpayInvoice { get; set; }
protected Invoice CreatedAccrecInvoice { get; set; }
protected string InventoryAccountCode;
protected string DirectCostsAccountCode;
protected string RevenueAccountCode;
public void Given_a_tracked_item()
{
if (string.IsNullOrEmpty(InventoryAccountCode))
{
Given_an_inventory_account();
}
if (string.IsNullOrEmpty(DirectCostsAccountCode))
{
Given_a_direct_cost_account();
}
if (string.IsNullOrEmpty(RevenueAccountCode))
{
Given_a_revenue_account();
}
var code = "Tracked Item" + Random.GetRandomString(10);
var item = Api.Items.Create(new Item
{
Code = code,
Description = "Sell me",
PurchaseDescription = "Purchase me",
PurchaseDetails = new PurchaseDetails
{
UnitPrice = 75.5555m,
TaxType = "INPUT2",
COGSAccountCode = DirectCostsAccountCode
},
SalesDetails = new SalesDetails
{
UnitPrice = 1020.5555m,
AccountCode = RevenueAccountCode,
TaxType = "OUTPUT2"
},
Name = "Full Tracked Item",
InventoryAssetAccountCode = InventoryAccountCode,
IsSold = true,
IsPurchased = true
});
CreatedItem = item;
}
public void Given_an_untracked_item()
{
if (string.IsNullOrEmpty(DirectCostsAccountCode))
{
Given_a_direct_cost_account();
}
if (string.IsNullOrEmpty(RevenueAccountCode))
{
Given_a_revenue_account();
}
var code = "Untracked Item" + Random.GetRandomString(10);
var item = Api.Items.Create(new Item
{
Code = code,
Description = "Sell me",
PurchaseDescription = "Purchase me",
PurchaseDetails = new PurchaseDetails
{
UnitPrice = 75.5555m,
TaxType = "INPUT2",
AccountCode = DirectCostsAccountCode
},
SalesDetails = new SalesDetails
{
UnitPrice = 1020.5555m,
AccountCode = RevenueAccountCode,
TaxType = "OUTPUT2"
},
Name = "Untracked Item",
IsSold = true,
IsPurchased = true
});
CreatedItem = item;
}
protected void Given_a_direct_cost_account()
{
var directCostsAccount = Api.Accounts.Where("Type == \"DIRECTCOSTS\"").Find().FirstOrDefault();
if (directCostsAccount == null)
{
directCostsAccount = Api.Accounts.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.DirectCosts,
Description = "Direct costs account",
Name = "Direct costs account"
});
}
DirectCostsAccountCode = directCostsAccount.Code;
}
protected void Given_a_revenue_account()
{
var revenueAccount = Api.Accounts.Where("Type == \"REVENUE\"").Find().FirstOrDefault();
if (revenueAccount == null)
{
revenueAccount = Api.Accounts.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.Revenue,
Description = "Revenue account",
Name = "Revenue account"
});
}
RevenueAccountCode = revenueAccount.Code;
}
protected void Given_an_inventory_account()
{
var inventoryAccount = Api.Accounts.Where("Type == \"INVENTORY\"").Find().FirstOrDefault();
if (inventoryAccount == null)
{
inventoryAccount = Api.Accounts.Create(new Account
{
Code = Random.GetRandomString(10),
Type = AccountType.Inventory,
Description = "The account to hold all the things",
Name = "My inventory account"
});
}
InventoryAccountCode = inventoryAccount.Code;
}
protected void Given_an_ACCPAY_invoice_using_the_item_with_code(string code)
{
var invoice = new Invoice
{
Contact = new Contact { Name = "ABC Bank" },
Type = InvoiceType.AccountsPayable,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = InvoiceStatus.Authorised,
LineItems = new List
{
new LineItem
{
ItemCode = code,
AccountCode = InventoryAccountCode,
Quantity = 2
}
}
};
CreatedAccpayInvoice = Api.Invoices.Create(invoice);
}
protected void Given_a_zero_total_ACCPAY_invoice_using_the_item_with_code(string code)
{
var invoice = new Invoice
{
Contact = new Contact { Name = "ABC Bank" },
Type = InvoiceType.AccountsPayable,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = InvoiceStatus.Authorised,
LineItems = new List
{
new LineItem
{
ItemCode = code,
AccountCode = InventoryAccountCode,
Quantity = 2
},
new LineItem
{
Description = "Inventory Adjustment",
AccountCode = DirectCostsAccountCode, //Using this account for the example. You would probably have your own inventory adjustments account
Quantity = 2,
UnitAmount = CreatedItem.PurchaseDetails.UnitPrice * -1
}
}
};
CreatedAccpayInvoice = Api.Invoices.Create(invoice);
}
protected void Given_an_ACCREC_invoice_using_the_item_with_code(string code)
{
var invoice = new Invoice
{
Contact = new Contact { Name = "ABC Bank" },
Type = InvoiceType.AccountsReceivable,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = InvoiceStatus.Authorised,
LineItems = new List
{
new LineItem
{
ItemCode = code,
AccountCode = RevenueAccountCode,
Quantity = 2
}
}
};
CreatedAccrecInvoice = Api.Invoices.Create(invoice);
}
protected void Given_a_zero_total_ACCREC_invoice_using_the_item_with_code(string code)
{
var invoice = new Invoice
{
Contact = new Contact { Name = "ABC Bank" },
Type = InvoiceType.AccountsReceivable,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = InvoiceStatus.Authorised,
LineItems = new List
{
new LineItem
{
ItemCode = code,
AccountCode = RevenueAccountCode,
Quantity = 2
},
new LineItem
{
Description = "Inventory Adjustment",
AccountCode = DirectCostsAccountCode, //Using this account for the example. You would probably want to have your own inventory adjustments account
Quantity = 2,
UnitAmount = CreatedItem.PurchaseDetails.UnitPrice * -1
}
}
};
CreatedAccrecInvoice = Api.Invoices.Create(invoice);
}
}
}
================================================
FILE: CoreTests/Integration/Items/TrackedItems/Update.cs
================================================
using NUnit.Framework;
namespace CoreTests.Integration.Items.TrackedItems
{
public class Update : TrackedInventoryTest
{
[Test]
public void Can_turn_untracked_item_to_tracked_item()
{
Given_an_untracked_item();
Given_an_inventory_account();
CreatedItem.InventoryAssetAccountCode = InventoryAccountCode;
CreatedItem.PurchaseDetails.AccountCode = null;
CreatedItem.PurchaseDetails.COGSAccountCode = DirectCostsAccountCode;
var updatedItem = Api.Items.Update(CreatedItem);
Assert.AreEqual(updatedItem.Id, CreatedItem.Id, "Expected the item's ID to be the same after creating and updating but they were different.");
Assert.IsTrue(updatedItem.IsTrackedAsInventory, "Expected the item's IsTrackedAsInventory value to be true but was false");
}
[Test]
public void Can_update_an_item_to_make_it_not_tracked_and_not_for_purchase()
{
Given_a_tracked_item();
CreatedItem.PurchaseDescription = null;
CreatedItem.PurchaseDetails = null;
CreatedItem.InventoryAssetAccountCode = null;
CreatedItem.IsPurchased = false;
var updatedItem = Api.Items.Update(CreatedItem);
Assert.AreEqual(updatedItem.Id, CreatedItem.Id, "Expected the item's ID to be the same after creating and updating but they were different.");
Assert.IsFalse(updatedItem.IsTrackedAsInventory, "Expected the item's IsTrackedAsInventory value to be false but was true");
Assert.IsFalse(updatedItem.IsPurchased.Value, "Expected the updated item's IsPurchased value to be false but was true.");
}
[Test]
public void Can_update_an_item_to_make_it_not_tracked_and_not_for_sale()
{
Given_a_tracked_item();
CreatedItem.Description = null;
CreatedItem.SalesDetails = null;
CreatedItem.InventoryAssetAccountCode = null;
CreatedItem.IsSold = false;
CreatedItem.PurchaseDetails.AccountCode = DirectCostsAccountCode;
CreatedItem.PurchaseDetails.COGSAccountCode = null;
var updatedItem = Api.Items.Update(CreatedItem);
Assert.AreEqual(updatedItem.Id, CreatedItem.Id, "Expected the item's ID to be the same after creating and updating but they were different.");
Assert.IsFalse(updatedItem.IsTrackedAsInventory, "Expected the item's IsTrackedAsInventory value to be false but was true");
Assert.IsFalse(updatedItem.IsSold.Value, "Expected the updated item's IsPurchased value to be false but was true.");
}
[Test]
public void Can_update_an_item_to_make_it_not_tracked_but_still_for_sale_and_purchase()
{
Given_a_tracked_item();
CreatedItem.PurchaseDetails.COGSAccountCode = null;
CreatedItem.InventoryAssetAccountCode = null;
var updatedItem = Api.Items.Update(CreatedItem);
Assert.AreEqual(updatedItem.Id, CreatedItem.Id, "Expected the item's ID to be the same after creating and updating but they were different.");
Assert.IsFalse(updatedItem.IsTrackedAsInventory, "Expected the item's IsTrackedAsInventory value to be false but was true");
Assert.IsTrue(updatedItem.IsSold.Value, "Expected the updated item's IsSold value to be true but was false.");
Assert.IsTrue(updatedItem.IsPurchased.Value, "Expected the updated item's IsPurchased value to be true but was false.");
}
}
}
================================================
FILE: CoreTests/Integration/Items/TrackedItems/Using_tracked_items.cs
================================================
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.Items.TrackedItems
{
public class Using_tracked_items : TrackedInventoryTest
{
//Purchase inventory like this
[Test]
public void Purchase_some_inventory_with_an_ACCPAY_invoice()
{
Given_a_tracked_item();
Then_the_quantity_of_the_tracked_item_is_zero(CreatedItem);
Given_an_ACCPAY_invoice_using_the_item_with_code(CreatedItem.Code);
var item = Api.Items.Find(CreatedItem.Id);
Then_the_quantity_of_the_tracked_item_is_more_than_zero(item);
}
//Sell inventory like this
[Test]
public void Sell_inventory_with_an_ACCREC_invoice()
{
Given_a_tracked_item();
Given_a_tracked_item();
Then_the_quantity_of_the_tracked_item_is_zero(CreatedItem);
Given_an_ACCPAY_invoice_using_the_item_with_code(CreatedItem.Code);
var item = Api.Items.Find(CreatedItem.Id);
Then_the_quantity_of_the_tracked_item_is_more_than_zero(item);
Given_an_ACCREC_invoice_using_the_item_with_code(item.Code);
item = Api.Items.Find(item.Id);
Then_the_quantity_of_the_tracked_item_is_zero(item);
}
//Make 'increase' adjustments like this
[Test]
public void Creating_a_zero_total_ACCPAY_invoice_increases_a_tracked_items_quantity_as_an_adjustment()
{
Given_a_tracked_item();
Then_the_quantity_of_the_tracked_item_is_zero(CreatedItem);
Given_a_zero_total_ACCPAY_invoice_using_the_item_with_code(CreatedItem.Code);
var item = Api.Items.Find(CreatedItem.Id);
Then_the_quantity_of_the_tracked_item_is_more_than_zero(item);
}
//Make 'decrease' adjustments like this
[Test]
public void Creating_a_zero_total_ACCREC_invoice_decreases_a_tracked_items_quantity()
{
Given_a_tracked_item();
Then_the_quantity_of_the_tracked_item_is_zero(CreatedItem);
Given_a_zero_total_ACCPAY_invoice_using_the_item_with_code(CreatedItem.Code);
var item = Api.Items.Find(CreatedItem.Id);
Then_the_quantity_of_the_tracked_item_is_more_than_zero(item);
Given_a_zero_total_ACCREC_invoice_using_the_item_with_code(CreatedItem.Code);
item = Api.Items.Find(CreatedItem.Id);
Then_the_quantity_of_the_tracked_item_is_zero(item);
}
//Find quantity and cost details of an item like this
[Test]
public void Finding_a_tracked_item_gives_you_quantity_on_hand_and_total_cost_pool()
{
//Create a tracked item with no quantity, and therefore no total cost pool
Given_a_tracked_item();
var item = Api.Items.Find(CreatedItem.Id);
var quantity = item.QuantityOnHand;
Assert.True(quantity == 0, "Expected the quanity on hand of a new inventory item to be 0");
var totalCostPool = item.TotalCostPool;
Assert.True(totalCostPool == 0, "Expected the total cost pool of a new inventory item to be 0");
}
private void Then_the_quantity_of_the_tracked_item_is_zero(Item item)
{
Assert.True(item.QuantityOnHand == 0);
}
private void Then_the_quantity_of_the_tracked_item_is_more_than_zero(Item item)
{
Assert.True(item.QuantityOnHand > 0);
}
}
}
================================================
FILE: CoreTests/Integration/Items/Update.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.Items
{
[TestFixture]
public class Update : ApiWrapperTest
{
[Test]
public void update_an_item()
{
var code = "Woo-hoo " + Random.GetRandomString(10);
var the_item = Api.Create(new Item
{
Code = code
});
var updated_item = Api.Update(new Item
{
Id = the_item.Id,
Code = code,
Description = "The Woo-hoo item",
SalesDetails = new SalesDetails
{
AccountCode = "200",
UnitPrice = 25.00m
}
});
Assert.IsTrue(Guid.Empty != updated_item.Id);
Assert.AreEqual(code, the_item.Code);
Assert.AreEqual(25.00m, updated_item.SalesDetails.UnitPrice);
}
}
}
================================================
FILE: CoreTests/Integration/Journals/Find.cs
================================================
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.Journals
{
[TestFixture]
public class Find : ApiWrapperTest
{
[Test]
public void find_journals()
{
var journals = Api.Journals.Find();
Assert.That(journals.Any());
}
[Test]
public void find_journals_offset()
{
var journals = Api.Journals.Find().ToList();
if (journals.Count() == 100)
{
var offset = journals.Max(p => p.Number);
Assert.That(Api.Journals.Offset(offset)
.Find()
.Any());
}
}
}
}
================================================
FILE: CoreTests/Integration/LinkedTransactions/Create.cs
================================================
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.LinkedTransactions
{
public class Create : LinkedTransactionTest
{
[Test]
public void can_create_a_linked_transaction_with_just_source_details()
{
Given_a_source_invoice();
var linkedTransaction = Api.LinkedTransactions.Create(new LinkedTransaction
{
SourceTransactionID = SourceId,
SourceLineItemID = SourceLineItemId
});
Then_the_linked_transaction_has_an_id(linkedTransaction);
Then_the_source_details_are_correct(linkedTransaction, SourceId, SourceLineItemId);
}
[Test]
public void can_create_a_linked_transaction_with_source_details_assigned_to_a_Contact()
{
Given_a_contact();
Given_a_source_invoice();
var linkedTransaction = Api.LinkedTransactions.Create(new LinkedTransaction
{
SourceTransactionID = SourceId,
SourceLineItemID = SourceLineItemId,
ContactID = ContactId
});
Then_the_linked_transaction_has_an_id(linkedTransaction);
Then_the_source_details_are_correct(linkedTransaction, SourceId, SourceLineItemId);
Then_the_contact_details_are_correct(linkedTransaction, ContactId);
}
[Test]
public void can_create_a_fully_allocated_linkedTransaction()
{
Given_a_contact();
Given_a_source_invoice();
Given_a_target_invoice(Contact);
var linkedTransaction = Api.LinkedTransactions.Create(new LinkedTransaction
{
SourceTransactionID = SourceId,
SourceLineItemID = SourceLineItemId,
ContactID = ContactId,
TargetTransactionID = TargetId,
TargetLineItemID = TargetLineItemId
});
Then_the_linked_transaction_has_an_id(linkedTransaction);
Then_the_source_details_are_correct(linkedTransaction, SourceId, SourceLineItemId);
Then_the_contact_details_are_correct(linkedTransaction, ContactId);
Then_the_target_details_are_correct(linkedTransaction, TargetId, TargetLineItemId);
}
}
}
================================================
FILE: CoreTests/Integration/LinkedTransactions/Delete.cs
================================================
using NUnit.Framework;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.LinkedTransactions
{
public class Delete : LinkedTransactionTest
{
[Test]
public void can_delete_linked_transactions()
{
Given_a_basic_linked_transaction();
var id = LinkedTransactionId;
Api.LinkedTransactions.Delete(LinkedTransaction);
//After deleting the linked transaction, it no longer exists so we exopect to get a 404 NotFound when looking for it.
Assert.Throws(() => Api.LinkedTransactions.Find(id));
}
}
}
================================================
FILE: CoreTests/Integration/LinkedTransactions/Find.cs
================================================
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.LinkedTransactions
{
public class Find : LinkedTransactionTest
{
[Test]
public void find_by_page()
{
Given_a_basic_linked_transaction();
var linkedTransactions = Api.LinkedTransactions.Page(1).Find();
Assert.Greater(linkedTransactions.Count(), 0);
}
[Test]
public void find_by_id()
{
Given_a_basic_linked_transaction();
var expected = LinkedTransactionId;
var linkedTransaction = Api.LinkedTransactions.Find(expected);
Assert.AreEqual(expected, linkedTransaction.Id);
}
[Test]
public void find_by_source_transaction_id()
{
Given_a_basic_linked_transaction();
var sourceTransactionId = SourceId;
var linkedTransactions = Api.LinkedTransactions.WhereSourceId(sourceTransactionId).Find().ToList();
Assert.Greater(linkedTransactions.Count(), 0);
Assert.AreEqual(sourceTransactionId, linkedTransactions.First().SourceTransactionID);
}
[Test]
public void find_by_contact_id()
{
Given_a_linked_transaction_assigned_to_a_contact();
var contactId = ContactId;
var linkedTransactions = Api.LinkedTransactions.WhereContactId(contactId).Find().ToList();
Assert.Greater(linkedTransactions.Count(), 0);
Assert.AreEqual(contactId, linkedTransactions.First().ContactID);
}
[Test]
public void find_by_target_transaction_id()
{
Given_a_fully_allocated_linked_transaction();
var targetTransactionId = TargetId;
var linkedTransactions = Api.LinkedTransactions.WhereTargetId(targetTransactionId).Find().ToList();
Assert.Greater(linkedTransactions.Count(), 0);
Assert.AreEqual(targetTransactionId, linkedTransactions.First().TargetTransactionID);
}
}
}
================================================
FILE: CoreTests/Integration/LinkedTransactions/LinkedTransactionTest.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.LinkedTransactions
{
public abstract class LinkedTransactionTest : ApiWrapperTest
{
protected Invoice SourceInvoice { get; set; }
protected Guid SourceId { get { return SourceInvoice.Id; } }
protected Guid SourceLineItemId { get { return SourceInvoice.LineItems[0].LineItemId; } }
protected Contact Contact { get; set; }
protected Guid ContactId { get { return Contact.Id; } }
protected Invoice TargetInvoice { get; set; }
protected Guid TargetId { get { return TargetInvoice.Id; } }
protected Guid TargetLineItemId { get { return TargetInvoice.LineItems[0].LineItemId; } }
protected LinkedTransaction LinkedTransaction { get; set; }
protected Guid LinkedTransactionId { get { return LinkedTransaction.Id; } }
protected void Given_a_basic_linked_transaction()
{
Given_a_source_invoice();
LinkedTransaction = Api.LinkedTransactions.Create(new LinkedTransaction
{
SourceTransactionID = SourceId,
SourceLineItemID = SourceLineItemId
});
}
protected void Given_a_linked_transaction_assigned_to_a_contact()
{
Given_a_source_invoice();
Given_a_contact();
LinkedTransaction = Api.LinkedTransactions.Create(new LinkedTransaction
{
SourceTransactionID = SourceId,
SourceLineItemID = SourceLineItemId,
ContactID = ContactId
});
}
protected void Given_a_fully_allocated_linked_transaction()
{
Given_a_source_invoice();
Given_a_contact();
Given_a_target_invoice(Contact);
LinkedTransaction = Api.LinkedTransactions.Create(new LinkedTransaction
{
SourceTransactionID = SourceId,
SourceLineItemID = SourceLineItemId,
ContactID = ContactId,
TargetTransactionID = TargetId,
TargetLineItemID = TargetLineItemId
});
}
protected void Given_a_source_invoice()
{
SourceInvoice = Given_an_invoice();
}
protected void Given_a_target_invoice(Contact contact = null)
{
TargetInvoice = Given_an_invoice(InvoiceType.AccountsReceivable, contact: contact);
}
private Invoice Given_an_invoice(InvoiceType type = InvoiceType.AccountsPayable, InvoiceStatus status = InvoiceStatus.Authorised, decimal amount = 100m, string accountCode = "100", Contact contact = null)
{
if (contact == null)
contact = new Contact {Name = "ABC Bank"};
return Api.Create(new Invoice
{
Contact = contact,
Type = type,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = status,
LineItems = new List
{
new LineItem
{
AccountCode = "200",
Description = "Good value item 1",
LineAmount = 100m
},
new LineItem
{
AccountCode = "200",
Description = "Good value item 2",
LineAmount = 100m
}
}
});
}
protected void Given_a_contact()
{
var contacts = Api.Contacts.Find().ToList();
if (contacts.Any())
{
Contact = contacts.First();
}
Contact = Api.Contacts.Create(new Contact
{
Name = "Phil" + Guid.NewGuid().ToString("N")
});
}
protected void Then_the_linked_transaction_has_an_id(LinkedTransaction linkedTransaction)
{
Assert.True(linkedTransaction.Id != Guid.Empty);
}
protected void Then_the_source_details_are_correct(LinkedTransaction linkedTransaction, Guid sourceId, Guid sourceLineItemId)
{
Assert.True(linkedTransaction.SourceTransactionID == sourceId);
Assert.True(linkedTransaction.SourceLineItemID == sourceLineItemId);
}
protected void Then_the_target_details_are_correct(LinkedTransaction linkedTransaction, Guid targetId, Guid targetLineItemId)
{
Assert.True(linkedTransaction.TargetTransactionID == targetId);
Assert.True(linkedTransaction.TargetLineItemID == targetLineItemId);
}
protected void Then_the_contact_details_are_correct(LinkedTransaction linkedTransaction, Guid contactId)
{
Assert.True(linkedTransaction.ContactID == contactId);
}
}
}
================================================
FILE: CoreTests/Integration/LinkedTransactions/Update.cs
================================================
using System.ComponentModel;
using NUnit.Framework;
namespace CoreTests.Integration.LinkedTransactions
{
public class Update : LinkedTransactionTest
{
[Test]
public void can_assign_a_contact_to_an_existing_linked_transaction()
{
Given_a_basic_linked_transaction();
Given_a_contact();
LinkedTransaction.ContactID = ContactId;
var linkedTransaction = Api.LinkedTransactions.Update(LinkedTransaction);
Assert.True(linkedTransaction.Id == LinkedTransactionId);
Then_the_contact_details_are_correct(linkedTransaction, ContactId);
}
[Test]
public void can_allocate_an_existing_linked_transaction_to_a_target_transaction()
{
Given_a_linked_transaction_assigned_to_a_contact();
Given_a_target_invoice(Contact);
LinkedTransaction.TargetTransactionID = TargetId;
LinkedTransaction.TargetLineItemID = TargetLineItemId;
var linkedTransaction = Api.LinkedTransactions.Update(LinkedTransaction);
Assert.True(linkedTransaction.Id == LinkedTransactionId);
Then_the_contact_details_are_correct(linkedTransaction, ContactId);
Then_the_target_details_are_correct(linkedTransaction, TargetId, TargetLineItemId);
}
}
}
================================================
FILE: CoreTests/Integration/ManualJournals/Create.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.ManualJournals
{
[TestFixture]
public class Create : ManualJournalsTest
{
[TestFixtureSetUp]
public void CreateSetUp()
{
ManualJournalsSetUp();
}
[Test]
public void create_manual_journal()
{
const string narration = "We know what we want to do";
const int amount = 50;
var manual = Given_a_manual_journal(narration, amount);
Assert.AreEqual(DateTime.Now.Date, manual.Date);
Assert.AreEqual(narration, manual.Narration);
Assert.True(manual.Lines.All(p => amount == Math.Abs(p.Amount)));
Assert.NotNull(manual.Lines.Single(p => Revenue.Code == p.AccountCode));
Assert.NotNull(manual.Lines.Single(p => Sales.Code == p.AccountCode));
}
[Test]
public void create_complex_manual_journal()
{
const string narration = "We know what we want to do";
var manual = Api.Create(new ManualJournal
{
Narration = narration,
Lines = new List
{
new Line
{
Amount = 12.5m,
AccountCode = Revenue.Code
},
new Line
{
Amount = 25,
AccountCode = Revenue.Code
},
new Line
{
Amount = 12.5m,
AccountCode = Sales.Code
},
new Line
{
Amount = -50m,
AccountCode = Sales.Code
}
}
});
Assert.AreEqual(0, manual.Lines.Sum(p => p.Amount));
Assert.AreEqual(DateTime.Now.Date, manual.Date);
Assert.AreEqual(narration, manual.Narration);
}
}
}
================================================
FILE: CoreTests/Integration/ManualJournals/Find.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.ManualJournals
{
[TestFixture]
public class Find : ManualJournalsTest
{
[TestFixtureSetUp]
public void UpdateSet()
{
ManualJournalsSetUp();
}
[Test]
public void find_by_id()
{
const string expected = "We know what we want to do";
var manual = Given_a_manual_journal(expected, 50);
var found = Api.ManualJournals.Find(manual.Id);
Assert.AreEqual(DateTime.Now.Date, found.Date);
Assert.AreEqual(expected, found.Narration);
}
[Test]
public void find_by_value()
{
const string expected = "We know what we want to do";
Given_a_manual_journal(expected, 50);
var found = Api.ManualJournals
.Where(string.Format("Narration == \"{0}\"", expected))
.Find();
Assert.True(found.All(p => p.Narration == expected));
}
[Test]
public void find_by_page()
{
const string expected = "We know what we want to do";
Given_a_manual_journal(expected, 50);
var manualJournals = Api.ManualJournals.Page(1).Find();
Assert.Greater(manualJournals.Count(), 0);
}
}
}
================================================
FILE: CoreTests/Integration/ManualJournals/ManualJournalsTest.cs
================================================
using System.Collections.Generic;
using System.Linq;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.ManualJournals
{
public class ManualJournalsTest : ApiWrapperTest
{
protected Account Sales { get; private set; }
protected Account Revenue { get; private set; }
protected void ManualJournalsSetUp()
{
SetUp();
Sales = Given_an_account();
Revenue = Given_an_account(AccountType.Revenue);
}
private Account Given_an_account(AccountType type = AccountType.Sales)
{
return Api.Accounts
.Where(string.Format("Type == \"{0}\"", type.ToString().ToUpper()))
.Find()
.FirstOrDefault() ??
Api.Create(new Account
{
Name = Random.GetRandomString(20),
Code = Random.GetRandomString(10),
Type = type
});
}
protected ManualJournal Given_a_manual_journal(string narration, decimal amount)
{
return Api.Create(new ManualJournal
{
Narration = narration,
Lines = new List
{
new Line
{
Amount = amount,
AccountCode = Sales.Code
},
new Line
{
Amount = -amount,
AccountCode = Revenue.Code
}
}
});
}
}
}
================================================
FILE: CoreTests/Integration/ManualJournals/Update.cs
================================================
using System;
using NUnit.Framework;
namespace CoreTests.Integration.ManualJournals
{
[TestFixture]
public class Update : ManualJournalsTest
{
[TestFixtureSetUp]
public void UpdateSet()
{
ManualJournalsSetUp();
}
[Test]
public void create_manual_journal()
{
const string expected = "We got that wrong";
var manual = Given_a_manual_journal("We know what we want to do", 50);
manual.Narration = expected;
var updated = Api.Update(manual);
Assert.AreEqual(DateTime.Now.Date, updated.Date);
Assert.AreEqual(expected, updated.Narration);
}
};
}
================================================
FILE: CoreTests/Integration/Organisation/Find.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Organisation
{
[TestFixture]
public class Find : ApiWrapperTest
{
[Test]
public void can_get_the_organisation_sales_tax_basis()
{
var test = Api.Organisation.SalesTaxBasisType;
Assert.True(Enum.IsDefined(typeof(SalesTaxBasisType), test));
}
[Test]
public void can_get_the_organisation_sales_tax_period()
{
var test = Api.Organisation.SalesTaxPeriod;
Assert.True(Enum.IsDefined(typeof(SalesTaxPeriodType), test));
}
}
}
================================================
FILE: CoreTests/Integration/Overpayments/Find.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Overpayments
{
[TestFixture]
public class Find : ApiWrapperTest
{
[Test]
public void find_all()
{
var overpayments = Api.Overpayments.Find();
Assert.Greater(overpayments.Count(), 0);
}
[Test]
public void find_all_receive_overpayments()
{
var overpayments = Api.Overpayments.Where("Type == \"RECEIVE-OVERPAYMENT\"").Find();
Assert.True(overpayments.All(p => p.Type == OverpaymentType.ReceiveOverpayment));
}
[Test]
public void find_all_spend_overpayments()
{
var overpayments = Api.Overpayments.Where("Type == \"SPEND-OVERPAYMENT\"").Find();
Assert.True(overpayments.All(p => p.Type == OverpaymentType.SpendOverpayment));
}
}
}
================================================
FILE: CoreTests/Integration/Payments/Create.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
namespace CoreTests.Integration.Payments
{
[TestFixture]
public class Create : PaymentsTest
{
[TestFixtureSetUp]
public void CreatePaymentsSetUp()
{
SetUp();
}
[Test]
public void create_simple_payment()
{
var date = DateTime.UtcNow;
const decimal expected = 32.6m;
const decimal invoiceAmount = 100;
var payment = Given_a_payment(invoiceAmount, date, expected);
Assert.AreEqual(expected, payment.Amount);
}
[Test]
public void create_multiple_payments()
{
var date = DateTime.UtcNow;
var payments = Api.Create(
new List
{
CreatePayment(4000, date, 3375),
CreatePayment(393.75m, date, 393.75m),
CreatePayment(450, date, 398),
}).ToList();
Assert.AreEqual(3, payments.Count());
Assert.IsNotNull(payments.Single(p => p.Amount == 393.75m));
Assert.IsNotNull(payments.Single(p => p.Amount == 3375));
Assert.IsNotNull(payments.Single(p => p.Amount == 398));
}
[Test]
public void create_reconciled_payment()
{
var date = DateTime.UtcNow;
const decimal amount = 32.6m;
const decimal invoiceAmount = 32.6m;
var payment = Api.Create(CreatePayment(invoiceAmount, date, amount, true));
Assert.AreEqual(amount, payment.Amount);
Assert.True(payment.IsReconciled.HasValue);
Assert.True(payment.IsReconciled.Value);
}
[Test]
public void create_refund_on_credit_note()
{
const int amount = 50;
var note = Given_an_credit_note(amount, Account.Code);
var date = DateTime.UtcNow;
const string reference = "Full refund as we couldn't replace item";
var payment = Api.Create(new Payment
{
CreditNote = new CreditNote { Number = note.Number },
Account = new Account { Code = BankAccount.Code },
Date = date,
Amount = amount,
Reference = reference
});
Assert.AreEqual(reference, payment.Reference);
Assert.AreEqual(amount, payment.Amount);
}
[Test]
public void create_refund_on_Prepayment()
{
const int amount = 50;
var transaction = Given_a_prepayment(BankAccount.Code, amount, Account.Code);
var date = DateTime.UtcNow;
const string reference = "Full refund on the prepayment";
//NOTE: When refunding a prepayment, you create the payment with a Prepayment object (payment.Prepayment). The resulting payment will have the Prepayment stored as an Invoice eg. payment.Invoice rather than payment.Prepayment
var payment = Api.Create(new Payment
{
Prepayment = new Prepayment { Id = transaction.PrepaymentID.GetValueOrDefault() },
Account = new Account { Code = BankAccount.Code },
Date = date,
Amount = amount,
Reference = reference
});
Assert.AreEqual(reference, payment.Reference);
Assert.AreEqual(amount, payment.Amount);
}
[Test]
public void create_refund_on_Overpayment()
{
//This may differ if you have changed the code of your accounts receivable
var accountsReceivable = Api.Accounts.Where("Code == \"610\"").Find().First();
const int amount = 50;
var transaction = Given_an_overpayment(BankAccount.Code, amount, accountsReceivable.Code);
var date = DateTime.UtcNow;
const string reference = "Full refund on the overpayment";
//NOTE: When refunding an overpayment, you create the payment with an Overpayment object (payment.Overpayment). The resulting payment will have the Overpayment stored as an Invoice eg. payment.Invoice rather than payment.Overpayment
var payment = Api.Create(new Payment
{
Overpayment = new Overpayment { Id = transaction.OverpaymentID.GetValueOrDefault() },
Account = new Account { Code = BankAccount.Code },
Date = date,
Amount = amount,
Reference = reference
});
Assert.AreEqual(reference, payment.Reference);
Assert.AreEqual(amount, payment.Amount);
}
}
}
================================================
FILE: CoreTests/Integration/Payments/CreateForeignCurrency.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Payments
{
[TestFixture]
public class CreateForeignCurrency : PaymentsTest
{
private Account Foreign { get; set; }
[TestFixtureSetUp]
[Ignore("The user needs to have foreign currency subscription on their account")]
public void SetUpForeignCurrency()
{
SetUp();
}
[Test]
[Ignore("The user needs to have foreign currency subscription on their account")]
public void create_refund_on_credit_note_with_foreign_currency()
{
Foreign = Given_a_foreign_currency_account();
const int amount = 50;
var accountCode = Account.Code;
var note = Given_an_credit_note(amount, accountCode);
var date = DateTime.UtcNow;
const string reference = "Full refund as we couldn't replace item";
var payment = Api.Create(new Payment
{
CreditNote = new CreditNote { Number = note.Number },
Account = new Account { Code = Foreign.Code },
CurrencyRate = 0.8m,
Date = date,
Amount = amount,
Reference = reference
});
Assert.AreEqual(reference, payment.Reference);
Assert.AreEqual(amount, payment.Amount);
}
private Account Given_a_foreign_currency_account()
{
return Api.Accounts
.Where("Type == \"BANK\"")
.And("CurrencyCode != \"NZD\"")
.Find().FirstOrDefault() ??
Create_foreign_currency_account();
}
private Account Create_foreign_currency_account()
{
return Api.Create(new Account
{
Code = Random.GetRandomString(10),
Name = "Foreign Currency",
CurrencyCode = "AUD",
BankAccountNumber = "121-121-1234567",
Type = AccountType.Bank
});
}
}
}
================================================
FILE: CoreTests/Integration/Payments/Delete.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.Payments
{
[TestFixture]
public class Delete : PaymentsTest
{
[TestFixtureSetUp]
public void CreatePaymentsSetUp()
{
SetUp();
}
[Test]
public void can_delete_payments()
{
var date = DateTime.UtcNow;
const decimal expected = 32.6m;
const decimal invoiceAmount = 100;
var payment = Given_a_payment(invoiceAmount, date, expected);
Given_this_payment_is_deleted(payment);
var found = Api.Payments.Find(payment.Id);
Assert.True(found.Status == PaymentStatus.Deleted);
}
}
}
================================================
FILE: CoreTests/Integration/Payments/Find.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.Payments
{
public class Find : PaymentsTest
{
[TestFixtureSetUp]
public void PaymentsSetUp()
{
SetUp();
}
[Test]
public void find_single_payment()
{
var expected = Given_a_payment(200, DateTime.Today.AddDays(-10), 150);
var found = Api.Payments.Find(expected.Id);
Assert.AreEqual(expected.Id, found.Id);
Assert.AreEqual(expected.Amount, found.Amount);
}
[Test]
public void find_payments()
{
var date = DateTime.Today.AddDays(-10).Date;
Given_a_payment(200, date, 150);
Given_a_payment(500, date, 150);
var found = Api.Payments
.ModifiedSince(DateTime.Now.AddSeconds(-1))
.Where("Amount == 150")
.Find()
.ToList();
Assert.IsTrue(found.Count() >= 2);
Assert.IsTrue(found.Count(p => p.Date == date) >= 2);
}
}
}
================================================
FILE: CoreTests/Integration/Payments/PaymentsTest.cs
================================================
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.Payments
{
public abstract class PaymentsTest : ApiWrapperTest
{
protected Payment Given_a_payment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false)
{
return Api.Create(CreatePayment(invoiceAmount, date, amount, isReconciled));
}
protected Payment CreatePayment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false)
{
var invoice = Given_an_invoice(invoiceAmount, Account.Code);
var bankCode = BankAccount.Code;
var payment = new Payment
{
Invoice = new Invoice { Number = invoice.Number },
Account = new Account { Code = bankCode },
Date = date,
Amount = amount
};
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
{
new LineItem
{
AccountCode = accountCode,
Description = "Good value item",
LineAmount = amount
}
}
});
}
protected CreditNote Given_an_credit_note(decimal amount = 100m, string accountCode = "100")
{
return Api.Create(new CreditNote
{
Contact = new Contact { Name = "Richard" },
Number = Random.GetRandomString(10),
Type = CreditNoteType.AccountsPayable,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = InvoiceStatus.Authorised,
LineItems = new List
{
new LineItem
{
AccountCode = accountCode,
Description = "Good value item",
LineAmount = amount
}
}
});
}
protected BankTransaction Given_a_prepayment(string bankAccountCode, decimal amount = 100m, string accountCode = "100")
{
return Api.Create(new BankTransaction
{
Contact = new Contact { Name = "Richard" },
Type = BankTransactionType.ReceivePrepayment,
Date = DateTime.UtcNow,
BankAccount = new Account
{
Code = bankAccountCode
},
LineItems = new List
{
new LineItem
{
AccountCode = accountCode,
Description = "Good value item",
LineAmount = amount
}
}
});
}
protected BankTransaction Given_an_overpayment(string bankAccountCode, decimal amount = 100m, string accountCode = "100")
{
return Api.Create(new BankTransaction
{
Contact = new Contact { Name = "Richard" },
Type = BankTransactionType.ReceiveOverpayment,
Date = DateTime.UtcNow,
LineAmountTypes = LineAmountType.NoTax,
BankAccount = new Account
{
Code = bankAccountCode
},
LineItems = new List
{
new LineItem
{
AccountCode = accountCode,
Description = "Good value item",
LineAmount = amount
}
}
});
}
protected void Given_this_payment_is_deleted(Payment payment)
{
var deleteThisPayment = new Payment { Status = PaymentStatus.Deleted, Id = payment.Id };
Api.Payments.Update(deleteThisPayment);
}
}
}
================================================
FILE: CoreTests/Integration/Pdf/Get.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.Pdf
{
[TestFixture]
public class Get : ApiWrapperTest
{
[Test]
public void can_get_invoice_as_pdf()
{
AssertOk(PdfEndpointType.Invoices, new Invoices.Create().Given_an_invoice().Id);
}
[Test]
public void can_get_credit_note_as_pdf()
{
AssertOk(PdfEndpointType.CreditNotes, new CreditNotes.Create().Given_a_creditnote().Id);
}
[Test]
public void can_get_purchase_order_as_pdf()
{
AssertOk(PdfEndpointType.PurchaseOrders, new PurchaseOrders.Create().Given_a_purchase_order().Id);
}
[Test]
public void invoice_gives_404_when_not_found()
{
Assert.Throws(() => Api.PdfFiles.Get(PdfEndpointType.Invoices, Guid.NewGuid()));
}
[Test]
public void credit_note_gives_404_when_not_found()
{
Assert.Throws(() => Api.PdfFiles.Get(PdfEndpointType.CreditNotes, Guid.NewGuid()));
}
[Test]
public void purchase_order_gives_404_when_not_found()
{
Assert.Throws(() => Api.PdfFiles.Get(PdfEndpointType.PurchaseOrders, Guid.NewGuid()));
}
private void AssertOk(PdfEndpointType type, Guid id)
{
var pdf = Api.PdfFiles.Get(type, id);
var expected = id.ToString("D") + ".pdf";
Assert.NotNull(pdf);
Assert.AreEqual(expected, pdf.FileName);
}
}
}
================================================
FILE: CoreTests/Integration/Prepayments/Find.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Prepayments
{
[TestFixture]
public class Find : ApiWrapperTest
{
[Test]
public void find_all()
{
var prepayments = Api.Prepayments.Find();
Assert.Greater(prepayments.Count(), 0);
}
[Test]
public void find_all_receive_prepayments()
{
var prepayments = Api.Prepayments.Where("Type == \"RECEIVE-PREPAYMENT\"").Find();
Assert.True(prepayments.All(p => p.Type == PrepaymentType.ReceivePrepayment));
}
[Test]
public void find_all_spend_prepayments()
{
var prepayments = Api.Prepayments.Where("Type == \"SPEND-PREPAYMENT\"").Find();
Assert.True(prepayments.All(p => p.Type == PrepaymentType.SpendPrepayment));
}
}
}
================================================
FILE: CoreTests/Integration/PurchaseOrders/Create.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.PurchaseOrders
{
public class Create : ApiWrapperTest
{
[Test]
public void Create_minimal_draft_purchase_order()
{
var purchaseOrder = Api.PurchaseOrders.Create(
new PurchaseOrder
{
Date = DateTime.Today,
Contact = new Contact { Id = ContactId }
}
);
Assert.True(purchaseOrder.Id != Guid.Empty);
Assert.True(purchaseOrder.Status == PurchaseOrderStatus.Draft);
}
[Test]
public void Create_authorised_purchase_order()
{
var purchaseOrder = Api.PurchaseOrders.Create(
new PurchaseOrder
{
Status = PurchaseOrderStatus.Authorised,
Date = DateTime.Today,
Contact = new Contact{Id = ContactId},
LineItems = new List()
{
new LineItem
{
Description = "An item I want to purchase",
UnitAmount = 1,
Quantity = 1,
}
}
}
);
Assert.True(purchaseOrder.Id != Guid.Empty);
Assert.True(purchaseOrder.Status == PurchaseOrderStatus.Authorised);
}
private Guid ContactId
{
get
{
return Api.Contacts.Find().First().Id;
}
}
public PurchaseOrder Given_a_purchase_order()
{
return Api.PurchaseOrders.Create(
new PurchaseOrder
{
Status = PurchaseOrderStatus.Authorised,
Date = DateTime.Today,
Contact = new Contact { Id = ContactId },
LineItems = new List()
{
new LineItem
{
Description = "An item I want to purchase",
UnitAmount = 1,
Quantity = 1,
}
}
}
);
}
}
}
================================================
FILE: CoreTests/Integration/PurchaseOrders/Find.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.PurchaseOrders
{
public class Find : ApiWrapperTest
{
[Test]
public void Find_a_purchase_order_by_Id()
{
var purchaseOrder = Given_a_minimum_PurchaseOrder();
var foundPurchaseOrder = Api.PurchaseOrders.Find(purchaseOrder.Id);
Assert.AreEqual(purchaseOrder.Id, foundPurchaseOrder.Id);
}
[Test]
public void Find_purchase_orders()
{
Given_a_minimum_PurchaseOrder();
var foundPurchaseOrders = Api.PurchaseOrders.Find();
Assert.GreaterOrEqual(foundPurchaseOrders.Count(), 1);
}
[Test]
public void Find_page_X_of_purchase_orders()
{
Given_a_minimum_PurchaseOrder();
var foundPurchaseOrders = Api.PurchaseOrders.Page(1).Find();
Assert.GreaterOrEqual(foundPurchaseOrders.Count(), 1);
}
[Test]
public void Filter_purchase_orders_by_status()
{
Given_an_authorised_PurchaseOrder();
var authorisedPurchaseOrders = Api.PurchaseOrders.Status(PurchaseOrderStatus.Authorised).Find();
Assert.IsTrue(authorisedPurchaseOrders.All(p => p.Status == PurchaseOrderStatus.Authorised), "Expected all retrieved purchase orders to have status of Authorised");
}
[Test]
public void Filter_purchase_orders_by_ModifiedSince()
{
var oldPurchaseOrder = Given_a_minimum_PurchaseOrder();
Thread.Sleep(1000);
var date = DateTime.UtcNow;
Thread.Sleep(1000);
var newPurchaseOrder = Given_a_minimum_PurchaseOrder();
var retrievedPurchaseOrders = Api.PurchaseOrders.ModifiedSince(date).Find().ToList();
Assert.True(retrievedPurchaseOrders.All(p => p.Id != oldPurchaseOrder.Id));
Assert.True(retrievedPurchaseOrders.Any(p => p.Id == newPurchaseOrder.Id));
}
[Test]
public void Filter_purchase_orders_by_DateFrom()
{
var oldPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today.AddDays(-7));
var newPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today);
var inbetweenDate = DateTime.Today.AddDays(-3);
var retrievedPurchaseOrders = Api.PurchaseOrders.DateFrom(inbetweenDate).Find().ToList();
Assert.True(retrievedPurchaseOrders.All(p => p.Id != oldPurchaseOrder.Id));
Assert.True(retrievedPurchaseOrders.Any(p => p.Id == newPurchaseOrder.Id));
}
[Test]
public void Filter_purchase_orders_by_DateTo()
{
var oldPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today.AddDays(-7));
var newPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today);
var inbetweenDate = DateTime.Today.AddDays(-3);
var retrievedPurchaseOrders = Api.PurchaseOrders.DateTo(inbetweenDate).Find().ToList();
Assert.True(retrievedPurchaseOrders.All(p => p.Id != newPurchaseOrder.Id));
Assert.True(retrievedPurchaseOrders.Any(p => p.Id == oldPurchaseOrder.Id));
}
[Test]
public void Filter_purchase_orders_by_a_DateFrom_DateTo_date_range()
{
var oldPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today.AddDays(-7));
var midPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today.AddDays(-4));
var newPurchaseOrder = Given_a_minimum_PurchaseOrder(DateTime.Today);
var dateFrom = DateTime.Today.AddDays(-5);
var dateTo = DateTime.Today.AddDays(-3);
var retrievedPurchaseOrders = Api.PurchaseOrders
.DateFrom(dateFrom)
.DateTo(dateTo)
.Find().ToList();
Assert.True(retrievedPurchaseOrders.All(p => p.Id != newPurchaseOrder.Id));
Assert.True(retrievedPurchaseOrders.All(p => p.Id != oldPurchaseOrder.Id));
Assert.True(retrievedPurchaseOrders.Any(p => p.Id == midPurchaseOrder.Id));
}
[Test]
public void Use_multiple_filters_to_find_Purchase_orders()
{
var purchaseOrders = Api.PurchaseOrders
.DateFrom(DateTime.Today.AddDays(-7))
.DateTo(DateTime.Today.AddDays(-1))
.Status(PurchaseOrderStatus.Authorised)
.Page(1)
.Find();
Assert.GreaterOrEqual(purchaseOrders.Count(), 1);
}
private PurchaseOrder Given_a_minimum_PurchaseOrder(DateTime? date = null)
{
var purchaseOrder = Api.PurchaseOrders.Create(new PurchaseOrder
{
Date = date ?? DateTime.Today,
Contact = Api.Contacts.Find().First()
});
return purchaseOrder;
}
private PurchaseOrder Given_an_authorised_PurchaseOrder()
{
var purchaseOrder = Api.PurchaseOrders.Create(new PurchaseOrder
{
Status = PurchaseOrderStatus.Authorised,
Date = DateTime.Today,
Contact = Api.Contacts.Find().First(),
LineItems = new List()
{
new LineItem
{
Description = "An item I want to purchase",
UnitAmount = 1,
Quantity = 1,
}
}
});
return purchaseOrder;
}
}
}
================================================
FILE: CoreTests/Integration/PurchaseOrders/Update.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.PurchaseOrders
{
public class Update : ApiWrapperTest
{
[Test]
public void Can_update_a_PurchaseOrder_like_this()
{
var purchaseOrder = Given_a_PurchaseOrder();
purchaseOrder.LineItems.Add(new LineItem
{
Description = "Another item I want to purchase",
UnitAmount = 10,
Quantity = 10
});
var updatedPurchaseOrder = Api.PurchaseOrders.Update(purchaseOrder);
Assert.AreEqual(2, updatedPurchaseOrder.LineItems.Count);
}
public PurchaseOrder Given_a_PurchaseOrder()
{
return Api.PurchaseOrders.Create(
new PurchaseOrder
{
Status = PurchaseOrderStatus.Authorised,
Date = DateTime.Today,
Contact = new Contact { Id = ContactId },
LineItems = new List()
{
new LineItem
{
Description = "An item I want to purchase",
UnitAmount = 1,
Quantity = 1,
}
}
}
);
}
private Guid ContactId
{
get
{
return Api.Contacts.Find().First().Id;
}
}
}
}
================================================
FILE: CoreTests/Integration/Receipts/Create.cs
================================================
using System.Linq;
using NUnit.Framework;
namespace CoreTests.Integration.Receipts
{
[TestFixture]
public class Create : ReceiptTest
{
[Test]
public void create_receipt()
{
var contact = Random.GetRandomString(10);
var description = Random.GetRandomString(30);
const decimal value = 13.8m;
var receipt = Given_a_receipt(Api.Users.Find().First().Id, contact, description, value, "420");
Assert.AreEqual(receipt.Total, value);
Assert.AreEqual(receipt.Contact.Name, contact);
Assert.AreEqual(receipt.LineItems[0].Description, description);
}
}
}
================================================
FILE: CoreTests/Integration/Receipts/ReceiptTest.cs
================================================
using System;
using System.Collections.Generic;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.Receipts
{
public abstract class ReceiptTest : ApiWrapperTest
{
public Receipt Given_a_receipt(Guid userId, string contactName, string description, decimal amount, string account)
{
return Api.Create(new Receipt
{
Date = DateTime.UtcNow.Date,
Contact = new Contact { Name = contactName },
LineAmountTypes = LineAmountType.Inclusive,
LineItems = new List
{
new LineItem
{
Description = description,
UnitAmount = amount,
AccountCode = account
}
},
Total = amount,
User = new User
{
Id = userId
}
});
}
}
}
================================================
FILE: CoreTests/Integration/Receipts/Update.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.Receipts
{
[TestFixture]
public class Update : ReceiptTest
{
[Test]
public void delete_receipt()
{
var contact = Random.GetRandomString(10);
var description = Random.GetRandomString(30);
const ReceiptStatus expected = ReceiptStatus.Deleted;
const decimal value = 13.8m;
var receipt = Given_a_receipt(Api.Users.Find().First().Id, contact, description, value, "420");
receipt.Status = expected;
var deletedReceipt = Api.Update(receipt);
Assert.AreEqual(expected, deletedReceipt.Status);
}
}
}
================================================
FILE: CoreTests/Integration/Reports/Find.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace CoreTests.Integration.Reports
{
[TestFixture]
public class Find : ApiWrapperTest
{
[Test]
public void find_all()
{
var reports = Api.Reports.Find();
Assert.IsNotNull(reports);
}
[Test]
public void find_gst_report()
{
var reports = Api.Reports.Find("BalanceSheet");
Assert.IsNotNull(reports);
}
[Test]
public void find_PL_report()
{
var reports = Api.Reports.ProfitAndLoss();
Assert.IsNotNull(reports);
}
[Test]
public void find_BudgetSummary_report()
{
var reports = Api.Reports.BudgetSummary(DateTime.Now.AddDays(-50));
Assert.IsNotNull(reports);
}
}
}
================================================
FILE: CoreTests/Integration/Setup/Create.cs
================================================
using System.Collections.Generic;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
using Xero.Api.Infrastructure.Exceptions;
namespace CoreTests.Integration.Setup
{
[TestFixture(Ignore = true, Description = "These test will remove all accounts! You have been warned.")]
public class Create : ApiWrapperTest
{
[Test]
public void create_a_valid_setup()
{
var import = Api.Setup.Create(new Xero.Api.Core.Model.Setup.Setup
{
Accounts = new List(new[] {
new Account
{
Code = "POS " + Random.GetRandomString(10),
Name = "POS Clearing" + Random.GetRandomString(10),
Type = AccountType.Current,
Description = "A test for the setup"
}
})
});
Assert.True(import.Accounts.New == 1);
}
[Test]
public void missing_account_code_will_error()
{
Assert.Throws(() => Api.Setup.Create(new Xero.Api.Core.Model.Setup.Setup
{
Accounts = new List(new[]
{
new Account
{
Name = "No account code",
Type = AccountType.Current,
}
})
}));
}
[Test]
public void providing_nothing_is_not_an_error()
{
var import = Api.Setup.Create(new Xero.Api.Core.Model.Setup.Setup());
Assert.False(import.Accounts.Present);
Assert.False(import.Organisation.Present);
}
}
}
================================================
FILE: CoreTests/Integration/TaxRates/Create.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.TaxRates
{
[TestFixture]
public class Create : TaxRateTest
{
[Test]
public void create_tax_rate()
{
var name = Random.GetRandomString(10);
var state = Random.GetRandomString(5);
var local = Random.GetRandomString(5);
const decimal stateRate = 7.5m;
const decimal localRate = 0.625m;
const ReportTaxType taxType = ReportTaxType.Input;
var taxRate = Given_a_tax_rate(name, taxType, state, stateRate, local, localRate);
Assert.That(name == taxRate.Name);
Assert.That(taxType == taxRate.ReportTaxType);
AssertContainsRate(taxRate, state, stateRate);
AssertContainsRate(taxRate, local, localRate);
}
private void AssertContainsRate(TaxRate taxRate, string name, decimal rate)
{
var taxComponent = taxRate.TaxComponents.SingleOrDefault(p => name == p.Name);
Assert.IsNotNull(taxComponent);
Assert.AreEqual(taxComponent.Rate, rate);
}
}
}
================================================
FILE: CoreTests/Integration/TaxRates/TaxRateTest.cs
================================================
using System.Collections.Generic;
using System.Linq;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.TaxRates
{
public abstract class TaxRateTest : ApiWrapperTest
{
protected TaxRate Given_a_tax_rate(string name, ReportTaxType taxType, string state, decimal stateRate, string local, decimal localRate)
{
return Api.Create(new[]{ new TaxRate
{
Name = name,
ReportTaxType = taxType,
TaxComponents = new List
{
new TaxComponent
{
Name = state,
Rate = stateRate
},
new TaxComponent
{
Name = local,
Rate = localRate
}
}
}}).First();
}
}
}
================================================
FILE: CoreTests/Integration/TaxRates/Update.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.TaxRates
{
[TestFixture]
public class Update : TaxRateTest
{
[Test]
public void update_tax_rate()
{
var name = Random.GetRandomString(10);
var state = Random.GetRandomString(5);
var local = Random.GetRandomString(5);
const decimal stateRate = 7.5m;
const decimal localRate = 0.625m;
const ReportTaxType taxType = ReportTaxType.Input;
var taxRate = Given_a_tax_rate(name, taxType, state, stateRate, local, localRate);
// the local tax rate is increased
const decimal expected = 0.7m;
var component = taxRate.TaxComponents.Single(p => p.Name == local);
component.Rate = expected;
var updated = Api.Update(taxRate);
Assert.AreEqual(expected, updated.TaxComponents.Single(p => p.Name == local).Rate);
}
[Test]
public void delete_tax_rate()
{
var name = Random.GetRandomString(10);
var state = Random.GetRandomString(5);
var local = Random.GetRandomString(5);
const decimal stateRate = 7.5m;
const decimal localRate = 0.625m;
const TaxRateStatus expected = TaxRateStatus.Deleted;
var taxRate = Given_a_tax_rate(name, ReportTaxType.Input, state, stateRate, local, localRate);
taxRate.Status = expected;
var updated = Api.TaxRates.Update(taxRate);
Assert.That(expected == updated.Status);
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/AddTrackingOption.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Endpoints;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class AddTrackingOption : TrackingCategoriesTest
{
[Test]
public void Can_add_tracking_option()
{
Given_a_TrackingCategory_with_Option();
Then_Category_Has_Option();
Given_Tracking_Category_is_deleted();
}
[Test]
public void Can_add_tracking_options()
{
Given_a_TrackingCategory_with_Options();
Then_Category_Has_Options();
Given_Tracking_Category_is_deleted();
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/Adding/CreateTrackingCategories.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class CreateTrackingCategories : TrackingCategoriesTest
{
[Test]
public void Can_create_a_Tracking_Category()
{
var category = Api.Create(new TrackingCategory
{
Id = new Guid(),
Name = "TheJoker " + Guid.NewGuid(),
Status = TrackingCategoryStatus.Active
});
Assert.IsTrue(category.Name.StartsWith("TheJoker"));
Assert.IsTrue(category.Status == TrackingCategoryStatus.Active);
// Archieve_a_TrackingCategoy(category);
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/ArchiveTrackingCategory.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Endpoints;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class ArchiveTrackingCategory : TrackingCategoriesTest
{
[Test]
public void Can_archieve_tracking_category()
{
Given_a_TrackingCategory_with_Options();
Given_approved_invoice_with_tracking_option();
Given_Tracking_Category_is_Archived();
Given_Invoice_is_voided();
Given_Tracking_Category_is_deleted();
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/CreateTrackingCategories.cs
================================================
using System;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class CreateTrackingCategories : TrackingCategoriesTest
{
[Test]
public void Can_create_a_Tracking_Category()
{
Given_a_TrackingCategory();
Given_Tracking_Category_is_deleted();
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/Delete.cs
================================================
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model.Status;
using Xero.Api.Infrastructure.ThirdParty.ServiceStack.Text;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class Delete : TrackingCategoriesTest
{
[Test]
public void can_delete_a_Tracking_Category()
{
Given_a_TrackingCategory();
Given_Tracking_Category_is_deleted();
}
[Test]
public void can_delete_a_Tracking_Category_Option()
{
Given_a_TrackingCategory_with_Options();
Given_Tracking_CategoryOption_is_deleted();
Given_Tracking_Category_is_deleted();
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/GetTrackingCategories.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using System.Collections.Generic;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class GetTrackingCategories : TrackingCategoriesTest
{
[Test]
public void Can_get_Tracking_Category()
{
Given_two_TrackingCategorys();
Given_GetAll();
List_contains_the_two_Tracking_Category();
Given_both_Tracking_Category_is_deleted();
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/GetTrackingCategoriesIncludingArchieved.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using System.Collections.Generic;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class GetTrackingCategoriesIncludingArchieved : TrackingCategoriesTest
{
[Test]
public void Can_get_Tracking_Category_including_archieved()
{
Given_a_TrackingCategory_with_Options();
Given_approved_invoice_with_tracking_option();
Given_Tracking_Category_is_Archived();
Given_GetAll_with_Archived();
Then_Archieved_Tracking_Category_is_in_list();
Given_Invoice_is_voided();
Given_Tracking_Category_is_deleted();
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/Options/AddTrackingOption.cs
================================================
using System;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
namespace CoreTests.Integration.TrackingCategories
{
[TestFixture]
public class AddTrackingOption : TrackingCategoriesTest
{
[Test]
public void Can_add_Tracking_options()
{
var category = Given_a_TrackingCategory();
var trackingOptions = Given_TrackingOptions();
var result = Can_Add_TrackingOptions_to_Category(category, trackingOptions);
Assert.IsTrue(result.Name.StartsWith("TheJoker"));
Assert.IsTrue(result.Options.First().Name == trackingOptions.First().Name);
Assert.IsTrue(result.Options.ElementAt(1).Id == trackingOptions.ElementAt(1).Id);
}
}
}
================================================
FILE: CoreTests/Integration/TrackingCategories/TrackingCategoriesTest.cs
================================================
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
namespace CoreTests.Integration.TrackingCategories
{
public class TrackingCategoriesTest : ApiWrapperTest
{
private Invoice invoice_;
public TrackingCategory category1_;
public TrackingCategory category2_;
private Option option_;
private List listresult_;
public void Given_a_TrackingCategory_with_Options()
{
Given_a_TrackingCategory();
var option1 = Given_a_tracking_option();
var option2 = Given_a_tracking_option();
Api.TrackingCategories[category1_.Id].Add(option1);
Api.TrackingCategories[category1_.Id].Add(option2);
category1_ = Api.TrackingCategories.GetByID(category1_.Id);
}
public void Given_a_TrackingCategory_with_Option()
{
Given_a_TrackingCategory();
var option1 = Given_a_tracking_option();
Api.TrackingCategories[category1_.Id].Add(option1);
category1_ = Api.TrackingCategories.GetByID(category1_.Id);
}
public void Given_a_TrackingCategory()
{
category1_ = Api.TrackingCategories.Add(new TrackingCategory
{
Name = "TheJoker " + Guid.NewGuid(),
Status = TrackingCategoryStatus.Active
});
Assert.IsTrue(category1_.Name.StartsWith("TheJoker"));
Assert.IsTrue(category1_.Status == TrackingCategoryStatus.Active);
}
public void Given_two_TrackingCategorys()
{
category1_ = Api.TrackingCategories.Add(new TrackingCategory
{
Name = "TheJoker " + Guid.NewGuid(),
Status = TrackingCategoryStatus.Active
});
category2_ = Api.TrackingCategories.Add(new TrackingCategory
{
Name = "HarleyQuinn " + Guid.NewGuid(),
Status = TrackingCategoryStatus.Active
});
}
public Option Given_a_tracking_option()
{
return new Option()
{
Id = Guid.Empty,
Name = "Option " + Guid.NewGuid(),
Status = TrackingOptionStatus.Active
};
}
public List