Integration tests using sqlite memory two api calls

Asked

Viewed 144 times

0

I’m having trouble making an Insert call (and creating the database) after query occurs that the database is in memory the problem is that ended called the database dies. It would be interesting if I could create the database in my test and manipulate it.

// 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();
  • Apparently you’re testing calls to Pis. In this case it would be better for you to focus the tests on your logic and use mocks to simulate these calls without them being actually made. With this dependency you need to ensure that the api environment is available when running the tests, which can be very bad.

1 answer

0


I managed to change my Startuptest.Cs to the IDbConnection use AddSingleton and on my test using _queryExecutor = _server.Host.Services.GetService(typeof(IQueryExecutor)) as IQueryExecutor; being _server instance of TestServer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.