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

b1f6c1c4 / ProfessionalAccounting / 315

13 Apr 2024 08:29AM UTC coverage: 0.0%. Remained the same
315

push

appveyor

b1f6c1c4
rich style

0 of 23101 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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
    {
×
44
        var voucher = new Voucher
×
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();
×
99
        await PrepareVoucher(voucher);
×
100
        Assert.Equal(expected, await RunQuery(ParsingF.VoucherQuery(query, Client)));
×
101
        await ResetVouchers();
×
102
    }
×
103

104
    protected class DataProvider : IEnumerable<object[]>
105
    {
106
        private static readonly List<object[]> Data = new()
×
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
                new object[] { true, "Ub1&b2 @#@" },
147
                new object[] { false, "Ub1&b2 @##@" },
148
            };
149

150
        public IEnumerator<object[]> GetEnumerator() => Data.GetEnumerator();
×
151
        IEnumerator IEnumerable.GetEnumerator() => Data.GetEnumerator();
×
152
    }
153
}
154

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

161
    protected override ValueTask PrepareVoucher(Voucher voucher)
162
    {
×
163
        m_Voucher = voucher;
×
164
        return new();
×
165
    }
×
166

167
    protected override ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
168
        => ValueTask.FromResult(MatchHelper.IsMatch(m_Voucher, query));
×
169

170
    protected override ValueTask ResetVouchers()
171
    {
×
172
        m_Voucher = null;
×
173
        return new();
×
174
    }
×
175

176
    [Theory]
177
    [ClassData(typeof(DataProvider))]
178
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
×
179
}
180

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

187
    public DbQueryTest()
×
188
    {
×
189
        m_Adapter = Facade.Create(db: "accounting-test");
×
190

191
        m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance).AsTask().Wait();
×
192
    }
×
193

194
    protected override Client Client { get; } = new() { User = "b1", Today = DateTime.UtcNow.Date };
×
195

196
    public void Dispose() => m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance).AsTask().Wait();
×
197

198
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Adapter.Upsert(voucher);
×
199

200
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
201
        => await m_Adapter.SelectVouchers(query).SingleOrDefaultAsync() != null;
×
202

203
    protected override async ValueTask ResetVouchers()
204
        => await m_Adapter.DeleteVouchers(VoucherQueryUnconstrained.Instance);
×
205

206
    [Theory]
207
    [ClassData(typeof(DataProvider))]
208
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
×
209
}
210

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

217
    public BLLQueryTest()
×
218
    {
×
219
        m_Accountant = new(new(db: "accounting-test"), "b1", DateTime.UtcNow.Date);
×
220

221
        m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
×
222
    }
×
223

224
    protected override Client Client => m_Accountant.Client;
×
225

226
    public void Dispose() => m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
×
227

228
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Accountant.UpsertAsync(voucher);
×
229

230
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
231
        => await m_Accountant.SelectVouchersAsync(query).SingleOrDefaultAsync() != null;
×
232

233
    protected override async ValueTask ResetVouchers()
234
        => await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
×
235

236
    [Theory]
237
    [ClassData(typeof(DataProvider))]
238
    public override Task RunTestA(bool expected, string query) => base.RunTestA(expected, query);
×
239
}
240

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

248
    public VirtualizedQueryTest()
×
249
    {
×
250
        m_Accountant = new(new(db: "accounting-test"), "b1", DateTime.UtcNow.Date);
×
251

252
        m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance).AsTask().Wait();
×
253
        m_Lock = m_Accountant.Virtualize();
×
254
    }
×
255

256
    protected override Client Client => m_Accountant.Client;
×
257

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

264
    protected override async ValueTask PrepareVoucher(Voucher voucher) => await m_Accountant.UpsertAsync(voucher);
×
265

266
    protected override async ValueTask<bool> RunQuery(IQueryCompounded<IVoucherQueryAtom> query)
267
        => await m_Accountant.SelectVouchersAsync(query).SingleOrDefaultAsync() != null;
×
268

269
    protected override async ValueTask ResetVouchers()
270
        => await m_Accountant.DeleteVouchersAsync(VoucherQueryUnconstrained.Instance);
×
271

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