Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit cb85b16

Browse files
committed
Merge pull request #132 from MatthewSteeples/TestableInterfaces
Demonstration of making wrapper testable
2 parents f1f6c5a + 3884409 commit cb85b16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1657
-914
lines changed

CoreTests/ApiWrapperTest.cs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
using System.Linq;
2-
using Xero.Api.Core;
3-
using Xero.Api.Core.Model;
4-
5-
namespace CoreTests
6-
{
7-
public class ApiWrapperTest
8-
{
9-
private XeroCoreApi _api;
10-
11-
protected Account BankAccount { get; set; }
12-
protected Account Account { get; set; }
13-
14-
protected XeroCoreApi Api
15-
{
16-
get { return _api ?? (_api = CreateCoreApi()); }
17-
}
18-
19-
private static XeroCoreApi CreateCoreApi()
20-
{
21-
return new Xero.Api.Example.Applications.Private.Core
22-
{
23-
UserAgent = "Xero Api - Integration tests"
24-
};
25-
}
26-
27-
protected void SetUp()
28-
{
29-
BankAccount = Given_a_bank_account();
30-
Account = Given_an_account();
31-
}
32-
33-
protected Account Given_a_bank_account()
34-
{
35-
return Api.Accounts.Where("Type == \"BANK\"").Find().First();
36-
}
37-
38-
protected Account Given_an_account()
39-
{
40-
return Api.Accounts.Where("Type != \"BANK\"").Find().First();
41-
}
42-
}
43-
}
1+
using System.Linq;
2+
using Xero.Api.Core;
3+
using Xero.Api.Core.Model;
4+
5+
namespace CoreTests
6+
{
7+
public class ApiWrapperTest
8+
{
9+
private IXeroCoreApi _api;
10+
11+
protected Account BankAccount { get; set; }
12+
protected Account Account { get; set; }
13+
14+
protected IXeroCoreApi Api
15+
{
16+
get { return _api ?? (_api = CreateCoreApi()); }
17+
}
18+
19+
private static IXeroCoreApi CreateCoreApi()
20+
{
21+
return new Xero.Api.Example.Applications.Private.Core
22+
{
23+
UserAgent = "Xero Api - Integration tests"
24+
};
25+
}
26+
27+
protected void SetUp()
28+
{
29+
BankAccount = Given_a_bank_account();
30+
Account = Given_an_account();
31+
}
32+
33+
protected Account Given_a_bank_account()
34+
{
35+
return Api.Accounts.Where("Type == \"BANK\"").Find().First();
36+
}
37+
38+
protected Account Given_an_account()
39+
{
40+
return Api.Accounts.Where("Type != \"BANK\"").Find().First();
41+
}
42+
}
43+
}

CoreTests/Unit/FourDecimalPlaces.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
using NUnit.Framework;
22
using Xero.Api.Common;
3+
using Xero.Api.Core.Endpoints;
34
using Xero.Api.Core.Endpoints.Base;
5+
using Xero.Api.Core.Model;
6+
using Xero.Api.Core.Request;
7+
using Xero.Api.Core.Response;
48
using Xero.Api.Infrastructure.Interfaces;
59

610
namespace CoreTests.Unit
@@ -11,109 +15,109 @@ public class FourDecimalPlaces : ApiWrapperTest
1115
[Test]
1216
public void explict_four_decimal_places_invoices()
1317
{
14-
ExplictUse4Dp(Api.Invoices, "unitdp=4&page=1");
18+
ExplictUse4Dp((FourDecimalPlacesEndpoint<InvoicesEndpoint, Invoice, InvoicesRequest, InvoicesResponse>)Api.Invoices, "unitdp=4&page=1");
1519
}
1620

1721
[Test]
1822
public void implict_four_decimal_places_invoice()
1923
{
20-
ImplicitUse4Dp(Api.Invoices, "unitdp=4&page=1");
24+
ImplicitUse4Dp((FourDecimalPlacesEndpoint<InvoicesEndpoint, Invoice, InvoicesRequest, InvoicesResponse>)Api.Invoices, "unitdp=4&page=1");
2125
}
2226

2327
[Test]
2428
public void no_four_decimal_places_invoice()
2529
{
26-
ExplicitNotUse4Dp(Api.Invoices, "page=1");
30+
ExplicitNotUse4Dp((FourDecimalPlacesEndpoint<InvoicesEndpoint, Invoice, InvoicesRequest, InvoicesResponse>)Api.Invoices, "page=1");
2731
}
2832

2933
[Test]
3034
public void no_four_decimal_places_bank_transactions()
3135
{
32-
ExplicitNotUse4Dp(Api.BankTransactions);
36+
ExplicitNotUse4Dp((FourDecimalPlacesEndpoint<BankTransactionsEndpoint, BankTransaction, BankTransactionsRequest, BankTransactionsResponse>)Api.BankTransactions);
3337
}
3438

