title: C# NUnit Mock Database Setup to test embedded SQL
body: <p>Project Framework: .NetFramework (Not .NetCore)</p>
  <p>UnitTest Framework: NUnit 3.13.0</p>
  <p>Project construction sample:</p>
  <p><strong>Program.cs:</strong></p>
  <pre><code>class Program
  {
        static void Main(string[] args)
        {
              SqlConnection connection = new SqlConnection(&quot;Server=serverName;Database=dbName;Trusted_Connection=True;&quot;);
              connection.open();
       
              TestProcess _process = new TestProcess();
              _process.Run(connection);
  
              connection.close();
  
        }
  }
  </code></pre>
  <p><strong>TestProcess.cs:</strong></p>
  <pre><code>class TestProcess
  {
        public void Run(SqlConnection connection)
        {
              List&lt;StudentModel&gt; students = GetFromDb(connection);
              //Do something with students
        }
  
        public void GetFromDb(SqlConnection connection)
        {
              List&lt;StudentModel&gt; students = new List&lt;StudentModel&gt;();
              DataTabel table = new DataTable();
              //This could be a view or a table
              using (SqlCommand command = new SqlCommand(&quot;SELECT * FROM dbName.vwStudents&quot;, connection)
              {
                    using (SqlReader dataRead = command.ExecuteReader())
                    {
                          tabel.load(dataRead);
                    }
              }
              foreach (DataRow row in table.Rows)
              {
                    students.Add(new Student(row));
              }
              return students;
        }
  }
  </code></pre>
  <p>PS: The code works fine, this is just a sample, so ignore any problems you see with it</p>
  <p>So, I am trying to write unit tests for this kind of a setup. Lets say I am writing unit tests for the GetFromDb() function. Is there a way I could mockup the database without actually querying the db. Or maybe I could create a facade. I am not using EFCore to create a context and use facade directly.</p>
  <p>I understand that using embedded sql is not the best way, but this is probably the easiest approach for my project. I already moved the sqlconnection out to the main() to make it a little better. Anyway, what is the best way to unitTest this setup without touching the DB. Is that even possible?
  Also, I am not keen on redoing the project but if you think moving a few things around will help me write better tests, I am all ears.</p>
  <p>Thank you in advance!</p>