如何从SpecFlow测试访问EF Core InMemory DB?

时间:2017-10-31 12:25:09

标签: c# sql-server entity-framework-core specflow in-memory-database

我的设置是:

  1. 我使用Web API在.NET Core中编写了REST API。它使用Entity Framework从SQL Server数据库中获取数据。如果环境是“测试”,它将被设置为使用Entity Framework In-Memory数据库。

  2. 我在.NET Framework中创建了一个SpecFlow测试项目(因为SpecFlow还不支持.NET内核)。

  3. 我的问题是:

    如何从SpecFlow步骤中在API内存数据库中注入数据?内存数据库是否具有可用于插入数据的连接字符串,还是有其他方法可以执行此操作?

    我有以下场景(简化):

    Given the user 'JohnDoe' with rating '123' is exists
    When I request the API with HTTP GET '/users/JohnDoe/rating'
    Then I get the rating '123'
    

    在Given步骤中,我想将用户放入内存数据库中,以便API可以找到并返回它。

0 个答案:

没有答案
相关问题