• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 320

16 Oct 2024 05:07PM UTC coverage: 55.799% (-1.1%) from 56.944%
320

push

appveyor

b1f6c1c4
final taobao

6264 of 11226 relevant lines covered (55.8%)

126.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.38
/AccountingServer.Test/IntegrationTest/VoucherTest/QueryTest.cs
1
/* Copyright (C) 2020-2024 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using System.Collections;
21
using System.Collections.Generic;
22
using System.Diagnostics.CodeAnalysis;
23
using System.Linq;
24
using System.Threading.Tasks;
25
using AccountingServer.BLL;
26
using AccountingServer.DAL;
27
using AccountingServer.Entities;
28
using AccountingServer.Entities.Util;
29
using Xunit;
30
using static AccountingServer.BLL.Parsing.FacadeF;
31

32
namespace AccountingServer.Test.IntegrationTest.VoucherTest;
33

34
public abstract class QueryTestBase
35
{
36
    protected abstract Client Client { get; }
37

38
    protected abstract ValueTask PrepareVoucher(Voucher voucher);
39
    protected abstract ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query);
40
    protected abstract ValueTask ResetVouchers();
41

42
    public virtual async Task RunTestA(bool expected, string query)
43
    {
180✔
44
        var voucher = new Voucher
180✔
45
            {
46
                ID = null,
47
                Date = null,
48
                Type = VoucherType.Uncertain,
49
                Remark = "rmk1",
50
                Details = new()
51
                    {
52
                        new()
53
                            {
54
                                User = "b1",
55
                                Currency = "JPY",
56
                                Title = 1001,
57
                                SubTitle = 05,
58
                                Content = "cont1",
59
                                Fund = 123.45,
60
                            },
61
                        new()
62
                            {
63
                                User = "b1",
64
                                Currency = "JPY",
65
                                Title = 1234,
66
                                Remark = "remk2",
67
                                Fund = -123.45,
68
                            },
69
                        new()
70
                            {
71
                                User = "b1",
72
                                Currency = "USD",
73
                                Title = 2345,
74
                                Content = "cont3",
75
                                Fund = -77.66,
76
                            },
77
                        new()
78
                            {
79
                                User = "b1",
80
                                Currency = "USD",
81
                                Title = 3456,
82
                                SubTitle = 05,
83
                                Content = "cont4",
84
                                Remark = "remk4",
85
                                Fund = 77.66,
86
                            },
87
                        new()
88
                            {
89
                                User = "b1&b2",
90
                                Currency = "eur#",
91
                                Title = 1111,
92
                                SubTitle = 22,
93
                                Fund = 114514,
94
                            },
95
                    },
96
            };
97

98
        await ResetVouchers();
180✔
99
        await PrepareVoucher(voucher);
180✔
100
        Assert.Equal(expected, await RunQuery(ParsingF.VoucherQuery(query, Client)));
180✔
101
        await ResetVouchers();
180✔
102
    }
180✔
103

104
    protected class DataProvider : IEnumerable<object[]>
105
    {
106
        private static readonly List<object[]> Data = new()
1✔
107
            {
108
                new object[] { true, "" },
109
                new object[] { false, "[null]%rmk%Uncertain" },
110
                new object[] { false, "[null]%rMk1%Uncertain" },
111
                new object[] { true, "[null]%rMk%.*Uncertain" },
112
                new object[] { false, "[null]Uncertain%rmk%" },
113
                new object[] { false, "[null]Uncertain%rMk1%" },
114
                new object[] { true, "[null]Uncertain%rMk%.*" },
115
                new object[] { true, "{}-{null}*{{Devalue}+{Amortization}}" },
116
                new object[] { true, "-{%rrr%}+{20170101}" },
117
                new object[] { false, "{^59278b516c2f021e80f51911^}+{G}*{%asdf%}" },
118
                new object[] { true, "@JPY T100105'cont1'>" },
119
                new object[] { true, "@JPY T123400\"remk2\"=-123.45" },
120
                new object[] { true, "@JPY T123400\"remk2\"=123.45" },
121
                new object[] { false, "@JPY T123400\"remk2\"=+123.45" },
122
                new object[] { true, "@USD T2345'cont3'<" },
123
                new object[] { true, "@USD T3456'cont4'\"remk4\"=77.66" },
124
                new object[] { true, "@USD T3456'cont4'\"remk4\"=+77.66" },
125
                new object[] { true, "{(T1234+T345605)*(''+'cont3')}-{Depreciation}-{Carry}" },
126
                new object[] { false, "T1002+'  '''+\" rmk\"+=77.66001" },
127
                new object[] { true, "(@USD+@JPY)*(=-123.45+>)+T2345+Ub1&b2@#eur# A" },
128
                new object[] { false, "(@USD+@JPY)*=-123.45+T2345+Ub1&b2@#eur# A" },
129
                new object[] { true, "{T1001+(T1234+(T2345)+T3456)+Ub1&b2@#eur# A}-{AnnualCarry}" },
130
                new object[] { true, "+(T1001+(T1234+T2345))+T3456+Ub1&b2@#eur# A" },
131
                new object[] { true, "{((<+>)*())+=1*=2+Ub1&b2@#eur# A}-{Ordinary}" },
132
                new object[] { true, "U-=1*=2 A" },
133
                new object[] { true, "-=1*=2 A" },
134
                new object[] { true, "{T1001 null Uncertain}*{T2345 G}-{T3456 A}" },
135
                new object[] { false, "{20170101~20180101}+{~~20160101}" },
136
                new object[] { true, "{20170101~~20180101}*{~20160101}" },
137
                new object[] { true, "U-" },
138
                new object[] { true, "-" },
139
                new object[] { false, "U- A" },
140
                new object[] { false, "- A" },
141
                new object[] { true, "U@#eur#\"\"" },
142
                new object[] { true, "U'b1&b2'" },
143
                new object[] { true, "Ub1+Ub1&b2 A" },
144
                new object[] { true, "U A" },
145
                new object[] { true, "@JPY Asset" },
146
                new object[] { true, "Liability cont3" },
147
                new object[] { true, "U @USD - U Asset - U Equity - U Revenue - U Expense" },
148
                new object[] { false, "%%" },
149
                new object[] { true, "U 'ConT'.**U\"rEMk\".*" },
150
                new object[] { false, "U 'cont\\'.*+U\"remk#\".*" },
151
                new object[] { true, "Ub1&b2 @#@" },
152
                new object[] { false, "Ub1&b2 @##@" },
153
            };
154

155
        public IEnumerator<object[]> GetEnumerator() => Data.GetEnumerator();
4✔
156
        IEnumerator IEnumerable.GetEnumerator() => Data.GetEnumerator();
×
157
    }
158
}
159

160
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
161
public class MatchTest : QueryTestBase
162
{
163
    private Voucher m_Voucher;
164
    protected override Client Client { get; } = new() { User = "b1", Today = DateTime.UtcNow.Date };
45✔
165

166
    protected override ValueTask PrepareVoucher(Voucher voucher)
167
    {
45✔
168
        m_Voucher = voucher;
45✔
169
        return new();
45✔
170
    }
45✔
171

172
    protected override ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
173
        => ValueTask.FromResult(MatchHelper.IsMatch(m_Voucher, query));
45✔
174

175
    protected override ValueTask ResetVouchers()
176
    {
90✔
177
        m_Voucher = null;
90✔
178
        return new();
90✔
179
    }
90✔
180

181
    [Theory]
182
    [ClassData(typeof(DataProvider))]
183
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
45✔
184
}
185

186
[Collection("DbTestCollection")]
187
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
188
public class DbQueryTest : QueryTestBase, IDisposable
189
{
190
    private readonly IDbAdapter m_Adapter;
191

192
    public DbQueryTest()
45✔
193
    {
45✔
194
        m_Adapter = Facade.Create(db: "accounting-test");
45✔
195

196
        m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance).AsTask().Wait();
45✔
197
    }
45✔
198

199
    protected override Client Client { get; } = new() { User = "b1", Today = DateTime.UtcNow.Date };
45✔
200

201
    public void Dispose() => m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance).AsTask().Wait();
45✔
202

203
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Adapter.Upsert(voucher);
45✔
204

205
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
206
        => await m_Adapter.SelectVouchers(query).SingleOrDefaultAsync() != null;
45✔
207

208
    protected override async ValueTask ResetVouchers()
209
        => await m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance);
90✔
210

211
    [Theory]
212
    [ClassData(typeof(DataProvider))]
213
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
45✔
214
}
215

216
[Collection("DbTestCollection")]
217
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
218
public class BLLQueryTest : QueryTestBase, IDisposable
219
{
220
    private readonly Accountant m_Accountant;
221

222
    public BLLQueryTest()
45✔
223
    {
45✔
224
        m_Accountant = new(new(db: "accounting-test"), "b1", DateTime.UtcNow.Date);
45✔
225

226
        m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
45✔
227
    }
45✔
228

229
    protected override Client Client => m_Accountant.Client;
45✔
230

231
    public void Dispose() => m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
45✔
232

233
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Accountant.UpsertAsync(voucher);
45✔
234

235
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
236
        => await m_Accountant.SelectVouchersAsync(query).SingleOrDefaultAsync() != null;
45✔
237

238
    protected override async ValueTask ResetVouchers()
239
        => await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
90✔
240

241
    [Theory]
242
    [ClassData(typeof(DataProvider))]
243
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
45✔
244
}
245

246
[Collection("DbTestCollection")]
247
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
248
public class VirtualizedQueryTest : QueryTestBase, IAsyncDisposable
249
{
250
    private readonly Accountant m_Accountant;
251
    private readonly Accountant.VirtualizeLock m_Lock;
252

253
    public VirtualizedQueryTest()
45✔
254
    {
45✔
255
        m_Accountant = new(new(db: "accounting-test"), "b1", DateTime.UtcNow.Date);
45✔
256

257
        m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
45✔
258
        m_Lock = m_Accountant.Virtualize();
45✔
259
    }
45✔
260

261
    protected override Client Client => m_Accountant.Client;
45✔
262

263
    public async ValueTask DisposeAsync()
264
    {
×
265
        await m_Lock.DisposeAsync();
×
266
        await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
×
267
    }
×
268

269
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Accountant.UpsertAsync(voucher);
45✔
270

271
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
272
        => await m_Accountant.SelectVouchersAsync(query).SingleOrDefaultAsync() != null;
45✔
273

274
    protected override async ValueTask ResetVouchers()
275
        => await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
90✔
276

277
    [Theory]
278
    [ClassData(typeof(DataProvider))]
279
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
45✔
280
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc