diff options
author | crupest <crupest@outlook.com> | 2024-11-11 01:12:29 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2024-12-19 21:42:01 +0800 |
commit | a7fb0508867ee53934be18a6606aa8bc12c2645b (patch) | |
tree | 5994f0a62733b13f9f330e3515260ae20dc4a0bd /docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs | |
parent | 7692763f83ad1be735b0b9e9ab0af8ce666d8de8 (diff) | |
download | crupest-a7fb0508867ee53934be18a6606aa8bc12c2645b.tar.gz crupest-a7fb0508867ee53934be18a6606aa8bc12c2645b.tar.bz2 crupest-a7fb0508867ee53934be18a6606aa8bc12c2645b.zip |
HALF WORK: 2024.12.19
Re-organize file structure.
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs deleted file mode 100644 index ad0d34c..0000000 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs +++ /dev/null @@ -1,77 +0,0 @@ -using CrupestApi.Commons.Crud.Migrations; -using Microsoft.Extensions.Logging.Abstractions; - -namespace CrupestApi.Commons.Crud.Tests; - -public class CrudServiceTest -{ - private readonly SqliteMemoryConnectionFactory _memoryConnectionFactory = new SqliteMemoryConnectionFactory(); - - private readonly CrudService<TestEntity> _crudService; - - public CrudServiceTest() - { - var columnTypeProvider = new ColumnTypeProvider(); - var tableInfoFactory = new TableInfoFactory(columnTypeProvider, NullLoggerFactory.Instance); - var dbConnectionFactory = new SqliteMemoryConnectionFactory(); - - _crudService = new CrudService<TestEntity>( - tableInfoFactory, dbConnectionFactory, new SqliteDatabaseMigrator(), NullLoggerFactory.Instance); - } - - [Fact] - public void CrudTest() - { - var key = _crudService.Create(new TestEntity() - { - Name = "crupest", - Age = 18, - }); - - Assert.Equal("crupest", key); - - var entity = _crudService.GetByKey(key); - Assert.Equal("crupest", entity.Name); - Assert.Equal(18, entity.Age); - Assert.Null(entity.Height); - Assert.NotEmpty(entity.Secret); - - var list = _crudService.GetAll(); - entity = Assert.Single(list); - Assert.Equal("crupest", entity.Name); - Assert.Equal(18, entity.Age); - Assert.Null(entity.Height); - Assert.NotEmpty(entity.Secret); - - var count = _crudService.GetCount(); - Assert.Equal(1, count); - - _crudService.UpdateByKey(key, new TestEntity() - { - Name = "crupest2.0", - Age = 22, - Height = 180, - }); - - entity = _crudService.GetByKey("crupest2.0"); - Assert.Equal("crupest2.0", entity.Name); - Assert.Equal(22, entity.Age); - Assert.Equal(180, entity.Height); - Assert.NotEmpty(entity.Secret); - - _crudService.DeleteByKey("crupest2.0"); - - count = _crudService.GetCount(); - Assert.Equal(0, count); - } - - [Fact] - public void EntityNotExistTest() - { - Assert.Throws<EntityNotExistException>(() => _crudService.GetByKey("KeyNotExist")); - Assert.Throws<EntityNotExistException>(() => _crudService.UpdateByKey("KeyNotExist", new TestEntity - { - Name = "crupest" - })); - } -} |