2

I am working on a unit test that works with dapper. I have read following articles :

https://miniprofiler.com/dotnet/HowTo/ProfileSql

https://miniprofiler.com/dotnet/ConsoleDotNet

and here's the code I have written :

    [TestMethod]
    public void GetEmployeesTest()
    {
        var profiler=MiniProfiler.Start("Dapper Test");
        using (profiler.Step("Test"))
        {
            using (DbConnection cnn = new SqlConnection("Server=.;Initial Catalog=Northwind;Integrated Security=true;"))
            {
                var pcnn = new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, profiler);
                pcnn.Open();
                var employees = pcnn.Query<Employee>("SELECT * FROM Employees");
                var count = pcnn.ExecuteScalar<long>("SELECT COUNT(*) FROM Employees");

                Assert.AreEqual(count, employees.Count());
            }
        }
        Console.WriteLine(profiler.RenderPlainText());

    }

The problem is no data is printed on the console.

Update: The problem is not in Console.WriteLine (I also used Debug.WriteLine and TestContext.WriteLine). The real question is why profiler.RenderPlainText() returns an empty string.

Is there anything that I have missed ?

Beatles1692
  • 5,214
  • 34
  • 65

1 Answers1

0

It is an unit test and you should use Assert methods to find out something is right or wrong. There is no need to print something on Console. And also it's better to use sql in memory for unit test or Mock database. because other tests may manipulate data and cause this test fails.