Refactor. Add data layer

This commit is contained in:
rossmill76 committed 2026-03-06 11:05:01 +00:00
1 parent 3b7e4e6ec5
commit b6b794f0b4
82 files changed
+2930 -2811

No files matched your search

@@ -1,5 +1,6 @@
using BudgetApp.Data;
using BudgetApp.Services;
using BudgetApp.Data.Entities;
using BudgetApp.Data.Repositories;
using BudgetApp.Tests.Helpers;
using Microsoft.EntityFrameworkCore;
using Xunit;
@@ -32,7 +33,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetTransactionsAsync(TestDbContextFactory.TestUserId);
Assert.Equal(2, result.Count);
@@ -55,7 +56,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetTransactionsAsync(TestDbContextFactory.TestUserId);
Assert.Single(result);
@@ -85,7 +86,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetTransactionsAsync(TestDbContextFactory.TestUserId);
Assert.Single(result);
@@ -113,7 +114,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetRecentTransactionsAsync(TestDbContextFactory.TestUserId, 10);
Assert.Equal(2, result.Count);
@@ -141,7 +142,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetRecentTransactionsAsync(TestDbContextFactory.TestUserId, 3);
Assert.Equal(3, result.Count);
@@ -166,7 +167,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetUpcomingTransactionsAsync(TestDbContextFactory.TestUserId, 10);
Assert.Single(result);
@@ -197,7 +198,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetTransactionsInRangeAsync(TestDbContextFactory.TestUserId, from, to);
Assert.Equal(3, result.Count);
@@ -229,7 +230,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetTransactionsByAccountAsync(accountId, TestDbContextFactory.TestUserId);
Assert.Single(result);
@@ -250,7 +251,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
var result = await service.GetTransactionsByAccountAsync(accountId, TestDbContextFactory.OtherUserId);
Assert.Empty(result);
@@ -271,7 +272,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.CreateTransactionAsync(new Transaction
{
Description = "Groceries",
@@ -296,7 +297,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.CreateTransactionAsync(new Transaction
{
Description = "One-off",
@@ -323,7 +324,7 @@ public class TransactionServiceTests
var startDate = new DateTime(2025, 1, 1);
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.CreateTransactionAsync(new Transaction
{
Description = "Recurring",
@@ -353,7 +354,7 @@ public class TransactionServiceTests
var startDate = new DateTime(2025, 1, 1);
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.CreateTransactionAsync(new Transaction
{
Description = "Recurring",
@@ -383,7 +384,7 @@ public class TransactionServiceTests
var startDate = new DateTime(2025, 1, 1);
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.CreateTransactionAsync(new Transaction
{
Description = "Weekly",
@@ -421,7 +422,7 @@ public class TransactionServiceTests
var startDate = new DateTime(2025, 1, 15);
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.CreateTransactionAsync(new Transaction
{
Description = "Monthly",
@@ -481,7 +482,7 @@ public class TransactionServiceTests
var newDate = DateTime.Today.AddDays(5);
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.UpdateTransactionAsync(
transactionId, TestDbContextFactory.TestUserId,
"Updated", 99m, newDate, TransactionType.Income,
@@ -520,7 +521,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.UpdateTransactionAsync(
transactionId, TestDbContextFactory.OtherUserId,
"Hacked", 999m, DateTime.Today, TransactionType.Income, 1, null);
@@ -548,7 +549,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.DeleteTransactionAsync(transactionId, TestDbContextFactory.TestUserId);
using var verifyCtx = factory.CreateContext();
@@ -570,7 +571,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.DeleteTransactionAsync(transactionId, TestDbContextFactory.OtherUserId);
using var verifyCtx = factory.CreateContext();
@@ -623,7 +624,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.DeleteTransactionSeriesAsync(childId, TestDbContextFactory.TestUserId);
using var verifyCtx = factory.CreateContext();
@@ -672,7 +673,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.DeleteTransactionSeriesAsync(childId, TestDbContextFactory.TestUserId);
using var verifyCtx = factory.CreateContext();
@@ -709,7 +710,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.DeleteTransactionSeriesAsync(parentId, TestDbContextFactory.TestUserId);
using var verifyCtx = factory.CreateContext();
@@ -731,7 +732,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.DeleteTransactionSeriesAsync(transactionId, TestDbContextFactory.OtherUserId);
using var verifyCtx = factory.CreateContext();
@@ -772,7 +773,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.MaterializeRecurringTransactionsAsync(TestDbContextFactory.TestUserId, startDate.AddDays(100));
using var verifyCtx = factory.CreateContext();
@@ -808,7 +809,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.MaterializeRecurringTransactionsAsync(TestDbContextFactory.TestUserId, startDate.AddDays(365));
using var verifyCtx = factory.CreateContext();
@@ -839,7 +840,7 @@ public class TransactionServiceTests
}
using var context = factory.CreateContext();
var service = new TransactionService(context);
var service = new TransactionRepository(context);
await service.MaterializeRecurringTransactionsAsync(TestDbContextFactory.TestUserId);
using var verifyCtx = factory.CreateContext();
@@ -860,7 +861,7 @@ public class TransactionServiceTests
var current = new DateTime(2025, 6, 15);
var expected = current.AddDays(expectedDays).AddMonths(expectedMonths).AddYears(expectedYears);
var result = TransactionService.GetNextOccurrence(current, type);
var result = TransactionRepository.GetNextOccurrence(current, type);
Assert.Equal(expected, result);
}
@@ -868,7 +869,7 @@ public class TransactionServiceTests
[Fact]
public void GetNextOccurrence_None_ReturnsMaxValue()
{
var result = TransactionService.GetNextOccurrence(DateTime.Today, RecurrenceType.None);
var result = TransactionRepository.GetNextOccurrence(DateTime.Today, RecurrenceType.None);
Assert.Equal(DateTime.MaxValue, result);
}