- 模型表: ScenarioDrone(原DroneProfile) / ScenarioUnit(原EquipmentDeployment) - ScenarioConfig.Equipment→Units - 数据库旧表清理 + scenariosVersion 4→5 - 238 测试全过
64 lines
2.2 KiB
C#
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 ScenarioDrone_DeleteByScenarioId_RemovesAll()
|
|
{
|
|
var repo = new ScenarioDroneRepository(_db);
|
|
repo.Insert(new ScenarioDrone { Id = "t1", ScenarioId = "scenarioA", Quantity = 1 });
|
|
repo.Insert(new ScenarioDrone { Id = "t2", ScenarioId = "scenarioA", Quantity = 2 });
|
|
repo.Insert(new ScenarioDrone { Id = "t3", ScenarioId = "scenarioB", Quantity = 1 });
|
|
|
|
repo.DeleteByScenarioId("scenarioA");
|
|
|
|
Assert.Empty(repo.GetByScenarioId("scenarioA"));
|
|
Assert.Single(repo.GetByScenarioId("scenarioB"));
|
|
}
|
|
|
|
[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 ScenarioUnit_DeleteByScenarioId_Works()
|
|
{
|
|
var repo = new ScenarioUnitRepository(_db);
|
|
repo.Insert(new ScenarioUnit { Id = "e1", ScenarioId = "eqA" });
|
|
repo.Insert(new ScenarioUnit { Id = "e2", ScenarioId = "eqA" });
|
|
|
|
repo.DeleteByScenarioId("eqA");
|
|
Assert.Empty(repo.GetByScenarioId("eqA"));
|
|
}
|
|
}
|
|
}
|