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 ?