using System; using System.IO; namespace YLErp.Modules.EodModule { [TestClass] public class BondPaymentListQueryBoundaryTest { [TestMethod] public void SearchList_OnlyQueriesBondPaymentTable() { var source = ReadBondPaymentServiceSource(); var searchList = ExtractMethod(source, "public SearchListResult SearchList", "public BondPayment SaveBondPayment"); Assert.IsFalse( searchList.Contains("ex_dividend_info", StringComparison.Ordinal), "债券付息列表只能查询 bond_payment_info,不能把公司行为除权表拼入展示结果。"); StringAssert.Contains(searchList, "DbContext.bondPayment"); } private static string ExtractMethod(string source, string startMarker, string endMarker) { var start = source.IndexOf(startMarker, StringComparison.Ordinal); Assert.IsTrue(start >= 0, $"Could not find method: {startMarker}"); var end = source.IndexOf(endMarker, start + startMarker.Length, StringComparison.Ordinal); Assert.IsTrue(end >= 0, $"Could not find method end: {endMarker}"); return source.Substring(start, end - start); } private static string ReadBondPaymentServiceSource() { var directory = new DirectoryInfo(AppContext.BaseDirectory); while (directory != null) { var path = Path.Combine(directory.FullName, "YLErpDAL", "Modules", "EodModule", "BondPaymentService.cs"); if (File.Exists(path)) { return File.ReadAllText(path); } directory = directory.Parent; } Assert.Fail("Could not locate BondPaymentService.cs from the test output directory."); return string.Empty; } } }