Skip to content

Commit

Permalink
Rework Unit Tests and Code cleanup after dropping Sqlite support #239 #…
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAxelander committed Sep 3, 2024
1 parent 90df11e commit 4e793f6
Show file tree
Hide file tree
Showing 109 changed files with 6,547 additions and 2,769 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/docker-image-pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ jobs:
test:
runs-on: ubuntu-latest
name: Run Test Cases

services:
mariadb:
image: mariadb:latest
ports:
- 3306:3306
env:
MYSQL_DATABASE: openbudgeteer_test
MYSQL_USER: openbudgeteer_test
MYSQL_PASSWORD: openbudgeteer_test

steps:
- name: Check out repo
uses: actions/checkout@v3
Expand All @@ -27,6 +38,12 @@ jobs:
run: dotnet build OpenBudgeteer.Blazor --configuration Release --no-restore

- name: Run Core Test Cases
env:
CONNECTION_SERVER: localhost
CONNECTION_PORT: 3306
CONNECTION_USER: openbudgeteer_test
CONNECTION_PASSWORD: openbudgeteer_test
CONNECTION_DATABASE: openbudgeteer_test
run: dotnet test OpenBudgeteer.Core.Test
deploy-docker-app:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Migrated reports from ChartJs.Blazor to Blazor-ApexCharts
* Bucket Movements will be now stored with the current date instead on first of the month [#240](https://github.com/TheAxelander/OpenBudgeteer/issues/240) Thanks [Lucaber](https://github.com/Lucaber)

### :hammer: Maintenance

* Rework Unit Tests and Code cleanup after dropping Sqlite support [#239](https://github.com/TheAxelander/OpenBudgeteer/issues/239) [#246](https://github.com/TheAxelander/OpenBudgeteer/issues/246)

## 1.8.3 (2024-05-20)

### :warning: Breaking Changes
Expand Down
7 changes: 4 additions & 3 deletions OpenBudgeteer.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using OpenBudgeteer.Core.Data.Entities;
using OpenBudgeteer.Core.Data.Entities.Models;
using OpenBudgeteer.Core.Data.Services;
using OpenBudgeteer.Core.Data.Services.EFCore;
using Swashbuckle.AspNetCore.SwaggerGen;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -30,8 +31,8 @@
options.GroupNameFormat = "'v'VVV";
});
builder.Services.AddDatabase(builder.Configuration);
builder.Services.AddScoped<IServiceManager, ServiceManager>(x =>
new ServiceManager(x.GetRequiredService<DbContextOptions<DatabaseContext>>()));
builder.Services.AddScoped<IServiceManager, EFCoreServiceManager>(x =>
new EFCoreServiceManager(x.GetRequiredService<DbContextOptions<DatabaseContext>>()));

var app = builder.Build();

Expand All @@ -41,7 +42,7 @@
// "api-supported-versions" and "api-deprecated-versions"
.ReportApiVersions()
.Build();
var serviceManager = new ServiceManager(app.Services.GetRequiredService<DbContextOptions<DatabaseContext>>());
var serviceManager = new EFCoreServiceManager(app.Services.GetRequiredService<DbContextOptions<DatabaseContext>>());

#region AccountService

Expand Down
2 changes: 0 additions & 2 deletions OpenBudgeteer.Blazor/OpenBudgeteer.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="3.3.2.23201" />
Expand All @@ -25,7 +24,6 @@
<ProjectReference Include="..\OpenBudgeteer.Core\OpenBudgeteer.Core.csproj" />
<ProjectReference Include="..\OpenBudgeteer.Core.Data.MySql.Migrations\OpenBudgeteer.Core.Data.MySql.Migrations.csproj" />
<ProjectReference Include="..\OpenBudgeteer.Core.Data.Postgres.Migrations\OpenBudgeteer.Core.Data.Postgres.Migrations.csproj" />
<ProjectReference Include="..\OpenBudgeteer.Core.Data.Sqlite.Migrations\OpenBudgeteer.Core.Data.Sqlite.Migrations.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion OpenBudgeteer.Blazor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using OpenBudgeteer.Core.Data.Contracts.Services;
using OpenBudgeteer.Core.Data.Entities;
using OpenBudgeteer.Core.Data.Services;
using OpenBudgeteer.Core.Data.Services.EFCore;
using OpenBudgeteer.Core.ViewModels.Helper;
using Tewr.Blazor.FileReader;

