aboutsummaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-12-10 11:35:49 +0800
committercrupest <crupest@outlook.com>2022-12-20 20:32:53 +0800
commitddce7fb5891d97eb66960687fe1fea4cb0bd7c94 (patch)
treeee9543893288d456910284f889473341f8bc8c0b /docker
parent7fd38e35fdc5248502008903cf7608d9b799fd7f (diff)
downloadcrupest-ddce7fb5891d97eb66960687fe1fea4cb0bd7c94.tar.gz
crupest-ddce7fb5891d97eb66960687fe1fea4cb0bd7c94.tar.bz2
crupest-ddce7fb5891d97eb66960687fe1fea4cb0bd7c94.zip
Develop secret api. v23
Diffstat (limited to 'docker')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/ColumnTypeInfoTest.cs26
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/SqlCompareHelper.cs14
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/TableInfoTest.cs1
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs5
4 files changed, 40 insertions, 6 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/ColumnTypeInfoTest.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/ColumnTypeInfoTest.cs
new file mode 100644
index 0000000..56ae06f
--- /dev/null
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/ColumnTypeInfoTest.cs
@@ -0,0 +1,26 @@
+using System.Data;
+
+namespace CrupestApi.Commons.Crud.Tests;
+
+public class ColumnTypeInfoTest
+{
+ private ColumnTypeProvider _provider = new ColumnTypeProvider();
+
+ [Theory]
+ [InlineData(typeof(int), DbType.Int32, 123)]
+ [InlineData(typeof(long), DbType.Int64, 456)]
+ [InlineData(typeof(sbyte), DbType.SByte, 789)]
+ [InlineData(typeof(short), DbType.Int16, 101)]
+ [InlineData(typeof(float), DbType.Single, 1.0f)]
+ [InlineData(typeof(double), DbType.Double, 1.0)]
+ [InlineData(typeof(string), DbType.String, "Hello world!")]
+ [InlineData(typeof(byte[]), DbType.Binary, new byte[] { 1, 2, 3 })]
+ public void BasicColumnTypeTest(Type type, DbType dbType, object? value)
+ {
+ var typeInfo = _provider.Get(type);
+ Assert.True(typeInfo.IsSimple);
+ Assert.Equal(dbType, typeInfo.DbType);
+ Assert.Equal(value, typeInfo.ConvertFromDatabase(value));
+ Assert.Equal(value, typeInfo.ConvertToDatabase(value));
+ }
+}
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/SqlCompareHelper.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/SqlCompareHelper.cs
index 8f3e5c6..c019e19 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/SqlCompareHelper.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/SqlCompareHelper.cs
@@ -44,9 +44,11 @@ public class SqlCompareHelper
}
else
{
- wordBuilder = new StringBuilder(sql[current]);
+ wordBuilder = new StringBuilder();
+ wordBuilder.Append(sql[current]);
}
}
+ current++;
}
if (wordBuilder is not null)
@@ -54,6 +56,14 @@ public class SqlCompareHelper
result.Add(wordBuilder.ToString());
}
+ if (toLower)
+ {
+ for (int i = 0; i < result.Count; i++)
+ {
+ result[i] = result[i].ToLower();
+ }
+ }
+
return result;
}
@@ -68,6 +78,6 @@ public class SqlCompareHelper
var sql = "SELECT * FROM TableName WHERE id = @abcd;";
var words = SqlExtractWords(sql);
- Assert.Equal(words, new List<string> { "select", "*", "from", "tablename", "where", "id", "=", "@abcd", ";" });
+ Assert.Equal(new List<string> { "select", "*", "from", "tablename", "where", "id", "=", "@abcd", ";" }, words);
}
}
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/TableInfoTest.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/TableInfoTest.cs
new file mode 100644
index 0000000..d82c70f
--- /dev/null
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons.Tests/Crud/TableInfoTest.cs
@@ -0,0 +1 @@
+namespace CrupestApi.Commons.Crud.Tests;
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
index 3017176..4f5862f 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Json.cs
@@ -29,11 +29,10 @@ public static class CrupestApiJsonExtensions
}
else
{
- throw new Exception("Only value not array or object is allowed.")
+ throw new Exception("Only value not array or object is allowed.");
}
}
-
public static IServiceCollection AddJsonOptions(this IServiceCollection services)
{
services.AddOptions<JsonSerializerOptions>();
@@ -44,8 +43,6 @@ public static class CrupestApiJsonExtensions
config.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
- // TODO: Register column type provided converters.
-
return services;
}