3539
[Test]
3640
public void explict_four_decimal_places_bank_transactions()
3741
{
38-
ExplictUse4Dp(Api.BankTransactions);
42+
ExplictUse4Dp((FourDecimalPlacesEndpoint<BankTransactionsEndpoint, BankTransaction, BankTransactionsRequest, BankTransactionsResponse>)Api.BankTransactions);
3943
}
4044

4145
[Test]
4246
public void implict_four_decimal_places_bank_transactions()
4347
{
44-
ImplicitUse4Dp(Api.BankTransactions);
48+
ImplicitUse4Dp((FourDecimalPlacesEndpoint<BankTransactionsEndpoint, BankTransaction, BankTransactionsRequest, BankTransactionsResponse>)Api.BankTransactions);
4549
}
4650

4751
[Test]
4852
public void no_four_decimal_places_credit_notes()
4953
{
50-
ExplicitNotUse4Dp(Api.CreditNotes);
54+
ExplicitNotUse4Dp((FourDecimalPlacesEndpoint<CreditNotesEndpoint, CreditNote, CreditNotesRequest, CreditNotesResponse>)Api.CreditNotes);
5155
}
5256

5357
[Test]
5458
public void explict_four_decimal_places_credit_notes()
5559
{
56-
ExplictUse4Dp(Api.CreditNotes);
60+
ExplictUse4Dp((FourDecimalPlacesEndpoint<CreditNotesEndpoint, CreditNote, CreditNotesRequest, CreditNotesResponse>)Api.CreditNotes);
5761
}
5862

5963
[Test]
6064
public void implict_four_decimal_places_credit_notes()
6165
{
62-
ImplicitUse4Dp(Api.CreditNotes);
66+
ImplicitUse4Dp((FourDecimalPlacesEndpoint<CreditNotesEndpoint, CreditNote, CreditNotesRequest, CreditNotesResponse>)Api.CreditNotes);
6367
}
6468

6569
[Test]
6670
public void no_four_decimal_places_reciepts()
6771
{
68-
ExplicitNotUse4Dp(Api.Receipts);
72+
ExplicitNotUse4Dp((FourDecimalPlacesEndpoint<ReceiptsEndpoint, Receipt, ReceiptsRequest, ReceiptsResponse>)Api.Receipts);
6973
}
7074

7175
[Test]
7276
public void explict_four_decimal_places_reciepts()
7377
{
74-
ExplictUse4Dp(Api.Receipts);
78+
ExplictUse4Dp((FourDecimalPlacesEndpoint<ReceiptsEndpoint, Receipt, ReceiptsRequest, ReceiptsResponse>)Api.Receipts);
7579
}
7680

7781
[Test]
7882
public void implict_four_decimal_places_reciepts()
7983
{
80-
ImplicitUse4Dp(Api.Receipts);
84+
ImplicitUse4Dp((FourDecimalPlacesEndpoint<ReceiptsEndpoint, Receipt, ReceiptsRequest, ReceiptsResponse>)Api.Receipts);
8185
}
8286

8387
[Test]
8488
public void no_four_decimal_places_payments()
8589
{
86-
ExplicitNotUse4Dp(Api.Payments);
90+
ExplicitNotUse4Dp((FourDecimalPlacesEndpoint<PaymentsEndpoint, Payment, PaymentsRequest, PaymentsResponse>)Api.Payments);
8791
}
8892

8993
[Test]
9094
public void explict_four_decimal_places_payments()
9195
{
92-
ExplictUse4Dp(Api.Payments);
96+
ExplictUse4Dp((FourDecimalPlacesEndpoint<PaymentsEndpoint, Payment, PaymentsRequest, PaymentsResponse>)Api.Payments);
9397
}
9498

9599
[Test]
96100
public void implict_four_decimal_places_payments()
97101
{
98-
ImplicitUse4Dp(Api.Payments);
102+
ImplicitUse4Dp((FourDecimalPlacesEndpoint<PaymentsEndpoint, Payment, PaymentsRequest, PaymentsResponse>)Api.Payments);
99103
}
100104

101105
[Test]
102106
public void no_four_decimal_places_items()
103107
{
104-
ExplicitNotUse4Dp(Api.Items);
108+
ExplicitNotUse4Dp((FourDecimalPlacesEndpoint<ItemsEndpoint, Item, ItemsRequest, ItemsResponse>)Api.Items);
105109
}
106110

107111
[Test]
108112
public void explict_four_decimal_places_items()
109113
{
110-
ExplictUse4Dp(Api.Items);
114+
ExplictUse4Dp((FourDecimalPlacesEndpoint< ItemsEndpoint, Item, ItemsRequest, ItemsResponse>) Api.Items);
111115
}
112116

113117
[Test]
114118
public void implict_four_decimal_places_items()
115119
{
116-
ImplicitUse4Dp(Api.Items);
120+
ImplicitUse4Dp((FourDecimalPlacesEndpoint<ItemsEndpoint, Item, ItemsRequest, ItemsResponse>)Api.Items);
117121
}
118122

119123
[Test]

0 commit comments

Comments
 (0)