Expand All @@ -27,7 +28,7 @@
builder.Services.AddFileReaderService();
builder.Services.AddHostedService<HostedDatabaseMigrator>();
builder.Services.AddDatabase(builder.Configuration);
builder.Services.AddScoped<IServiceManager, ServiceManager>(x => new ServiceManager(x.GetRequiredService<DbContextOptions<DatabaseContext>>()));
builder.Services.AddScoped<IServiceManager, EFCoreServiceManager>(x => new EFCoreServiceManager(x.GetRequiredService<DbContextOptions<DatabaseContext>>()));
builder.Services.AddScoped(x => new YearMonthSelectorViewModel(x.GetRequiredService<IServiceManager>()));

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Required to read ANSI Text files
Expand Down
1 change: 0 additions & 1 deletion OpenBudgeteer.Blazor/Shared/BucketSelectDialog.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@using OpenBudgeteer.Core.ViewModels
@using System.Drawing
@using System.Globalization
@using OpenBudgeteer.Core.Data
@using OpenBudgeteer.Core.Data.Entities.Models
@using OpenBudgeteer.Core.ViewModels.EntityViewModels
@using OpenBudgeteer.Core.ViewModels.Helper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace OpenBudgeteer.Core.Data.Contracts.Repositories;

public interface IBaseRepository<T> where T : IEntity
{
IQueryable<T> All();
IQueryable<T> AllWithIncludedEntities();
IEnumerable<T> All();
IEnumerable<T> AllWithIncludedEntities();
T? ById(Guid id);
T? ByIdWithIncludedEntities(Guid id);
int Create(T entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ namespace OpenBudgeteer.Core.Data.Contracts.Repositories;

public interface IBucketRepository : IBaseRepository<Bucket>
{

public Bucket? ByIdWithVersions(Guid id);
public Bucket? ByIdWithMovements(Guid id);
public Bucket? ByIdWithTransactions(Guid id);
public IEnumerable<Bucket> AllWithVersions();
public IEnumerable<Bucket> AllWithActivities();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace OpenBudgeteer.Core.Data.Contracts.Repositories;

public interface IBudgetedTransactionRepository : IBaseRepository<BudgetedTransaction>
{

public IEnumerable<BudgetedTransaction> AllWithTransactions();
public BudgetedTransaction? ByIdWithTransaction(Guid id);
}
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/AccountRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public AccountRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<Account> All() => DatabaseContext.Account
public IEnumerable<Account> All() => DatabaseContext.Account
.AsNoTracking();

public IQueryable<Account> AllWithIncludedEntities() => DatabaseContext.Account
public IEnumerable<Account> AllWithIncludedEntities() => DatabaseContext.Account
.AsNoTracking();

public Account? ById(Guid id) => DatabaseContext.Account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public BankTransactionRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<BankTransaction> All() => DatabaseContext.BankTransaction
public IEnumerable<BankTransaction> All() => DatabaseContext.BankTransaction
.AsNoTracking();

public IQueryable<BankTransaction> AllWithIncludedEntities() => DatabaseContext.BankTransaction
public IEnumerable<BankTransaction> AllWithIncludedEntities() => DatabaseContext.BankTransaction
.Include(i => i.Account)
.AsNoTracking();

Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/BucketGroupRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public BucketGroupRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<BucketGroup> All() => DatabaseContext.BucketGroup
public IEnumerable<BucketGroup> All() => DatabaseContext.BucketGroup
.AsNoTracking();

public IQueryable<BucketGroup> AllWithIncludedEntities() => DatabaseContext.BucketGroup
public IEnumerable<BucketGroup> AllWithIncludedEntities() => DatabaseContext.BucketGroup
.Include(i => i.Buckets)
.AsNoTracking();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public BucketMovementRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<BucketMovement> All() => DatabaseContext.BucketMovement
public IEnumerable<BucketMovement> All() => DatabaseContext.BucketMovement
.AsNoTracking();

public IQueryable<BucketMovement> AllWithIncludedEntities() => DatabaseContext.BucketMovement
public IEnumerable<BucketMovement> AllWithIncludedEntities() => DatabaseContext.BucketMovement
.Include(i => i.Bucket)
.AsNoTracking();

Expand Down
8 changes: 4 additions & 4 deletions OpenBudgeteer.Core.Data.Repository/BucketRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public BucketRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<Bucket> All() => DatabaseContext.Bucket
public IEnumerable<Bucket> All() => DatabaseContext.Bucket
.AsNoTracking();

public IQueryable<Bucket> AllWithVersions() => DatabaseContext.Bucket
public IEnumerable<Bucket> AllWithVersions() => DatabaseContext.Bucket
.Include(i => i.BucketVersions)
.AsNoTracking();

public IQueryable<Bucket> AllWithActivities() => DatabaseContext.Bucket
public IEnumerable<Bucket> AllWithActivities() => DatabaseContext.Bucket
.Include(i => i.BucketMovements)
.Include(i => i.BudgetedTransactions)!.ThenInclude(i => i.Transaction)
.AsNoTracking();

public IQueryable<Bucket> AllWithIncludedEntities() => DatabaseContext.Bucket
public IEnumerable<Bucket> AllWithIncludedEntities() => DatabaseContext.Bucket
.Include(i => i.BucketGroup)
.Include(i => i.BucketMovements)
.Include(i => i.BucketVersions)
Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/BucketRuleSetRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public BucketRuleSetRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<BucketRuleSet> All() => DatabaseContext.BucketRuleSet
public IEnumerable<BucketRuleSet> All() => DatabaseContext.BucketRuleSet
.AsNoTracking();

public IQueryable<BucketRuleSet> AllWithIncludedEntities() => DatabaseContext.BucketRuleSet
public IEnumerable<BucketRuleSet> AllWithIncludedEntities() => DatabaseContext.BucketRuleSet
.Include(i => i.TargetBucket)
.Include(i => i.MappingRules)
.AsNoTracking();
Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/BucketVersionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public BucketVersionRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<BucketVersion> All() => DatabaseContext.BucketVersion
public IEnumerable<BucketVersion> All() => DatabaseContext.BucketVersion
.AsNoTracking();

public IQueryable<BucketVersion> AllWithIncludedEntities() => DatabaseContext.BucketVersion
public IEnumerable<BucketVersion> AllWithIncludedEntities() => DatabaseContext.BucketVersion
.Include(i => i.Bucket)
.AsNoTracking();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public BudgetedTransactionRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<BudgetedTransaction> All() => DatabaseContext.BudgetedTransaction
public IEnumerable<BudgetedTransaction> All() => DatabaseContext.BudgetedTransaction
.AsNoTracking();

public IQueryable<BudgetedTransaction> AllWithIncludedEntities() => DatabaseContext.BudgetedTransaction
public IEnumerable<BudgetedTransaction> AllWithIncludedEntities() => DatabaseContext.BudgetedTransaction
.Include(i => i.Bucket)
.Include(i => i.Transaction)
.AsNoTracking();

public IQueryable<BudgetedTransaction> AllWithTransactions() => DatabaseContext.BudgetedTransaction
public IEnumerable<BudgetedTransaction> AllWithTransactions() => DatabaseContext.BudgetedTransaction
.Include(i => i.Transaction)
.Include(i => i.Transaction.Account)
.AsNoTracking();
Expand Down Expand Up @@ -55,14 +55,18 @@ public int CreateRange(IEnumerable<BudgetedTransaction> entities)

public int Update(BudgetedTransaction entity)
{
DatabaseContext.BudgetedTransaction.Update(entity);
return DatabaseContext.SaveChanges();
// DatabaseContext.BudgetedTransaction.Update(entity);
// return DatabaseContext.SaveChanges();
throw new NotSupportedException(
$"{typeof(BudgetedTransaction)} should not be updated, instead delete and re-create");
}

public int UpdateRange(IEnumerable<BudgetedTransaction> entities)
{
DatabaseContext.BudgetedTransaction.UpdateRange(entities);
return DatabaseContext.SaveChanges();
// DatabaseContext.BudgetedTransaction.UpdateRange(entities);
// return DatabaseContext.SaveChanges();
throw new NotSupportedException(
$"{typeof(BudgetedTransaction)} should not be updated, instead delete and re-create");
}

public int Delete(Guid id)
Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/ImportProfileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public ImportProfileRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<ImportProfile> All() => DatabaseContext.ImportProfile
public IEnumerable<ImportProfile> All() => DatabaseContext.ImportProfile
.AsNoTracking();

public IQueryable<ImportProfile> AllWithIncludedEntities() => DatabaseContext.ImportProfile
public IEnumerable<ImportProfile> AllWithIncludedEntities() => DatabaseContext.ImportProfile
.Include(i => i.Account)
.AsNoTracking();

Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.Core.Data.Repository/MappingRuleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public MappingRuleRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<MappingRule> All() => DatabaseContext.MappingRule
public IEnumerable<MappingRule> All() => DatabaseContext.MappingRule
.AsNoTracking();

public IQueryable<MappingRule> AllWithIncludedEntities() => DatabaseContext.MappingRule
public IEnumerable<MappingRule> AllWithIncludedEntities() => DatabaseContext.MappingRule
.Include(i => i.BucketRuleSet)
.AsNoTracking();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public RecurringBankTransactionRepository(DatabaseContext databaseContext)
DatabaseContext = databaseContext;
}

public IQueryable<RecurringBankTransaction> All() => DatabaseContext.RecurringBankTransaction
public IEnumerable<RecurringBankTransaction> All() => DatabaseContext.RecurringBankTransaction
.AsNoTracking();

public IQueryable<RecurringBankTransaction> AllWithIncludedEntities() => DatabaseContext.RecurringBankTransaction
public IEnumerable<RecurringBankTransaction> AllWithIncludedEntities() => DatabaseContext.RecurringBankTransaction
.Include(i => i.Account)
.AsNoTracking();

Expand Down
Loading

0 comments on commit 4e793f6

Please sign in to comment.