Skip to content

Commit cf98794

Browse files
improved IDynamicSQLRepository and implementations + Unit tests
1 parent a2ab054 commit cf98794

File tree

8 files changed

+454
-32
lines changed

8 files changed

+454
-32
lines changed

Arian.Querium.SQLite.Tests/QueryBuilders/DeleteQueryBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void ShouldBuild_DeleteQueryWithMixedAndOrConditions()
105105
public void ShouldThrow_WhenTableNameIsNotSpecified()
106106
{
107107
// Arrange
108-
SqliteDeleteQueryBuilder builder = new SqliteDeleteQueryBuilder();
108+
SqliteDeleteQueryBuilder builder = new();
109109

110110
// Act & Assert
111111
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => builder.Sql);

Arian.Querium.SQLite.Tests/Repositories/SqliteDynamicRepositoryTests.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using Arian.Querium.SQL.QueryBuilders;
2-
using Arian.Querium.SQL.Repositories;
32
using Arian.Querium.SQLite.Implementations.QueryBuilders;
43
using Arian.Querium.SQLite.Implementations.Repositories;
54
using Microsoft.Data.Sqlite;
65
using SQLitePCL;
7-
using System.Data;
86

97
namespace Arian.Querium.SQLite.Tests.Repositories;
108

@@ -51,21 +49,21 @@ public void Dispose()
5149
public class SqliteDynamicRepositoryTests : IAsyncLifetime
5250
{
5351
private readonly DatabaseFixture _fixture;
54-
private readonly SqliteDynamicRepository _repository;
52+
private readonly SQliteDynamicRepository _repository;
5553
private const string TestTableName = "users";
5654

5755
public SqliteDynamicRepositoryTests(DatabaseFixture fixture)
5856
{
5957
_fixture = fixture;
60-
_repository = new SqliteDynamicRepository(_fixture.ConnectionString, _fixture.QueryBuilderFactory);
58+
_repository = new SQliteDynamicRepository(_fixture.ConnectionString, _fixture.QueryBuilderFactory);
6159
}
6260

6361
/// <summary>
6462
/// Creates a test table before each test method runs.
6563
/// </summary>
6664
public async Task InitializeAsync()
6765
{
68-
var columns = new Dictionary<string, ColumnType>
66+
Dictionary<string, ColumnType> columns = new()
6967
{
7068
{ "Id", ColumnType.Integer },
7169
{ "Name", ColumnType.Text },
@@ -87,7 +85,7 @@ public async Task DisposeAsync()
8785
public async Task ShouldAdd_AndRetrieve_A_New_Row()
8886
{
8987
// Arrange
90-
var newUserData = new Dictionary<string, object>
88+
Dictionary<string, object> newUserData = new()
9189
{
9290
{ "Name", "John Doe" },
9391
{ "Age", 30 },
@@ -136,7 +134,7 @@ public async Task ShouldUpdate_An_Existing_Row()
136134
Assert.NotEmpty(allUsers);
137135
long idToUpdate = (long)allUsers.First()["Id"];
138136

139-
var updatedData = new Dictionary<string, object>
137+
Dictionary<string, object> updatedData = new()
140138
{
141139
{ "Name", "New Name" },
142140
{ "Age", 35 }
@@ -180,7 +178,7 @@ public async Task ShouldCreate_A_Table_Successfully()
180178
// Arrange is handled by InitializeAsync, which creates the "users" table.
181179
// We will test creating a new, different table here.
182180
const string newTableName = "products";
183-
var columns = new Dictionary<string, ColumnType>
181+
Dictionary<string, ColumnType> columns = new()
184182
{
185183
{ "Id", ColumnType.Integer },
186184
{ "ProductName", ColumnType.Text },
@@ -191,7 +189,7 @@ public async Task ShouldCreate_A_Table_Successfully()
191189
await _repository.AddAsync(newTableName, new Dictionary<string, object> { { "ProductName", "Laptop" } });
192190

193191
// Assert
194-
var products = await _repository.GetAllAsync(newTableName);
192+
IEnumerable<Dictionary<string, object>> products = await _repository.GetAllAsync(newTableName);
195193
Assert.Single(products);
196194

197195
// Clean up the new table manually, since DisposeAsync only cleans the main one.
@@ -209,7 +207,7 @@ public async Task ShouldRename_A_Table_Successfully()
209207
await _repository.RenameTableAsync(TestTableName, newTableName);
210208

211209
// Assert
212-
var renamedUsers = await _repository.GetAllAsync(newTableName);
210+
IEnumerable<Dictionary<string, object>> renamedUsers = await _repository.GetAllAsync(newTableName);
213211
Assert.Single(renamedUsers);
214212

215213
// We cannot use the old table name anymore.
@@ -249,7 +247,7 @@ public async Task ShouldReturn_Null_When_GetById_DoesNotExist()
249247
public async Task ShouldNotUpdate_A_NonExistent_Row()
250248
{
251249
// Arrange
252-
var updatedData = new Dictionary<string, object> { { "Name", "Updated Name" } };
250+
Dictionary<string, object> updatedData = new() { { "Name", "Updated Name" } };
253251

254252
// Act
255253
await _repository.UpdateAsync(TestTableName, updatedData, "Id", 999);

0 commit comments

Comments
 (0)