I am currently trying to learn Mocking with Moq, and I wanted to try it on an existing database that I have, however I am unsure how is the correct way to approach this.
In my data layer I have a class that handles connecting to the DB and has the various methods for inserting, selecting etc. I want to test whether an actor was correctly inserted into the database.
My Insert method currently looks like this:
public void Insert(string firstname, string lastname)
{
string query = $"INSERT INTO `sakila`.`actor`(`first_name`,`last_name`) VALUES('" + firstname + "','" + lastname + "')";
Console.WriteLine(query);
//open connection
if (this.OpenConnection() == true)
{
Console.WriteLine("Established connection");
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
Console.WriteLine("Insert query succesfully executed.");
//close connection
this.CloseConnection();
}
}
How would I go about doing this using Mocks? Do I create a class for the actor entity? Should I create an interface for my DbConnection
class?
Sorry for all the questions, but I'm really stumped on how to approach this problem.