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

b1f6c1c4 / ProfessionalAccounting / 307

25 Sep 2023 04:48AM UTC coverage: 56.975% (-1.3%) from 58.254%
307

push

appveyor

b1f6c1c4
raw subtotal more controllable

5947 of 10438 relevant lines covered (56.97%)

125.9 hits per line

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

35.29
/AccountingServer.Shell/Serializer/IEntitySerializer.cs
1
/* Copyright (C) 2020-2023 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.Collections.Generic;
20
using System.Linq;
21
using AccountingServer.Entities;
22

23
namespace AccountingServer.Shell.Serializer;
24

25
/// <summary>
26
///     表示器
27
/// </summary>
28
public interface IEntitySerializer
29
{
30
    /// <summary>
31
    ///     将记账凭证表示
32
    /// </summary>
33
    /// <param name="voucher">记账凭证</param>
34
    /// <returns>表示</returns>
35
    string PresentVoucher(Voucher voucher);
36

37
    /// <summary>
38
    ///     将记账凭证表示,并嵌入任意字符串
39
    /// </summary>
40
    /// <param name="voucher">记账凭证</param>
41
    /// <param name="inject">嵌入字符串</param>
42
    /// <returns>表示</returns>
43
    string PresentVoucher(Voucher voucher, string inject);
44

45
    /// <summary>
46
    ///     从表示中取得记账凭证
47
    /// </summary>
48
    /// <param name="str">表示</param>
49
    /// <returns>记账凭证</returns>
50
    Voucher ParseVoucher(string str);
51

52
    /// <summary>
53
    ///     将细目表示
54
    /// </summary>
55
    /// <param name="detail">细目</param>
56
    /// <returns>表示</returns>
57
    string PresentVoucherDetail(VoucherDetail detail);
58

59
    /// <summary>
60
    ///     将带记账凭证的细目表示
61
    /// </summary>
62
    /// <param name="detail">细目</param>
63
    /// <returns>表示</returns>
64
    string PresentVoucherDetail(VoucherDetailR detail);
65

66
    /// <summary>
67
    ///     从表示中取得记账凭证细目
68
    /// </summary>
69
    /// <param name="str">表达</param>
70
    /// <returns>细目</returns>
71
    VoucherDetail ParseVoucherDetail(string str);
72

73
    /// <summary>
74
    ///     将资产表示
75
    /// </summary>
76
    /// <param name="asset">资产</param>
77
    /// <returns>表示</returns>
78
    string PresentAsset(Asset asset);
79

80
    /// <summary>
81
    ///     从表示中取得资产
82
    /// </summary>
83
    /// <param name="str">表示</param>
84
    /// <returns>资产</returns>
85
    Asset ParseAsset(string str);
86

87
    /// <summary>
88
    ///     将摊销表示
89
    /// </summary>
90
    /// <param name="amort">摊销</param>
91
    /// <returns>表示</returns>
92
    string PresentAmort(Amortization amort);
93

94
    /// <summary>
95
    ///     从表示中取得摊销
96
    /// </summary>
97
    /// <param name="str">表示</param>
98
    /// <returns>摊销</returns>
99
    Amortization ParseAmort(string str);
100
}
101

102
internal interface IEntitiesSerializer : IEntitySerializer
103
{
104
    /// <summary>
105
    ///     将多个记账凭证表示
106
    /// </summary>
107
    /// <param name="vouchers">记账凭证</param>
108
    /// <returns>表示</returns>
109
    IAsyncEnumerable<string> PresentVouchers(IAsyncEnumerable<Voucher> vouchers);
110

111
    /// <summary>
112
    ///     将多个细目表示
113
    /// </summary>
114
    /// <param name="details">细目</param>
115
    /// <returns>表示</returns>
116
    IAsyncEnumerable<string> PresentVoucherDetails(IAsyncEnumerable<VoucherDetail> details);
117

118
    /// <summary>
119
    ///     将多个带记账凭证的细目表示
120
    /// </summary>
121
    /// <param name="details">细目</param>
122
    /// <returns>表示</returns>
123
    IAsyncEnumerable<string> PresentVoucherDetails(IAsyncEnumerable<VoucherDetailR> details);
124

125
    /// <summary>
126
    ///     将多个资产表示
127
    /// </summary>
128
    /// <param name="assets">资产</param>
129
    /// <returns>表示</returns>
130
    IAsyncEnumerable<string> PresentAssets(IAsyncEnumerable<Asset> assets);
131

132
    /// <summary>
133
    ///     将多个摊销表示
134
    /// </summary>
135
    /// <param name="amorts">摊销</param>
136
    /// <returns>表示</returns>
137
    IAsyncEnumerable<string> PresentAmorts(IAsyncEnumerable<Amortization> amorts);
138
}
139

140
internal static class SerializerHelper
141
{
142
    public static string Wrap(this string str) => $"@{str}@\n";
14✔
143
}
144

145
internal class TrivialEntitiesSerializer : IEntitiesSerializer
146
{
147
    private readonly IEntitySerializer m_Serializer;
148
    public TrivialEntitiesSerializer(IEntitySerializer serializer) => m_Serializer = serializer;
10✔
149

150
    public IAsyncEnumerable<string> PresentVouchers(IAsyncEnumerable<Voucher> vouchers)
151
        => vouchers.Select(voucher => m_Serializer.PresentVoucher(voucher).Wrap());
2✔
152

153
    public IAsyncEnumerable<string> PresentVoucherDetails(IAsyncEnumerable<VoucherDetail> details)
154
        => details.Select(detail => m_Serializer.PresentVoucherDetail(detail));
×
155

156
    public IAsyncEnumerable<string> PresentVoucherDetails(IAsyncEnumerable<VoucherDetailR> details)
157
        => details.Select(detail => m_Serializer.PresentVoucherDetail(detail));
2✔
158

159
    public IAsyncEnumerable<string> PresentAssets(IAsyncEnumerable<Asset> assets)
160
        => assets.Select(asset => m_Serializer.PresentAsset(asset).Wrap());
×
161

162
    public IAsyncEnumerable<string> PresentAmorts(IAsyncEnumerable<Amortization> amorts)
163
        => amorts.Select(amort => m_Serializer.PresentAmort(amort).Wrap());
×
164

165
    public string PresentVoucher(Voucher voucher) => m_Serializer.PresentVoucher(voucher);
12✔
166
    public string PresentVoucher(Voucher voucher, string inject) => m_Serializer.PresentVoucher(voucher, inject);
×
167
    public Voucher ParseVoucher(string str) => m_Serializer.ParseVoucher(str);
14✔
168
    public string PresentVoucherDetail(VoucherDetail detail) => m_Serializer.PresentVoucherDetail(detail);
×
169
    public string PresentVoucherDetail(VoucherDetailR detail) => m_Serializer.PresentVoucherDetail(detail);
×
170
    public VoucherDetail ParseVoucherDetail(string str) => m_Serializer.ParseVoucherDetail(str);
×
171
    public string PresentAsset(Asset asset) => m_Serializer.PresentAsset(asset);
×
172
    public Asset ParseAsset(string str) => m_Serializer.ParseAsset(str);
×
173
    public string PresentAmort(Amortization amort) => m_Serializer.PresentAmort(amort);
×
174
    public Amortization ParseAmort(string str) => m_Serializer.ParseAmort(str);
×
175
}
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