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

b1f6c1c4 / ProfessionalAccounting / 296

02 Jan 2023 05:19AM UTC coverage: 35.998% (-0.05%) from 36.047%
296

push

appveyor

b1f6c1c4
filter on sem

9757 of 27104 relevant lines covered (36.0%)

719.91 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-2022 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
    {
152✔
44
        var voucher = new Voucher
152✔
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();
152✔
99
        await PrepareVoucher(voucher);
152✔
100
        Assert.Equal(expected, await RunQuery(ParsingF.VoucherQuery(query, Client)));
152✔
101
        await ResetVouchers();
152✔
102
    }
152✔
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[] { true, "[null]Uncertain%rmk%" },
110
                new object[] { true, "{}-{null}*{{Devalue}+{Amortization}}" },
111
                new object[] { true, "-{%rrr%}+{20170101}" },
112
                new object[] { false, "{^59278b516c2f021e80f51911^}+{G}*{%asdf%}" },
113
                new object[] { true, "@JPY T100105'cont1'>" },
114
                new object[] { true, "@JPY T123400\"remk2\"=-123.45" },
115
                new object[] { true, "@JPY T123400\"remk2\"=123.45" },
116
                new object[] { false, "@JPY T123400\"remk2\"=+123.45" },
117
                new object[] { true, "@USD T2345'cont3'<" },
118
                new object[] { true, "@USD T3456'cont4'\"remk4\"=77.66" },
119
                new object[] { true, "@USD T3456'cont4'\"remk4\"=+77.66" },
120
                new object[] { true, "{(T1234+T345605)*(''+'cont3')}-{Depreciation}-{Carry}" },
121
                new object[] { false, "T1002+'  '''+\" rmk\"+=77.66001" },
122
                new object[] { true, "(@USD+@JPY)*(=-123.45+>)+T2345+Ub1&b2@EUR A" },
123
                new object[] { false, "(@USD+@JPY)*=-123.45+T2345+Ub1&b2@EUR A" },
124
                new object[] { true, "{T1001+(T1234+(T2345)+T3456)+Ub1&b2@EUR A}-{AnnualCarry}" },
125
                new object[] { true, "+(T1001+(T1234+T2345))+T3456+Ub1&b2@EUR A" },
126
                new object[] { true, "{((<+>)*())+=1*=2+Ub1&b2@EUR A}-{Ordinary}" },
127
                new object[] { true, "U-=1*=2 A" },
128
                new object[] { true, "-=1*=2 A" },
129
                new object[] { true, "{T1001 null Uncertain}*{T2345 G}-{T3456 A}" },
130
                new object[] { false, "{20170101~20180101}+{~~20160101}" },
131
                new object[] { true, "{20170101~~20180101}*{~20160101}" },
132
                new object[] { true, "U-" },
133
                new object[] { true, "-" },
134
                new object[] { false, "U- A" },
135
                new object[] { false, "- A" },
136
                new object[] { true, "U@EUR\"\"" },
137
                new object[] { true, "U'b1&b2'" },
138
                new object[] { true, "Ub1+Ub1&b2 A" },
139
                new object[] { true, "U A" },
140
                new object[] { true, "@JPY Asset" },
141
                new object[] { true, "Liability cont3" },
142
                new object[] { true, "U @USD - U Asset - U Equity - U Revenue - U Expense" },
143
                new object[] { false, "%%" },
144
                new object[] { true, "U 'ConT'.**U\"rEMk\".*" },
145
                new object[] { false, "U 'cont\\'.*+U\"remk#\".*" },
146
            };
147

148
        public IEnumerator<object[]> GetEnumerator() => Data.GetEnumerator();
4✔
149
        IEnumerator IEnumerable.GetEnumerator() => Data.GetEnumerator();
×
150
    }
151
}
152

