CounterDroneBackend/test/unit/CounterDrone.Core.Tests/RepositoryEdgeTests.cs
tian ca0ce8aa52 重命名核心模型:TargetConfig→DroneProfile, SimTask→Scenario, TaskFullConfig→ScenarioConfig, TaskId→ScenarioId
- DroneType 枚举清理:移除 Electric/Piston,重编号 HighSpeed=2
- planner_config.json / defaults.json 同步迁移
- 238 单元测试全部通过
2026-06-18 15:02:58 +08:00

64 lines
2.2 KiB
C#

using System;
using System.IO;
using CounterDrone.Core;
using CounterDrone.Core.Models;
using CounterDrone.Core.Repository;
using Xunit;
namespace CounterDrone.Core.Tests
{
public class RepositoryEdgeTests : IDisposable
{
private readonly string _testDir;
private readonly SQLite.SQLiteConnection _db;
public RepositoryEdgeTests()
{
_testDir = Path.Combine(Path.GetTempPath(), $"cd_repo_{Guid.NewGuid():N}");
var paths = new TestPathProvider(_testDir);
_db = new DatabaseManager(paths).OpenMainDb();
}
public void Dispose() { _db?.Close(); if (Directory.Exists(_testDir)) Directory.Delete(_testDir, true); }
[Fact]
public void DroneProfile_DeleteByScenarioId_RemovesAll()
{
var repo = new DroneProfileRepository(_db);
repo.Insert(new DroneProfile { Id = "t1", ScenarioId = "taskA", Quantity = 1 });
repo.Insert(new DroneProfile { Id = "t2", ScenarioId = "taskA", Quantity = 2 });
repo.Insert(new DroneProfile { Id = "t3", ScenarioId = "taskB", Quantity = 1 });
repo.DeleteByScenarioId("taskA");
Assert.Empty(repo.GetByScenarioId("taskA"));
Assert.Single(repo.GetByScenarioId("taskB"));
}
[Fact]
public void Waypoint_DeleteByScenarioId_RemovesAll()
{
var repo = new WaypointRepository(_db);
repo.Insert(new Waypoint { ScenarioId = "w1", OrderIndex = 0 });
repo.Insert(new Waypoint { ScenarioId = "w1", OrderIndex = 1 });
repo.Insert(new Waypoint { ScenarioId = "w2", OrderIndex = 0 });
repo.DeleteByScenarioId("w1");
Assert.Empty(repo.GetByScenarioId("w1"));
Assert.Single(repo.GetByScenarioId("w2"));
}
[Fact]
public void EquipmentDeployment_DeleteByScenarioId_Works()
{
var repo = new EquipmentDeploymentRepository(_db);
repo.Insert(new EquipmentDeployment { Id = "e1", ScenarioId = "eqA" });
repo.Insert(new EquipmentDeployment { Id = "e2", ScenarioId = "eqA" });
repo.DeleteByScenarioId("eqA");
Assert.Empty(repo.GetByScenarioId("eqA"));
}
}
}