Commit 96ed1fb0 authored by 罗显健's avatar 罗显健

测试项目调整:增加类 DboPerformanceTest

parent 8b1cccb7
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using test.Extension;
using test.Tester;
namespace test.Cases
{
/// <summary>
/// Dbo性能测试
/// </summary>
public class DboPerformanceTest
{
Dictionary<string, double> dicTimes = new Dictionary<string, double>();
public void RunDapper()
{
Test1(new TDapper());
}
public void RunFluentData()
{
Test1(new TFluentData());
}
public void RunSqlHelper()
{
Test1(new TSqlHelper());
}
public void Test1(ITester tester)
{
dicTimes.Clear();
try
{
TimeWatch timeWatch = TimeWatch.Start();
var sql = "Update OrderStyleBOM Set SubmitDate = @SubmitDate,LastModifiedMemo = @LastModifiedMemo,Remark = @Remark Where UID = @UID";
Dictionary<string, object> data = new Dictionary<string, object>() { { "SubmitDate", DateTime.Now }, { "LastModifiedMemo", "更新测试" }, { "UID", Guid.Parse("F25701F7-D877-46CB-986D-991090168B97") }, { "Remark", null } };
tester.Execute(sql, data);
ShowTestTime("更新1条记录", timeWatch);
#region Select 5000
DataTable dtBom = tester.GetDataTable("Select top(5000) * From OrderStyleBOM");
ShowTestTime("查询5000条记录", timeWatch);
#endregion
var dtQuery = tester.GetDataTable("Select top(100) * From OrderStyleBOM order by ID");
#region Update 100
var upCommand = dtBom.GetUpdateCommand("OrderStyleBOM", "UID");
tester.Update(upCommand, dtQuery);
ShowTestTime("更新100条记录", timeWatch);
#endregion
#region Insert 100
foreach (DataRow row in dtQuery.Rows) row["UID"] = Guid.NewGuid(); //
tester.Insert(dtQuery.GetInsertCommand("OrderStyleBOM"), dtQuery);
ShowTestTime("插入100条记录", timeWatch);
#endregion
}
catch
{
throw;
}
}
private void ShowTestTime(string text, TimeWatch timeWatch)
{
dicTimes.Add(text, timeWatch.TimeSpan.TotalMilliseconds);
timeWatch.ShowLog(text, true);
}
public Dictionary<string, double> Result => dicTimes;
}
}
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;
using test.Cases;
using test.Extension;
using test.Tester;
......@@ -76,58 +77,20 @@ namespace test
button.Enabled = false;
Test1(tester);
button.Enabled = true;
}
private void Test1(ITester tester)
{
dicTimes.Clear();
TimeWatch timeWatch = TimeWatch.Start();
var sql = "Update OrderStyleBOM Set SubmitDate = @SubmitDate,LastModifiedMemo = @LastModifiedMemo,Remark = @Remark Where UID = @UID";
Dictionary<string, object> data = new Dictionary<string, object>() { { "SubmitDate", DateTime.Now }, { "LastModifiedMemo", "更新测试" }, { "UID", Guid.Parse("F25701F7-D877-46CB-986D-991090168B97") }, { "Remark", null } };
tester.Execute(sql, data);
ShowTestTime("更新1条记录", timeWatch);
#region Select 5000
DataTable dtBom = tester.GetDataTable("Select top(5000) * From OrderStyleBOM");
ShowTestTime("查询5000条记录", timeWatch);
#endregion
var dtQuery = tester.GetDataTable("Select top(100) * From OrderStyleBOM order by ID");
#region Update 100
var upCommand = dtBom.GetUpdateCommand("OrderStyleBOM", "UID");
tester.Update(upCommand, dtQuery);
ShowTestTime("更新100条记录", timeWatch);
#endregion
#region Insert 100
foreach (DataRow row in dtQuery.Rows) row["UID"] = Guid.NewGuid(); //
tester.Insert(dtQuery.GetInsertCommand("OrderStyleBOM"), dtQuery);
ShowTestTime("插入100条记录", timeWatch);
#endregion
ShowTester(tester.GetType().Name);
DboPerformanceTest performanceTest = new DboPerformanceTest();
performanceTest.Test1(tester);
var dicTimes = performanceTest.Result;
ShowTester(tester.GetType().Name, dicTimes);
}
Dictionary<string, double> dicTimes = new Dictionary<string, double>();
private void ShowTestTime(string text, TimeWatch timeWatch)
{
dicTimes.Add(text, timeWatch.TimeSpan.TotalMilliseconds);
timeWatch.ShowLog(text, true);
}
private void ShowTester(string testerName)
private void ShowTester(string testerName, Dictionary<string, double> dicTimes)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"{ testerName} 测试完成:");
......
......@@ -33,6 +33,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapper.2.0.78\lib\net461\Dapper.dll</HintPath>
......@@ -55,6 +58,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Cases\DboPerformance.cs" />
<Compile Include="DBO\DbFluentData.cs" />
<Compile Include="DBO\DbSqlHelper.cs" />
<Compile Include="Extension\DataTableExtension.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment