- DroneProfile/DroneSpec: 加 Model、Description - Scenario: 加 Description,TaskNumber→ScenarioNumber - EquipmentDeployment/FireUnitSpec: 加 Description - ScenarioConfig: Task→Info - ScenarioService: CreateTask→CreateScenario 等方法名统一 - 238 单元测试通过
93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using CounterDrone.Core;
|
|
using CounterDrone.Core.Models;
|
|
using CounterDrone.Core.Services;
|
|
using CounterDrone.Core.Simulation;
|
|
using SQLite;
|
|
using Xunit;
|
|
|
|
namespace CounterDrone.Core.Tests
|
|
{
|
|
public class ReportServiceTests : IDisposable
|
|
{
|
|
private readonly string _testDir;
|
|
private readonly IReportService _service;
|
|
private readonly SQLiteConnection _db;
|
|
|
|
public ReportServiceTests()
|
|
{
|
|
_testDir = Path.Combine(Path.GetTempPath(), $"cd_rep_{Guid.NewGuid():N}");
|
|
var paths = new TestPathProvider(_testDir);
|
|
var dbm = new DatabaseManager(paths);
|
|
_db = dbm.OpenMainDb();
|
|
_service = new ReportService(_db, paths);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_db?.Close();
|
|
if (Directory.Exists(_testDir)) Directory.Delete(_testDir, true);
|
|
}
|
|
|
|
[Fact]
|
|
public void Generate_And_Get_ReturnsReport()
|
|
{
|
|
var config = new ScenarioConfig
|
|
{
|
|
Info = new Scenario { Name = "Test", ScenarioNumber = "SIM-001" },
|
|
Targets = new List<DroneProfile> { new DroneProfile { Quantity = 1 } },
|
|
Equipment = new List<EquipmentDeployment>(),
|
|
Cloud = new CloudDispersal(),
|
|
};
|
|
|
|
var report = _service.Generate("scenario1", config, new List<SimEvent>(), "Destroyed", 45f);
|
|
|
|
Assert.NotNull(report);
|
|
Assert.NotEmpty(report.Id);
|
|
Assert.Equal("Test", report.ScenarioName);
|
|
Assert.Contains("仿真评估报告", report.Content);
|
|
|
|
var fetched = _service.GetReport(report.Id);
|
|
Assert.NotNull(fetched);
|
|
}
|
|
|
|
[Fact]
|
|
public void Delete_RemovesReport()
|
|
{
|
|
var config = new ScenarioConfig
|
|
{
|
|
Info = new Scenario { Name = "Del", ScenarioNumber = "SIM-DEL" },
|
|
Targets = new List<DroneProfile> { new DroneProfile { Quantity = 1 } },
|
|
Equipment = new List<EquipmentDeployment>(),
|
|
Cloud = new CloudDispersal(),
|
|
};
|
|
|
|
var report = _service.Generate("scenario1", config, new List<SimEvent>(), "Destroyed", 10f);
|
|
_service.DeleteReport(report.Id);
|
|
Assert.Null(_service.GetReport(report.Id));
|
|
}
|
|
|
|
[Fact]
|
|
public void SearchReports_Keyword()
|
|
{
|
|
var cfg = new ScenarioConfig
|
|
{
|
|
Info = new Scenario { Name = "城市防御", ScenarioNumber = "SIM-A" },
|
|
Targets = new List<DroneProfile> { new DroneProfile { Quantity = 1 } },
|
|
Equipment = new List<EquipmentDeployment>(),
|
|
Cloud = new CloudDispersal(),
|
|
};
|
|
|
|
_service.Generate("t1", cfg, new List<SimEvent>(), "Destroyed", 10f);
|
|
cfg.Info.Name = "平原拦截";
|
|
cfg.Info.ScenarioNumber = "SIM-B";
|
|
_service.Generate("t2", cfg, new List<SimEvent>(), "Destroyed", 20f);
|
|
|
|
var result = _service.SearchReports("城市", null, null, 1, 10);
|
|
Assert.Equal(1, result.TotalCount);
|
|
}
|
|
}
|
|
}
|