![](/img/trans.png)
[英]Unit Tests for C# Code where primary processing occurs in SQL Stored procedures
[英]Run stored procedures in InMemory unit tests
如何在内存数据库中运行存储过程? 我正在尝试搜索此功能。
https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/in-memory
这是用于设置:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFProviders.InMemory;Trusted_Connection=True;ConnectRetryCount=0");
}
}
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseInMemoryDatabase(databaseName: "Find_searches_url")
.Options;
// Insert seed data into the database using one instance of the context
using (var context = new BloggingContext(options))
{
context.Blogs.Add(new Blog { Url = "http://sample.com/cats" });
context.Blogs.Add(new Blog { Url = "http://sample.com/catfish" });
context.Blogs.Add(new Blog { Url = "http://sample.com/dogs" });
context.SaveChanges();
}
简短的回答; 内存中的提供者不能这样做。
我遇到过同样的问题; 我在单元测试中存储了 procs,我需要模拟结果。 在搜索了一个库来做这件事并没有找到可以做大 3( FromSql
、 ExecuteSqlCommand
和 Queries)的库之后,我写了我自己的: EntityFrameworkCore.Testing 。 它对大多数事情使用内存提供程序,并为它不能做的位提供模拟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.