-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from MrDave1999/test/sqlite-integration-tests
test: Add integration tests for repositories using SQLite
- Loading branch information
Showing
10 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
BEGIN TRANSACTION; | ||
CREATE TABLE IF NOT EXISTS "players" ( | ||
"id" INTEGER, | ||
"name" TEXT NOT NULL UNIQUE COLLATE NOCASE, | ||
"password" TEXT NOT NULL, | ||
"total_kills" INTEGER NOT NULL, | ||
"total_deaths" INTEGER NOT NULL, | ||
"max_killing_spree" INTEGER NOT NULL, | ||
"brought_flags" INTEGER NOT NULL, | ||
"captured_flags" INTEGER NOT NULL, | ||
"dropped_flags" INTEGER NOT NULL, | ||
"returned_flags" INTEGER NOT NULL, | ||
"head_shots" INTEGER NOT NULL, | ||
"role_id" INTEGER NOT NULL, | ||
"skin_id" INTEGER NOT NULL, | ||
"rank_id" INTEGER NOT NULL, | ||
"created_at" TEXT NOT NULL, | ||
"last_connection" TEXT NOT NULL, | ||
PRIMARY KEY("id") | ||
); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- name: InitializeSeedData | ||
DELETE FROM players; | ||
INSERT INTO players | ||
( | ||
name, | ||
password, | ||
total_kills, | ||
total_deaths, | ||
max_killing_spree, | ||
brought_flags, | ||
captured_flags, | ||
dropped_flags, | ||
returned_flags, | ||
head_shots, | ||
role_id, | ||
skin_id, | ||
rank_id, | ||
created_at, | ||
last_connection | ||
) | ||
VALUES | ||
('Admin_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,3,146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'), | ||
('Moderator_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,2,146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'), | ||
('VIP_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,1,146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'), | ||
('Basic_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,0,146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Tests/Common/InMemoryRepositoryManager.cs → ...aseProviders/InMemoryRepositoryManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....Tests/Common/MariaDbRepositoryManager.cs → ...baseProviders/MariaDbRepositoryManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/Persistence.Tests/Common/DatabaseProviders/SqliteRepositoryManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace Persistence.Tests.Common.DatabaseProviders; | ||
|
||
public class SqliteRepositoryManager : IRepositoryManager | ||
{ | ||
private readonly ServiceProvider _serviceProvider; | ||
public IPlayerRepository PlayerRepository { get; } | ||
public SqliteRepositoryManager() | ||
{ | ||
var services = new ServiceCollection(); | ||
IConfiguration configuration = EnvConfigurationBuilder.Instance; | ||
services.AddSingleton<IPasswordHasher, FakePasswordHasher>(); | ||
services.AddPersistenceSQLiteServices(configuration); | ||
_serviceProvider = services.BuildServiceProvider(); | ||
PlayerRepository = _serviceProvider.GetRequiredService<IPlayerRepository>(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_serviceProvider.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
public void InitializeSeedData() | ||
{ | ||
var settings = _serviceProvider.GetRequiredService<SQLiteSettings>(); | ||
var sqlCollection = _serviceProvider.GetRequiredService<ISqlCollection>(); | ||
using var connection = new SqliteConnection(settings.ConnectionString); | ||
connection.Open(); | ||
SqliteCommand command = connection.CreateCommand(); | ||
command.CommandText = sqlCollection["InitializeSeedData"]; | ||
command.ExecuteNonQuery(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters