增加模型化存储过程调用测试工程
This commit is contained in:
parent
346a8380be
commit
8f0d39981f
19
Falcon.ModelSP.Test/Falcon.ModelSP.Test.csproj
Normal file
19
Falcon.ModelSP.Test/Falcon.ModelSP.Test.csproj
Normal file
|
@ -0,0 +1,19 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Falcon.ModelSP\Falcon.ModelSP.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
47
Falcon.ModelSP.Test/ModelSPTest.cs
Normal file
47
Falcon.ModelSP.Test/ModelSPTest.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Falcon.ModelSP;
|
||||
using System.Linq;
|
||||
|
||||
namespace Falcon.ModelSP.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class ModelSPTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void getParamsTest() {
|
||||
var model = new ParmModel { Id = 1,Name = "n1",AAAge = 10 };
|
||||
|
||||
var data = DataExtend.getParams(model);
|
||||
Assert.IsNotNull(data);
|
||||
Assert.IsTrue(data.Count() == typeof(ParmModel).GetProperties().Length - 1);
|
||||
|
||||
Assert.IsTrue(data.Any(m => m.ParameterName == "@Id" && m.Value.Equals(1)));
|
||||
Assert.IsTrue(data.Any(m => m.ParameterName == "@Name" && m.Value.Equals("n1")));
|
||||
Assert.IsTrue(data.Any(m => m.ParameterName == "@age" && m.Value.Equals(10)));
|
||||
Assert.IsTrue(!data.Any(m => m.ParameterName == "@Address"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void getProcuderNameTest() {
|
||||
var model = new ParmModel { };
|
||||
Assert.IsTrue(DataExtend.getProcuderName<ParmModel>() == "ParmModel");
|
||||
Assert.IsTrue(DataExtend.getProcuderName<ParmModel1>() == "sp123");
|
||||
}
|
||||
|
||||
class ParmModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
[FalconSPPrarmName("age")]
|
||||
public int AAAge { get; set; }
|
||||
|
||||
[FalconSPIgnore]
|
||||
public string Address { get; set; }
|
||||
}
|
||||
|
||||
[FalconSPProcuderName("sp123")]
|
||||
class ParmModel1 { }
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ namespace Falcon.ModelSP
|
|||
/// </summary>
|
||||
/// <typeparam name="T">参数模型类型</typeparam>
|
||||
/// <param name="data">参数实例</param>
|
||||
private static IEnumerable<SqlParameter> getParams<T>(T data) {
|
||||
public static IEnumerable<SqlParameter> getParams<T>(T data) {
|
||||
if(data == null)
|
||||
yield break;
|
||||
foreach(var p in typeof(T).GetProperties()) {
|
||||
|
@ -75,7 +75,7 @@ namespace Falcon.ModelSP
|
|||
/// 获取存储过程名
|
||||
/// </summary>
|
||||
/// <typeparam name="T">参数模型</typeparam>
|
||||
private static string getProcuderName<T>() {
|
||||
public static string getProcuderName<T>() {
|
||||
var attr = typeof(T).GetCustomAttribute<FalconSPProcuderNameAttribute>(true);
|
||||
if(attr != null && attr is FalconSPProcuderNameAttribute pna && !string.IsNullOrEmpty(pna.ProcuderName)) {
|
||||
return pna.ProcuderName;
|
|
@ -15,9 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Falcon.Packget.Test", "Falc
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Falcon.ModelSP", "Falcon.ModelSP\Falcon.ModelSP.csproj", "{D31D628F-60F5-4F98-8280-2D312B0A99F1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Falcon.AutoTableLog", "Falcon.AutoTableLog\Falcon.AutoTableLog.csproj", "{61C50690-4419-4F6D-B34D-4258565185E9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Falcon.AutoTableLog", "Falcon.AutoTableLog\Falcon.AutoTableLog.csproj", "{61C50690-4419-4F6D-B34D-4258565185E9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Falcon.AutoTableLog.Test", "Falcon.AutoTableLog.Test\Falcon.AutoTableLog.Test.csproj", "{D60683D5-D6F6-41EE-9627-43C34C977C45}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Falcon.AutoTableLog.Test", "Falcon.AutoTableLog.Test\Falcon.AutoTableLog.Test.csproj", "{D60683D5-D6F6-41EE-9627-43C34C977C45}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Falcon.ModelSP.Test", "Falcon.ModelSP.Test\Falcon.ModelSP.Test.csproj", "{C05DEBF9-79ED-4BA9-B8D5-CAF6F8EB4A87}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -57,6 +59,10 @@ Global
|
|||
{D60683D5-D6F6-41EE-9627-43C34C977C45}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D60683D5-D6F6-41EE-9627-43C34C977C45}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D60683D5-D6F6-41EE-9627-43C34C977C45}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C05DEBF9-79ED-4BA9-B8D5-CAF6F8EB4A87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C05DEBF9-79ED-4BA9-B8D5-CAF6F8EB4A87}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C05DEBF9-79ED-4BA9-B8D5-CAF6F8EB4A87}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C05DEBF9-79ED-4BA9-B8D5-CAF6F8EB4A87}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
Loading…
Reference in New Issue
Block a user