【发布时间】:2020-01-10 09:00:12
【问题描述】:
我正在开发一个与 dapper 一起使用的单元测试。 我已阅读以下文章:
https://miniprofiler.com/dotnet/HowTo/ProfileSql
https://miniprofiler.com/dotnet/ConsoleDotNet
这是我写的代码:
[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());
}
问题是控制台上没有打印数据。
更新:
问题不在Console.WriteLine 中(我也使用了Debug.WriteLine 和TestContext.WriteLine)。
真正的问题是为什么profiler.RenderPlainText() 返回一个空字符串。
我有什么遗漏的吗?
【问题讨论】:
-
现在看到更新。由于重复不再适用,将投票重新打开帖子。
标签: c# unit-testing dapper miniprofiler