[英]Run stored procedures in InMemory unit tests
How do I run stored procedures in an in-memory databases?如何在内存数据库中运行存储过程? I am trying to search for this functionality.
我正在尝试搜索此功能。
https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/in-memory https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/in-memory
This is for setup:这是用于设置:
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();
}
Short answer;简短的回答; the in-memory provider can't do it.
内存中的提供者不能这样做。
I had the same issue;我遇到过同样的问题; I had stored procs surfacing in unit tests and I needed to mock the results.
我在单元测试中存储了 procs,我需要模拟结果。 After searching for a library to do it and finding none that could do the big 3 (
FromSql
, ExecuteSqlCommand
and Queries) I wrote my own: EntityFrameworkCore.Testing .在搜索了一个库来做这件事并没有找到可以做大 3(
FromSql
、 ExecuteSqlCommand
和 Queries)的库之后,我写了我自己的: EntityFrameworkCore.Testing 。 It uses the in-memory provider for most things and provides mocks for the bits it can't do.它对大多数事情使用内存提供程序,并为它不能做的位提供模拟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.