refactor(infra.tests): moved builders to common project
This commit is contained in:
@@ -1,62 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class AccountBuilder
|
|
||||||
{
|
|
||||||
private string _name = "accountName";
|
|
||||||
private AccountMetadata? _metadata;
|
|
||||||
private readonly List<Transaction> _transactions = [];
|
|
||||||
|
|
||||||
private AccountBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AccountBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountBuilder WithName(string name)
|
|
||||||
{
|
|
||||||
_name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountBuilder WithMetadata(Action<AccountMetadataBuilder>? action = null)
|
|
||||||
{
|
|
||||||
var imb = AccountMetadataBuilder.Create();
|
|
||||||
action?.Invoke(imb);
|
|
||||||
_metadata = imb.Build();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountBuilder WithMetadata(AccountMetadata metadata)
|
|
||||||
{
|
|
||||||
_metadata = metadata;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountBuilder WithTransaction(Action<TransactionBuilder>? action = null)
|
|
||||||
{
|
|
||||||
var tb = TransactionBuilder.Create();
|
|
||||||
action?.Invoke(tb);
|
|
||||||
_transactions.Add(tb.Build());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Account Build()
|
|
||||||
{
|
|
||||||
if (_metadata is null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"You must call {nameof(WithMetadata)} prior to building");
|
|
||||||
}
|
|
||||||
|
|
||||||
var account = Account.From(_name, _metadata);
|
|
||||||
|
|
||||||
foreach (var transaction in _transactions)
|
|
||||||
{
|
|
||||||
account.AddTransaction(transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
return account;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class AccountMetadataBuilder
|
|
||||||
{
|
|
||||||
private string _plaidId = "plaidId";
|
|
||||||
private string _plaidName = "plaidName";
|
|
||||||
|
|
||||||
private AccountMetadataBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AccountMetadataBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountMetadataBuilder WithPlaidId(string plaidId)
|
|
||||||
{
|
|
||||||
_plaidId = plaidId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountMetadataBuilder WithPlaidName(string plaidName)
|
|
||||||
{
|
|
||||||
_plaidName = plaidName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaidAccountMetadata Build()
|
|
||||||
{
|
|
||||||
return PlaidAccountMetadata.From(_plaidId, _plaidName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class InstitutionBuilder
|
|
||||||
{
|
|
||||||
private string _name = "institutionName";
|
|
||||||
private InstitutionMetadata? _metadata;
|
|
||||||
private readonly List<Account> _accounts = [];
|
|
||||||
|
|
||||||
private InstitutionBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InstitutionBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionBuilder WithName(string name)
|
|
||||||
{
|
|
||||||
_name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionBuilder WithMetadata(Action<InstitutionMetadataBuilder>? action = null)
|
|
||||||
{
|
|
||||||
var imb = InstitutionMetadataBuilder.Create();
|
|
||||||
action?.Invoke(imb);
|
|
||||||
_metadata = imb.Build();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionBuilder WithAccount(Action<AccountBuilder>? action = null)
|
|
||||||
{
|
|
||||||
var ab = AccountBuilder.Create();
|
|
||||||
action?.Invoke(ab);
|
|
||||||
_accounts.Add(ab.Build());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Institution Build()
|
|
||||||
{
|
|
||||||
if (_metadata is null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"You must call {nameof(WithMetadata)} prior to building");
|
|
||||||
}
|
|
||||||
|
|
||||||
var institution = Institution.From(
|
|
||||||
_name,
|
|
||||||
_metadata
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach (var account in _accounts)
|
|
||||||
{
|
|
||||||
institution.AddAccount(account);
|
|
||||||
}
|
|
||||||
|
|
||||||
return institution;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class InstitutionMetadataBuilder
|
|
||||||
{
|
|
||||||
private string _plaidId = "plaidId";
|
|
||||||
private string _plaidName = "plaidName";
|
|
||||||
private string _accessToken = "encryptedAccessToken";
|
|
||||||
private string _itemId = "itemId";
|
|
||||||
|
|
||||||
private InstitutionMetadataBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InstitutionMetadataBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionMetadataBuilder WithPlaidId(string plaidId)
|
|
||||||
{
|
|
||||||
_plaidId = plaidId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionMetadataBuilder WithPlaidName(string plaidName)
|
|
||||||
{
|
|
||||||
_plaidName = plaidName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionMetadataBuilder WithAccessToken(string accessToken)
|
|
||||||
{
|
|
||||||
_accessToken = accessToken;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InstitutionMetadataBuilder WithItemId(string itemId)
|
|
||||||
{
|
|
||||||
_itemId = itemId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaidInstitutionMetadata Build()
|
|
||||||
{
|
|
||||||
return PlaidInstitutionMetadata.From(
|
|
||||||
_plaidId,
|
|
||||||
_plaidName,
|
|
||||||
_accessToken,
|
|
||||||
_itemId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class TransactionBuilder
|
|
||||||
{
|
|
||||||
private string _merchantName = "merchantName";
|
|
||||||
private string _description = "description";
|
|
||||||
private decimal _amount = 100;
|
|
||||||
private DateTimeOffset _date = DateTimeOffset.UtcNow;
|
|
||||||
private TransactionMetadata? _metadata;
|
|
||||||
|
|
||||||
private TransactionBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TransactionBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder WithMerchantName(string merchantName)
|
|
||||||
{
|
|
||||||
_merchantName = merchantName;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder WithDescription(string description)
|
|
||||||
{
|
|
||||||
_description = description;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder WithAmount(decimal amount)
|
|
||||||
{
|
|
||||||
_amount = amount;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder WithDate(DateTimeOffset date)
|
|
||||||
{
|
|
||||||
_date = date;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder WithMetadata(Action<TransactionMetadataBuilder>? action = null)
|
|
||||||
{
|
|
||||||
var tmb = TransactionMetadataBuilder.Create();
|
|
||||||
action?.Invoke(tmb);
|
|
||||||
_metadata = tmb.Build();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Transaction Build()
|
|
||||||
{
|
|
||||||
if (_metadata is null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"You must call {nameof(WithMetadata)} prior to building");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Transaction.From(
|
|
||||||
_merchantName,
|
|
||||||
_description,
|
|
||||||
_amount,
|
|
||||||
_date,
|
|
||||||
_metadata
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class TransactionMetadataBuilder
|
|
||||||
{
|
|
||||||
private string _plaidId = "plaidId";
|
|
||||||
|
|
||||||
private TransactionMetadataBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TransactionMetadataBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionMetadataBuilder WithPlaidId(string plaidId)
|
|
||||||
{
|
|
||||||
_plaidId = plaidId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaidTransactionMetadata Build()
|
|
||||||
{
|
|
||||||
return PlaidTransactionMetadata.From(_plaidId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
namespace FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
internal sealed class UserBuilder
|
|
||||||
{
|
|
||||||
private string _username = "username";
|
|
||||||
private string _password = "hashedPassword";
|
|
||||||
private EncryptedDataKey _dataKey = EncryptedDataKey.From(
|
|
||||||
"keyUsed",
|
|
||||||
"encryptedKey"
|
|
||||||
);
|
|
||||||
private readonly List<Institution> _instituions = [];
|
|
||||||
|
|
||||||
private UserBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UserBuilder Create()
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserBuilder WithUsername(string username)
|
|
||||||
{
|
|
||||||
_username = username;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserBuilder WithPassword(string password)
|
|
||||||
{
|
|
||||||
_password = password;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserBuilder WithDataKey(EncryptedDataKey key)
|
|
||||||
{
|
|
||||||
_dataKey = key;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserBuilder WithInstitution(Action<InstitutionBuilder>? action = null)
|
|
||||||
{
|
|
||||||
var ib = InstitutionBuilder.Create();
|
|
||||||
action?.Invoke(ib);
|
|
||||||
_instituions.Add(ib.Build());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User Build()
|
|
||||||
{
|
|
||||||
var user = User.From(
|
|
||||||
_username,
|
|
||||||
_password,
|
|
||||||
_dataKey
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach (var institution in _instituions)
|
|
||||||
{
|
|
||||||
user.AddInstitution(institution);
|
|
||||||
|
|
||||||
foreach (var account in institution.Accounts)
|
|
||||||
{
|
|
||||||
user.AddAccount(account);
|
|
||||||
|
|
||||||
foreach (var transaction in account.Transactions)
|
|
||||||
{
|
|
||||||
user.AddTransaction(transaction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\FiscalOS.Infra\FiscalOS.Infra.csproj" />
|
<ProjectReference Include="..\..\src\FiscalOS.Infra\FiscalOS.Infra.csproj" />
|
||||||
|
<ProjectReference Include="..\FiscalOS.Tests.Common\FiscalOS.Tests.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
using FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
namespace FiscalOS.Infra.Tests.Integration;
|
namespace FiscalOS.Infra.Tests.Integration;
|
||||||
|
|
||||||
public abstract class IntegrationTest : IAsyncLifetime
|
public abstract class IntegrationTest : IAsyncLifetime
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
using FiscalOS.Infra.Tests.Data;
|
|
||||||
|
|
||||||
namespace FiscalOS.Infra.Tests.Unit;
|
namespace FiscalOS.Infra.Tests.Unit;
|
||||||
|
|
||||||
public class PlaidTransactionSyncerTests
|
public class PlaidTransactionSyncerTests
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ global using FiscalOS.Infra.Data;
|
|||||||
global using FiscalOS.Infra.Security;
|
global using FiscalOS.Infra.Security;
|
||||||
global using FiscalOS.Infra.Tests.Assertions;
|
global using FiscalOS.Infra.Tests.Assertions;
|
||||||
global using FiscalOS.Infra.Tests.Mocks;
|
global using FiscalOS.Infra.Tests.Mocks;
|
||||||
|
global using FiscalOS.Tests.Common.Data;
|
||||||
global using FiscalOS.Infra.Transactions.Plaid;
|
global using FiscalOS.Infra.Transactions.Plaid;
|
||||||
|
|
||||||
global using Going.Plaid;
|
global using Going.Plaid;
|
||||||
|
|||||||
Reference in New Issue
Block a user