using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
namespace NavisworksTransport.UnitTests.Integration
{
///
/// 路径分析集成测试(覆盖计划 T15)。
///
/// 验证路径分析链路(PathAnalysisService.AnalyzePath):
/// - 分析成功并返回与路径关联的评分结果
/// - 评分结构完整(安全/效率/综合分、转弯难度、曲折度等)
/// - 策略参数正确回传
///
[TestClass]
[TestCategory("NavisworksIntegration")]
public class PathAnalysisAutomationTests
{
[TestMethod]
[Timeout(240000)]
public async Task GroundRoute_Analysis_ReturnsValidScores()
{
using (var client = new NavisworksTestAutomationClient())
{
await client.EnsureServiceReadyAsync(TimeSpan.FromSeconds(90)).ConfigureAwait(false);
JObject response = await client.AnalyzePathAsync("自动测试_Ground", "安全优先").ConfigureAwait(false);
Assert.IsTrue(response.Value("ok"), "路径分析失败: " + (string)response["error"]);
JObject data = (JObject)response["data"];
// 关联路径
Assert.AreEqual("自动测试_Ground", (string)data["routeName"], "分析路径名不匹配");
Assert.IsFalse(string.IsNullOrWhiteSpace((string)data["routeId"]), "分析结果缺少路径 ID");
// 策略回传
Assert.AreEqual("安全优先", (string)data["strategy"], "分析策略不匹配");
// 评分结构(非负)
Assert.IsTrue((int)data["collisionCount"] >= 0, "碰撞数不能为负");
Assert.IsTrue((double)data["safetyScore"] >= 0, "安全评分不能为负");
Assert.IsTrue((double)data["efficiencyScore"] >= 0, "效率评分不能为负");
Assert.IsTrue((double)data["overallScore"] >= 0, "综合评分不能为负");
Assert.IsTrue((double)data["turnDifficultyScore"] >= 0, "转弯难度评分不能为负");
Assert.IsTrue((double)data["tortuosityScore"] >= 0, "曲折度评分不能为负");
Assert.IsTrue((double)data["redundancyScore"] >= 0, "冗余度评分不能为负");
Assert.IsTrue((int)data["hotspotCount"] >= 0, "热点数不能为负");
}
}
}
}