【问题标题】:Integration testing using sqlite memory two api calls使用sqlite内存进行集成测试两个api调用
【发布时间】:2018-05-19 22:47:41
【问题描述】:

在数据库在内存中的查询发生后,我在进行插入调用(和创建数据库)时遇到问题,问题是对数据库的 acada 调用终止。能够在我的测试中创建数据库并对其进行操作会很有趣。

// Act
var model = new CreateOrUpdateTagsModel
{
    UserId = 1,
    CatalogItemType = "Movie",
    Owner = 1,
    PinRequired = false,
    ProductId = 1,
    TagType = "Stars",
    TagValue = "5"
};

var jsonSerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var json = JsonConvert.SerializeObject(model, jsonSerializerSettings);

var response2 = await _client.PutAsync("/v1/tags", new StringContent(json, Encoding.UTF8, "application/json"));
response2.EnsureSuccessStatusCode();

var responseString2 = await response2.Content.ReadAsStringAsync();

var response = await _client.GetAsync("/v1/tags?userId=1");
response.EnsureSuccessStatusCode();

【问题讨论】:

    标签: c# asp.net-core integration-testing web-api-testing


    【解决方案1】:

    我一直在使用AddSingletonIDbConnection 解决您的StartupTest.cs,并在我的测试中使用_queryExecutor = _server.Host.Services.GetService(typeof(IQueryExecutor)) as IQueryExecutor; 作为_serverTestServer 实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-16
      • 2013-03-18
      • 1970-01-01
      • 2020-03-09
      • 2013-11-22
      • 2015-03-21
      • 2019-06-30
      • 2014-03-09
      相关资源
      最近更新 更多