aboutsummaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-12-21 19:36:18 +0800
committercrupest <crupest@outlook.com>2022-12-21 19:36:18 +0800
commitb022122b0a697f063433d5fe525e536bd23e8372 (patch)
tree4a71b079867ab3b6a86035637bcefaba8b660c87 /docker
parentfb91ec33aea40c41900fee6bc2da769ff461ce38 (diff)
downloadcrupest-b022122b0a697f063433d5fe525e536bd23e8372.tar.gz
crupest-b022122b0a697f063433d5fe525e536bd23e8372.tar.bz2
crupest-b022122b0a697f063433d5fe525e536bd23e8372.zip
Develop secret api. v57
Diffstat (limited to 'docker')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs18
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs2
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/DatabaseHelper.cs13
3 files changed, 19 insertions, 14 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
index 762e3a8..a515d2f 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/CrudServiceTest.cs
@@ -44,6 +44,24 @@ public class CrudServiceTest
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);
}
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
index eab8567..dc32387 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
@@ -108,7 +108,7 @@ public class CrudService<TEntity> : IDisposable where TEntity : class
return result;
}
- public void UpdateByKey(object key, TEntity entity, UpdateBehavior behavior)
+ public void UpdateByKey(object key, TEntity entity, UpdateBehavior behavior = UpdateBehavior.None)
{
var affectedCount = _table.Update(_dbConnection, WhereClause.Create().Eq(_table.KeyColumn.ColumnName, key),
ConvertEntityToUpdateClauses(entity, behavior));
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/DatabaseHelper.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/DatabaseHelper.cs
deleted file mode 100644
index 9eb6a08..0000000
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/DatabaseHelper.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace CrupestApi.Commons;
-
-
-public static class DatabaseHelper
-{
- public static string GenerateUpdateColumnString(this IEnumerable<string> updateColumnList, IEnumerable<KeyValuePair<string, string>>? paramNameMap = null)
- {
- paramNameMap = paramNameMap ?? Enumerable.Empty<KeyValuePair<string, string>>();
- var paramNameDictionary = new Dictionary<string, string>(paramNameMap);
-
- return string.Join(", ", updateColumnList.Select(x => $"{x} = @{paramNameDictionary.GetValueOrDefault(x) ?? x}"));
- }
-} \ No newline at end of file