153
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
154
public class MatchTest : QueryTestBase
155
{
156
    private Voucher m_Voucher;
157
    protected override Client Client { get; } = new() { User = "b1", Today = DateTime.UtcNow.Date };
38✔
158

159
    protected override ValueTask PrepareVoucher(Voucher voucher)
160
    {
38✔
161
        m_Voucher = voucher;
38✔
162
        return new();
38✔
163
    }
38✔
164

165
    protected override ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
166
        => ValueTask.FromResult(MatchHelper.IsMatch(m_Voucher, query));
38✔
167

168
    protected override ValueTask ResetVouchers()
169
    {
76✔
170
        m_Voucher = null;
76✔
171
        return new();
76✔
172
    }
76✔
173

174
    [Theory]
175
    [ClassData(typeof(DataProvider))]
176
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
38✔
177
}
178

179
[Collection("DbTestCollection")]
180
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
181
public class DbQueryTest : QueryTestBase, IDisposable
182
{
183
    private readonly IDbAdapter m_Adapter;
184

185
    public DbQueryTest()
38✔
186
    {
38✔
187
        m_Adapter = Facade.Create(db: "accounting-test");
38✔
188

189
        m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance).AsTask().Wait();
38✔
190
    }
38✔
191

192
    protected override Client Client { get; } = new() { User = "b1", Today = DateTime.UtcNow.Date };
38✔
193

194
    public void Dispose() => m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance).AsTask().Wait();
38✔
195

196
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Adapter.Upsert(voucher);
38✔
197

198
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
199
        => await m_Adapter.SelectVouchers(query).SingleOrDefaultAsync() != null;
38✔
200

201
    protected override async ValueTask ResetVouchers()
202
        => await m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance);
76✔
203

204
    [Theory]
205
    [ClassData(typeof(DataProvider))]
206
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
38✔
207
}
208

209
[Collection("DbTestCollection")]
210
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
211
public class BLLQueryTest : QueryTestBase, IDisposable
212
{
213
    private readonly Accountant m_Accountant;
214

215
    public BLLQueryTest()
38✔
216
    {
38✔
217
        m_Accountant = new(new(db: "accounting-test"), "b1", DateTime.UtcNow.Date);
38✔
218

219
        m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
38✔
220
    }
38✔
221

222
    protected override Client Client => m_Accountant.Client;
38✔
223

224
    public void Dispose() => m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
38✔
225

226
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Accountant.UpsertAsync(voucher);
38✔
227

228
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
229
        => await m_Accountant.SelectVouchersAsync(query).SingleOrDefaultAsync() != null;
38✔
230

231
    protected override async ValueTask ResetVouchers()
232
        => await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
76✔
233

234
    [Theory]
235
    [ClassData(typeof(DataProvider))]
236
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
38✔
237
}
238

239
[Collection("DbTestCollection")]
240
[SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
241
public class VirtualizedQueryTest : QueryTestBase, IAsyncDisposable
242
{
243
    private readonly Accountant m_Accountant;
244
    private readonly DbSession.VirtualizeLock m_Lock;
245

246
    public VirtualizedQueryTest()
38✔
247
    {
38✔
248
        m_Accountant = new(new(db: "accounting-test"), "b1", DateTime.UtcNow.Date);
38✔
249

250
        m_Lock = m_Accountant.Virtualize();
38✔
251
        m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
38✔
252
    }
38✔
253

254
    protected override Client Client => m_Accountant.Client;
38✔
255

256
    public async ValueTask DisposeAsync()
257
    {
×
258
        await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
×
259
        await m_Lock.DisposeAsync();
×
260
    }
×
261

262
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Accountant.UpsertAsync(voucher);
38✔
263

264
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
265
        => await m_Accountant.SelectVouchersAsync(query).SingleOrDefaultAsync() != null;
38✔
266

267
    protected override async ValueTask ResetVouchers()
268
        => await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
76✔
269

270
    [Theory]
271
    [ClassData(typeof(DataProvider))]
272
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
38✔
273
}
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