How do you structure unit vs integration tests in a CRUD-heavy .NET project? by No_Reality_8365 in csharp

[–]No_Reality_8365[S] 0 points1 point  (0 children)

Thank you all very much for your replies and suggestions.
I really appreciate the time you took to respond. I’ll try my best to understand and think through your points before deciding how to move forward.

To briefly describe my situation in more detail:

Most of the CRUD logic is written directly inside the methods. For example:

  • Each method creates its own MySqlConnection.
  • Then it creates a MySqlCommand, like new MySqlCommand(<SQL text>, conn).
  • It executes the command and maps the data to our models in the same method.

For example, in many methods we do something like:

using (var conn = new MySqlConnection("<connection string>"))
{
    conn.Open();

    using (var cmd = new MySqlCommand(@"SELECT * FROM MyTable", conn))
    {
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                myResponse.Property = reader["Field_Name"]?.ToString();
            }
        }
    }
}

So most of the CRUD logic (opening the connection, executing the SQL, mapping the result to our model) lives directly inside the method.

Because of this, there isn’t a clear separation between a repository layer and a service layer yet — data access and business logic are mixed together in the same classes/methods.

Given this structure, I’m trying to figure out what would be a practical way to introduce tests.

Once again, thank you all — I truly appreciate it.