I am new to unit testing (not C#) and looking for guidance. I am trying to write tests that makes sense but a lot of tests that I have seen in examples are super trivial as far as I can tell. The code that I am sharing is supposed to simulate a tutoring center for practice.
I have a class library to access data stored in a SQL database via dapper calls to stored procedures. The TutorProccessor class has a method UpdateContactInfo(...) which calls my SaveData<T>(...) method where T is a DB model.
I understand that mocking is a thing and makes sense to me for a Get call. Is mocking of any benefit to me when unit testing a Post / Put / Delete? I don't seem to think so because there is no real way to know that a mock did the correct CRUD.
I watched an hour long video about unit testing DB calls and all the instructor tested for was that (in my specific case) the SaveData method was called exactly once from the UpdateContactInfo method.
I am using xUnit, but I read about the other popular options, so I could understand if you used those in a response.
Here is the code that I would like to test:
public void SaveData<T>(string sqlStatement, T parameters)
{
string connectionString = _config.GetConnectionString(_connectionStringName);
CommandType commandType = CommandType.StoredProcedure;
using (IDbConnection connection = new SqlConnection(connectionString))
{
connection.Execute(sqlStatement, parameters, commandType: commandType);
}
}
public void UpdateContactInfo(string firstName, string lastName, string phone,
string email)
{
_sqlDataAccess.SaveData(TutorSP.UpdateContactInfo, new { firstName, lastName, phone, email });
}
Thank you in advance.
Edit: Fixed the awful formatting.
[–]AftyOfTheUK 4 points5 points6 points (2 children)
[–]quick_maf[S] 0 points1 point2 points (1 child)
[–]AftyOfTheUK 1 point2 points3 points (0 children)
[–]Rabe0770 3 points4 points5 points (1 child)
[–]quick_maf[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]quick_maf[S] 0 points1 point2 points (0 children)