- NT8StrategyBase.cs: hide inert breakeven parameters with Browsable(false) and unused descriptions - SimpleORBNT8.cs: label settings export AutoBreakeven values as unused compatibility fields - NT8StrategyBaseBreakevenParamsTests.cs: add source assertions for hidden/inert parameters and no order-flow reads - SPRINT_BOARD.md/decisions.md: record Option A and verification evidence Build: clean | Tests: 555 passing; Core 466 passing | Dual-deployed: no - skipped by prompt
129 lines
5.5 KiB
C#
129 lines
5.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace NT8.Core.Tests.Adapters
|
|
{
|
|
[TestClass]
|
|
public class NT8StrategyBaseBreakevenParamsTests
|
|
{
|
|
[TestMethod]
|
|
public void BreakevenParameters_AreHiddenAndMarkedUnused()
|
|
{
|
|
string source = File.ReadAllText(FindStrategyBaseSourceFile());
|
|
|
|
AssertPropertyHiddenAndUnused(source, "EnableAutoBreakeven");
|
|
AssertPropertyHiddenAndUnused(source, "BreakevenTriggerTicks");
|
|
AssertPropertyHiddenAndUnused(source, "BreakevenOffsetTicks");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void BreakevenParameters_AreNotReadByOrderFlowMethods()
|
|
{
|
|
string source = File.ReadAllText(FindStrategyBaseSourceFile());
|
|
string onBarUpdate = ExtractMethodBlock(source, "protected override void OnBarUpdate");
|
|
string submitOrder = ExtractMethodBlock(source, "private void SubmitOrderToNT8");
|
|
|
|
AssertNoBreakevenParameterReference(onBarUpdate);
|
|
AssertNoBreakevenParameterReference(submitOrder);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SimpleORBSettingsExport_LabelsBreakevenAsUnused()
|
|
{
|
|
string source = File.ReadAllText(FindSimpleOrbSourceFile());
|
|
string method = ExtractMethodBlock(source, "protected override List<string> GetStrategySettingsLines");
|
|
|
|
Assert.IsTrue(method.Contains("AutoBreakeven : UNUSED (retained for compatibility)"), "Settings export must not present inert breakeven parameters as active controls.");
|
|
}
|
|
|
|
private static void AssertPropertyHiddenAndUnused(string source, string propertyName)
|
|
{
|
|
string block = ExtractPropertyBlock(source, propertyName);
|
|
Assert.IsTrue(block.Contains("[Browsable(false)]"), propertyName + " must be hidden from the NinjaTrader property grid.");
|
|
Assert.IsTrue(block.Contains("Currently unused; retained for saved workspace compatibility."), propertyName + " must state why it remains declared.");
|
|
Assert.IsTrue(block.Contains("public"), propertyName + " must remain declared for saved workspace compatibility.");
|
|
}
|
|
|
|
private static void AssertNoBreakevenParameterReference(string method)
|
|
{
|
|
Assert.IsFalse(method.Contains("EnableAutoBreakeven"), "Order flow must not read EnableAutoBreakeven while it is inert.");
|
|
Assert.IsFalse(method.Contains("BreakevenTriggerTicks"), "Order flow must not read BreakevenTriggerTicks while it is inert.");
|
|
Assert.IsFalse(method.Contains("BreakevenOffsetTicks"), "Order flow must not read BreakevenOffsetTicks while it is inert.");
|
|
}
|
|
|
|
private static string FindStrategyBaseSourceFile()
|
|
{
|
|
return FindSourceFile("NT8StrategyBase.cs");
|
|
}
|
|
|
|
private static string FindSimpleOrbSourceFile()
|
|
{
|
|
return FindSourceFile("SimpleORBNT8.cs");
|
|
}
|
|
|
|
private static string FindSourceFile(string fileName)
|
|
{
|
|
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
|
|
while (dir != null)
|
|
{
|
|
string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", fileName);
|
|
if (File.Exists(candidate))
|
|
return candidate;
|
|
dir = dir.Parent;
|
|
}
|
|
|
|
throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\" + fileName + " from test output directory.");
|
|
}
|
|
|
|
private static string ExtractPropertyBlock(string source, string propertyName)
|
|
{
|
|
string signature = "public";
|
|
int property = source.IndexOf(propertyName + " { get; set; }", StringComparison.Ordinal);
|
|
if (property < 0)
|
|
Assert.Fail("Property not found: " + propertyName);
|
|
|
|
int start = source.LastIndexOf("[NinjaScriptProperty]", property, StringComparison.Ordinal);
|
|
if (start < 0)
|
|
Assert.Fail("Property missing NinjaScriptProperty attribute: " + propertyName);
|
|
|
|
int end = source.IndexOf(signature, property, StringComparison.Ordinal);
|
|
if (end < 0)
|
|
Assert.Fail("Property declaration not found: " + propertyName);
|
|
|
|
end = source.IndexOf(";", end, StringComparison.Ordinal);
|
|
if (end < 0)
|
|
Assert.Fail("Property declaration terminator not found: " + propertyName);
|
|
|
|
return source.Substring(start, end - start + 1);
|
|
}
|
|
|
|
private static string ExtractMethodBlock(string source, string signature)
|
|
{
|
|
int start = source.IndexOf(signature, StringComparison.Ordinal);
|
|
if (start < 0)
|
|
Assert.Fail("Source does not contain method: " + signature);
|
|
|
|
int brace = source.IndexOf("{", start, StringComparison.Ordinal);
|
|
if (brace < 0)
|
|
Assert.Fail("Method has no opening brace: " + signature);
|
|
|
|
int depth = 0;
|
|
for (int i = brace; i < source.Length; i++)
|
|
{
|
|
if (source[i] == '{')
|
|
depth++;
|
|
else if (source[i] == '}')
|
|
{
|
|
depth--;
|
|
if (depth == 0)
|
|
return source.Substring(start, i - start + 1);
|
|
}
|
|
}
|
|
|
|
Assert.Fail("Method has no closing brace: " + signature);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|