86 lines
3.5 KiB
C#
86 lines
3.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
|
||
namespace Gpulse.WCT.DataAnalyzer.Tests.Commands;
|
||
|
||
[TestFixture]
|
||
public class AggregateCommandTests : CommandTestBase
|
||
{
|
||
[Test]
|
||
public async Task Aggregate_EmptyDatabase_ReportsZero()
|
||
{
|
||
var (code, stdout, _) = await Aggregate().RunCaptureAsync();
|
||
|
||
Assert.Multiple(() =>
|
||
{
|
||
Assert.That(code, Is.EqualTo(0));
|
||
Assert.That(stdout, Does.Contain("Aggregated 0 local Ploss records into 0 release records."));
|
||
});
|
||
}
|
||
|
||
[Test]
|
||
public async Task Aggregate_AfterParse_GroupsByThresholdIntoReleaseDb()
|
||
{
|
||
var dir = NewDir();
|
||
var file = TestFixtures.WritePlossLog(dir, TestFixtures.PlossFileName,
|
||
new TestFixtures.PlossTwoLineRow(Field7: 100, Field9: 350, Field10: 350),
|
||
new TestFixtures.PlossTwoLineRow(Field7: 110, Field9: 350, Field10: 350),
|
||
new TestFixtures.PlossTwoLineRow(Field7: 200, Field9: 500, Field10: 500));
|
||
await Parse().RunCaptureAsync("--file", file);
|
||
|
||
var (code, stdout, _) = await Aggregate().RunCaptureAsync();
|
||
|
||
Assert.Multiple(() =>
|
||
{
|
||
Assert.That(code, Is.EqualTo(0));
|
||
Assert.That(stdout, Does.Contain("Aggregated 3 local Ploss records into 1 release records."));
|
||
});
|
||
|
||
var record = await Host.ReleaseDb.ChargingParameters.SingleAsync();
|
||
Assert.Multiple(() =>
|
||
{
|
||
// 维度来自文件名:singleMold(TxPanel) / v1.0(TxHardware) / hex2_1(TxSoftware) / iPhone15(RxType)
|
||
Assert.That(record.CarFactory, Is.EqualTo("singleMold"));
|
||
Assert.That(record.CarModel, Is.EqualTo("v1.0"));
|
||
Assert.That(record.PhoneModel, Is.EqualTo("iPhone15"));
|
||
// Field9=350 的两行 Field7 取平均 = (100+110)/2
|
||
Assert.That(record.Power350mW, Is.EqualTo(105));
|
||
Assert.That(record.Power500mW, Is.EqualTo(200));
|
||
});
|
||
}
|
||
|
||
[Test]
|
||
public async Task Aggregate_DefaultRebuild_DoesNotDuplicateOnSecondRun()
|
||
{
|
||
var dir = NewDir();
|
||
var file = TestFixtures.WritePlossLog(dir, TestFixtures.PlossFileName,
|
||
new TestFixtures.PlossTwoLineRow(Field7: 100, Field9: 350, Field10: 350));
|
||
await Parse().RunCaptureAsync("--file", file);
|
||
|
||
await Aggregate().RunCaptureAsync();
|
||
await Aggregate().RunCaptureAsync();
|
||
|
||
Assert.That(await Host.ReleaseDb.ChargingParameters.CountAsync(), Is.EqualTo(1));
|
||
}
|
||
|
||
[Test]
|
||
public async Task Aggregate_RebuildFalse_InsertsIntoEmptyTable()
|
||
{
|
||
// 注:发布库对业务键 (车厂/车型/手机厂商/型号) 有唯一索引;
|
||
// append 模式会对全部本地记录重新入库,因此只适合表为空时使用,
|
||
// 对已聚合过的同一数据再 append 会因唯一索引冲突而失败(聚合命令捕获并输出 "Aggregation failed")。
|
||
var dir = NewDir();
|
||
var file = TestFixtures.WritePlossLog(dir, TestFixtures.PlossFileName,
|
||
new TestFixtures.PlossTwoLineRow(Field7: 100, Field9: 350, Field10: 350));
|
||
await Parse().RunCaptureAsync("--file", file);
|
||
|
||
var (code, stdout, _) = await Aggregate().RunCaptureAsync("--rebuild", "false");
|
||
|
||
Assert.Multiple(() =>
|
||
{
|
||
Assert.That(code, Is.EqualTo(0));
|
||
Assert.That(stdout, Does.Contain("Aggregated 1 local Ploss records into 1 release records."));
|
||
});
|
||
Assert.That(await Host.ReleaseDb.ChargingParameters.CountAsync(), Is.EqualTo(1));
|
||
}
|
||
}
|