1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
public class ReportSmokeTests : IClassFixture<WebApplicationFixture>
{
private RequestAdapter _requestAdapter;
private readonly WebApplicationFixture _fixture;
public ReportSmokeTests(WebApplicationFixture fixture)
{
_fixture = fixture;
_requestAdapter = new RequestAdapter(_fixture.Client);
}
[Fact]
public async Task Report_Should_Be_OK()
{
var tenantId = await _requestAdapter.CreateUserWorkspaceAsync();
_requestAdapter = new RequestAdapter(_fixture.Client, tenantId);
await GenerateTestData();
await Profit_And_Loss_Report_Should_Be_OK();
await Trial_Balance_Report_Should_Be_OK();
await Cash_Flow_Report_Should_Be_OK();
await Balance_Sheet_Report_Should_Be_OK();
await Credit_Balance_Report_Should_Be_OK();
await Revenue_By_Customer_Report_Should_Be_OK();
await Invoice_Details_Report_Should_Be_OK();
await Payment_Collected_Report_Should_Be_OK();
}
private async Task Profit_And_Loss_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<ProfitAndLossReportDto>(
$"{BaseApi.Report}/profitAndLoss?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.NetProfit.Should().Be(641.63M);
}
private async Task Trial_Balance_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<TrialBalanceReportDto>(
$"{BaseApi.Report}/trialBalance?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.TotalDebit.Should().Be(3298.77M);
record.TotalCredit.Should().Be(3298.77M);
}
private async Task Cash_Flow_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<CashFlowReportDto>(
$"{BaseApi.Report}/cashFlow?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.StartingBalance.Should().Be(0);
record.EndingBalance.Should().Be(2423.48M);
}
private async Task Balance_Sheet_Report_Should_Be_OK()
{
// Arrange
var date = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<BalanceSheetReportDto>(
$"{BaseApi.Report}/balanceSheet?date={date.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.Details[0].Total.Should().Be(2522.07M);
record.Details[1].Total.Should().Be(2522.07M);
}
private async Task Credit_Balance_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<CreditBalanceReportDto>(
$"{BaseApi.Report}/creditBalance?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.TotalCreditIssued.Should().Be(301.39M);
record.TotalCreditApplied.Should().Be(30);
record.TotalCreditBalance.Should().Be(271.39M);
}
private async Task Revenue_By_Customer_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<RevenueByCustomerReportDto>(
$"{BaseApi.Report}/revenueByCustomer?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.Total.Should().Be(1635.57M);
}
private async Task Invoice_Details_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<InvoiceDetailsReportDto>(
$"{BaseApi.Report}/invoiceDetails?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.Summary.TotalInvoice.Should().Be(1635.57M);
record.Summary.AmountPaid.Should().Be(1536.98M);
record.Summary.AmountDue.Should().Be(98.59M);
}
private async Task Payment_Collected_Report_Should_Be_OK()
{
// Arrange
var fromDate = new DateTime(2020, 01, 01);
var toDate = DateTime.Now;
// Act
var (record, response) = await _requestAdapter.GetAsync<PaymentsCollectedReportDto>(
$"{BaseApi.Report}/paymentsCollected?fromDate={fromDate.ToUniversalTime():o}&toDate={toDate.ToUniversalTime():o}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
record.Total.Should().Be(1808.37M);
}
private async Task GenerateTestData()
{
var billBuilder = BillBuilder.Create(_requestAdapter);
var invoiceBuilder = InvoiceBuilder.Create(_requestAdapter);
var journalFactory = JournalFactory.Create(_requestAdapter);
var expensePaymentFactory = ExpensePaymentFactory.Create(_requestAdapter);
await billBuilder.RunAsync(true, BillStatus.Issued, 1, 50, 7, 30, BillStatus.Partial);
await billBuilder.RunAsync(true, BillStatus.Issued, 2, 23, 4, 12, BillStatus.Partial);
await billBuilder.RunAsync(true, BillStatus.Issued, 4, 74, 3, 36, BillStatus.Partial);
await billBuilder.RunAsync(true, BillStatus.Issued, 3, 50, 7, 160.5M, BillStatus.Paid);
await invoiceBuilder.RunAsync(true, InvoiceStatus.Issued, 1, 50, 7, 9, 30, InvoiceStatus.Partial);
await invoiceBuilder.RunAsync(true, InvoiceStatus.Issued, 2, 50, 7, 9, 97.37M, InvoiceStatus.Paid);
await invoiceBuilder.RunAsync(true, InvoiceStatus.Issued, 2, 250, 7, 9, 550M, InvoiceStatus.Paid);
await invoiceBuilder.RunAsync(true, InvoiceStatus.Issued, 4, 233, 3, 7, 1024M, InvoiceStatus.Paid);
await invoiceBuilder.RunAsync(true, InvoiceStatus.Issued, 2, 53, 8, 4, 30, 100, InvoiceStatus.Partial);
await journalFactory.CreateJournalAsync(1237,
AccountType.Asset,
AccountSubType.CashAndBank,
AccountGroup.Bank,
AccountType.Equity,
AccountSubType.Equity,
AccountGroup.Default);
await expensePaymentFactory.CreateExpensePaymentAsync(42);
await expensePaymentFactory.CreateExpensePaymentAsync(13);
await expensePaymentFactory.CreateExpensePaymentAsync(27);
}
}
|