I’m creating tests for my .Net 8 API, and as I want to test with fake self created data (instead of using the real MySql connection) I’m having problems figuring out how to implement that behavior, I mean, using -for example- an In-Memory database.
We use CQRS (Mediator pattern) for the database queries, and on each query handler we inject ICloudStackCoreConnectionFactory which has a CreateConnection method that returns a DBConnection (in our case, a MySqlConnection):
´ICloudStackCoreConnectionFactory:´
public DbConnection CreateConnection(Region region)
{
return (DbConnection)new MySqlConnection(GetConnString(region));
}
I’d like to replace that MySqlConnection implementation by an in-memory connection so I can test with a reduced set of fake data, but I don’t know how to do it.
Any help?