Skip to content

Commit a8f0f3a

Browse files
committed
Make types public to improve testability
1 parent fa1fc64 commit a8f0f3a

19 files changed

Lines changed: 115 additions & 102 deletions

Taxes/Basics.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using System.Collections.ObjectModel;
33
using System.Globalization;
44
using System.Text.RegularExpressions;
5+
using System.Text.Json.Serialization;
56

67
namespace Taxes;
78

8-
public partial class Basics
9+
internal partial class Basics
910
{
1011
public string ReportsDirectoryPath { get; }
1112

@@ -192,3 +193,17 @@ public sealed class CountryWithholdingTaxes
192193

193194
public sealed record EventsFiles(string FilePattern, string Broker);
194195
}
196+
197+
[JsonSourceGenerationOptions(
198+
WriteIndented = true,
199+
AllowTrailingCommas = true,
200+
PropertyNameCaseInsensitive = true,
201+
ReadCommentHandling = JsonCommentHandling.Skip)]
202+
[JsonSerializable(typeof(Basics))]
203+
public partial class BasicsContext : JsonSerializerContext;
204+
205+
public partial class Basics
206+
{
207+
public static readonly Basics Default =
208+
JsonSerializer.Deserialize<Basics>(
209+
// ... existing code ...

Taxes/CryptoEventsReader.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Taxes;
66

7-
class CryptoEventsReader(Basics basics)
7+
public class CryptoEventsReader(Basics basics)
88
{
99
// Unlike stocks, which are considered distinct assets, all cryptos, from a tax perspective, are considered a single asset.
1010
// When a stock is bought or sold, the tax office looks into what specific stock has been affected by the financial event, and tax
@@ -21,13 +21,13 @@ class CryptoEventsReader(Basics basics)
2121
// TRANSFER,Current,2022-06-25 13:29:03,2022-06-25 13:29:03,Exchanged to ZRX,1000.0000000000,ZRX,293.9067439000,298.3167439000,4.4100000000,EUR,COMPLETED,1000.0000000000
2222
// REWARD,Current,2022-06-25 13:29:03,2022-06-25 13:29:03,Exchanged to ZRX,1000.0000000000,ZRX,293.9067439000,298.3167439000,4.4100000000,EUR,COMPLETED,1000.0000000000
2323

24-
const string Type_Reset = "RESET";
25-
const string Type_Transfer = "TRANSFER";
26-
const string Type_Exchange = "EXCHANGE";
27-
const string Type_Reward = "REWARD";
28-
const string Product_Current = "Current";
29-
const string Product_CryptoStaking = "Crypto Staking";
30-
const string State_Completed = "COMPLETED";
24+
private const string Type_Reset = "RESET";
25+
private const string Type_Transfer = "TRANSFER";
26+
private const string Type_Exchange = "EXCHANGE";
27+
private const string Type_Reward = "REWARD";
28+
private const string Product_Current = "Current";
29+
private const string Product_CryptoStaking = "Crypto Staking";
30+
private const string State_Completed = "COMPLETED";
3131

3232
// Example of 2025 CSV format:
3333
// Symbol,Type,Quantity,Price,Value,Fees,Date
@@ -37,9 +37,9 @@ class CryptoEventsReader(Basics basics)
3737
// BTC,Sell,0.03053533,"EUR 63,551.31","EUR 1,940.56",EUR 19.21,"May 22, 2024, 3:30:49 PM"
3838
// ETH,Sell,0.1,"3,235.24 CHF",323.52 CHF,2.55 CHF,"Dec 1, 2024, 7:58:16 PM"
3939

40-
const string Type2025_Buy = "Buy";
41-
const string Type2025_Sell = "Sell";
42-
const string Type2025_Reset = "Reset";
40+
private const string Type2025_Buy = "Buy";
41+
private const string Type2025_Sell = "Sell";
42+
private const string Type2025_Reset = "Reset";
4343

4444
public Basics Basics => basics;
4545

Taxes/CryptoPortfolioValues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Taxes;
66

7-
class CryptoPortfolioValues
7+
public class CryptoPortfolioValues
88
{
99
private static CsvConfiguration CsvConfiguration(Basics basics) =>
1010
new(basics.DefaultCulture)

Taxes/DecimalExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Taxes;
22

3-
public static class DecimalExtensions
3+
internal static class DecimalExtensions
44
{
55
/// <summary>
66
/// Shortcut to round a decimal via the Rounding method defined in the provided Basics

Taxes/EnumerableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Taxes;
22

3-
static class EnumerableExtensions
3+
internal static class EnumerableExtensions
44
{
55
public static IEnumerable<T> EnsureNonEmpty<T>(this IEnumerable<T> values)
66
{

Taxes/Event.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// - Fees: fees of all shares in this event
1212
/// - Portfolio: all shares of all events, not just this event
1313
/// </summary>
14-
record Event(
14+
public record Event(
1515
/// <summary>
1616
/// The date and time at which the event occurred.
1717
/// It's mandatory for all types of events, even synthetic ones like Reset.

Taxes/EventType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Taxes;
22

33
/// <summary>
4-
/// The type of an event.
4+
/// The type of event.
55
/// </summary>
66
public enum EventType
77
{

Taxes/EventsFileAndBroker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
namespace Taxes;
22

3-
record EventsFileAndBroker(string FilePath, string Broker);
3+
public record EventsFileAndBroker(string FilePath, string Broker);

Taxes/FXRates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public record FxRates(Basics Basics, Dictionary<string, Dictionary<DateTime, dec
3838
return result;
3939
}
4040

41-
static bool IsWeekend(DateTime date) => date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday;
41+
private static bool IsWeekend(DateTime date) => date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday;
4242

4343
internal sealed class DictionaryAlwaysReturning1 : IDictionary<DateTime, decimal>
4444
{

Taxes/FileUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Taxes;
44

5-
public static class FileUtils
5+
internal static class FileUtils
66
{
77
public static string CalculateMD5Digest(string filePath)
88
{

0 commit comments

Comments
 (0)