增加内存数据库ModelSP测试,测试失败
This commit is contained in:
parent
8f0d39981f
commit
9eaae62a60
45
Falcon.ModelSP.Test/Db/TestDbContext.cs
Normal file
45
Falcon.ModelSP.Test/Db/TestDbContext.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Falcon.ModelSP;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Falcon.ModelSP.Test.Db
|
||||
{
|
||||
class TestDbContext:DbContext
|
||||
{
|
||||
protected TestDbContext() { }
|
||||
protected TestDbContext(DbContextOptions option) : base(option) { }
|
||||
|
||||
public static TestDbContext GetDbInMemory() {
|
||||
var option = new DbContextOptionsBuilder<TestDbContext>().UseInMemoryDatabase("TestDb").Options;
|
||||
var db = new TestDbContext(option);
|
||||
AddTestPr(db);
|
||||
return db;
|
||||
}
|
||||
|
||||
public static void AddTestPr(TestDbContext db) {
|
||||
var sql = @"
|
||||
DROP PROC Pr_AddOne
|
||||
CREATE PROCEDURE Pr_AddOne
|
||||
@a AS INT
|
||||
AS
|
||||
Set Nocount On
|
||||
SELECT @a+1 aa;
|
||||
GO
|
||||
";
|
||||
//db.Database.ExecuteSqlCommandAsync(sql).Wait();
|
||||
}
|
||||
|
||||
public IEnumerable<Pr_AddOneResult> Pr_AddOne(Pr_AddOne data) {
|
||||
return this.RunProcuder<Pr_AddOne,Pr_AddOneResult>(data);
|
||||
}
|
||||
}
|
||||
|
||||
public class Pr_AddOne
|
||||
{
|
||||
public int A { get; set; }
|
||||
}
|
||||
public class Pr_AddOneResult
|
||||
{
|
||||
public int Aa { get; set; }
|
||||
}
|
||||
}
|
|
@ -7,6 +7,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.6" />
|
||||
<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" />
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Falcon.ModelSP;
|
||||
using System.Linq;
|
||||
using Falcon.ModelSP.Test.Db;
|
||||
|
||||
namespace Falcon.ModelSP.Test
|
||||
{
|
||||
|
@ -43,5 +44,18 @@ namespace Falcon.ModelSP.Test
|
|||
|
||||
[FalconSPProcuderName("sp123")]
|
||||
class ParmModel1 { }
|
||||
|
||||
[TestMethod]
|
||||
public void InMemoryDbTest() {
|
||||
//内存数据库无法使用关系模型,测试无法进行
|
||||
return;
|
||||
using(var db = TestDbContext.GetDbInMemory()) {
|
||||
var re = db.Pr_AddOne(new Pr_AddOne { A = 1 });
|
||||
Assert.IsTrue(re != null);
|
||||
Assert.IsTrue(re.Any());
|
||||
var first = re.First();
|
||||
Assert.IsTrue(first.Aa == 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
Falcon.ModelSP/FalconSPRuner.cs
Normal file
20
Falcon.ModelSP/FalconSPRuner.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Falcon.ModelSP
|
||||
{
|
||||
/// <summary>
|
||||
/// 存储过程执行器实现
|
||||
/// </summary>
|
||||
public class FalconSPRuner:IFalconSPRuner
|
||||
{
|
||||
public int RunSP<TPrarmType>(DbContext db,TPrarmType data) {
|
||||
return db.RunProcuder(data);
|
||||
}
|
||||
|
||||
public IEnumerable<TResultType> RunSP<TPrarmType, TResultType>(DbContext db,TPrarmType data)
|
||||
where TResultType : class, new() {
|
||||
return db.RunProcuder<TPrarmType,TResultType>(data);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Falcon.ModelSP
|
||||
|
@ -27,19 +25,4 @@ namespace Falcon.ModelSP
|
|||
/// <param name="data">参数数据</param>
|
||||
IEnumerable<TResultType> RunSP<TPrarmType, TResultType>(DbContext db,TPrarmType data) where TResultType : class, new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 存储过程执行器实现
|
||||
/// </summary>
|
||||
public class FalconSPRuner:IFalconSPRuner
|
||||
{
|
||||
public int RunSP<TPrarmType>(DbContext db,TPrarmType data) {
|
||||
return db.RunProcuder(data);
|
||||
}
|
||||
|
||||
public IEnumerable<TResultType> RunSP<TPrarmType, TResultType>(DbContext db,TPrarmType data)
|
||||
where TResultType : class, new() {
|
||||
return db.RunProcuder<TPrarmType,TResultType>(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Falcon.ModelSP
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user