簡體   English   中英

在 InMemory 單元測試中運行存儲過程

[英]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( FromSqlExecuteSqlCommand和 Queries)的庫之后,我寫了我自己的: EntityFrameworkCore.Testing 它對大多數事情使用內存提供程序,並為它不能做的位提供模擬。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM