Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 1m57s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using FreeSql;
|
|
using Repository;
|
|
|
|
namespace WebApi.Test.Basic;
|
|
|
|
public class DatabaseTest : BaseTest, IDisposable
|
|
{
|
|
protected IFreeSql FreeSql { get; }
|
|
protected ITransactionRecordRepository Repository { get; }
|
|
|
|
public DatabaseTest()
|
|
{
|
|
FreeSql = new FreeSqlBuilder()
|
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
|
.UseAutoSyncStructure(true)
|
|
.UseNoneCommandParameter(true)
|
|
.Build();
|
|
|
|
Repository = new TransactionRecordRepository(FreeSql);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
FreeSql.Dispose();
|
|
}
|
|
|
|
protected TransactionRecord CreateTestRecord(
|
|
decimal amount,
|
|
TransactionType type = TransactionType.Expense,
|
|
DateTime? occurredAt = null,
|
|
string reason = "测试摘要",
|
|
string classify = "测试分类")
|
|
{
|
|
return new TransactionRecord
|
|
{
|
|
Amount = amount,
|
|
Type = type,
|
|
OccurredAt = occurredAt ?? DateTime.Now,
|
|
Reason = reason,
|
|
Classify = classify,
|
|
Card = "1234",
|
|
Balance = 1000,
|
|
EmailMessageId = 1,
|
|
ImportNo = Guid.NewGuid().ToString(),
|
|
ImportFrom = "测试"
|
|
};
|
|
}
|
|
|
|
protected TransactionRecord CreateExpense(decimal amount, DateTime? occurredAt = null, string reason = "支出", string classify = "餐饮")
|
|
{
|
|
return CreateTestRecord(-amount, TransactionType.Expense, occurredAt, reason, classify);
|
|
}
|
|
|
|
protected TransactionRecord CreateIncome(decimal amount, DateTime? occurredAt = null, string reason = "收入", string classify = "工资")
|
|
{
|
|
return CreateTestRecord(amount, TransactionType.Income, occurredAt, reason, classify);
|
|
}
|
|
} |