- DroneProfile/DroneSpec: 加 Model、Description - Scenario: 加 Description,TaskNumber→ScenarioNumber - EquipmentDeployment/FireUnitSpec: 加 Description - ScenarioConfig: Task→Info - ScenarioService: CreateTask→CreateScenario 等方法名统一 - 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 DroneProfile_DeleteByScenarioId_RemovesAll()
|
|
{
|
|
var repo = new DroneProfileRepository(_db);
|
|
repo.Insert(new DroneProfile { Id = "t1", ScenarioId = "scenarioA", Quantity = 1 });
|
|
repo.Insert(new DroneProfile { Id = "t2", ScenarioId = "scenarioA", Quantity = 2 });
|
|
repo.Insert(new DroneProfile { 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 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"));
|
|
}
|
|
}
|
|
}
|