mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 00:21:31 +00:00
Every test written during the coverage review, in one commit: 105 files, about 32,000 lines added. No product code is touched here - what the tests found is repaired in the commit that follows. WHERE THEY CAME FROM. Three audits read the core and its suite side by side and filed 295 findings. Each was taken as a claim to be disproved rather than believed: of the defects claimed, most did not survive a second reading - an unreachable trigger, a promise nobody ever made, behaviour already covered, and in one case a property the model no longer has, so the test could not be written at all. What survived is here. WHAT THE TESTS ARE. Three kinds, and the difference matters. A hole: behaviour the core has and nothing checked. Most of the new files are this - the adapters that filter a depth, hold a candle, track a lookup, associate a security or loop a message back; the message clone that must not share state with its original; the generators behind localized strings and media names; the round trip of a diagram strategy and of a FIX data type. A test that proved nothing: a name that promised one thing while the assertion checked another, an assertion that could not fail, an expected value copied from whatever the code returned that day. Those were rewritten in place to say what they were named for, and several of them go red doing it. A defect: a promise the core makes and does not keep. Those tests are red, and they stay red until the next commit repairs them - a red test is the record of the defect, and there is nowhere else the record would be read. HOW THEY ARE WRITTEN. From the promise, not from the implementation: the expected value is what the caller is owed, never what the method happens to return. Every assertion carries a message saying what was owed to whom, so a failure reads as a sentence rather than as two numbers that differ. Claude-Session: https://claude.ai/code/session_01LjT4RKLsz3vBd8eSERZTde
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
namespace StockSharp.Tests;
|
|
|
|
using System.Text;
|
|
|
|
using StockSharp.Fix.Native;
|
|
|
|
using FixExtensions = StockSharp.Fix.Native.Extensions;
|
|
|
|
/// <summary>
|
|
/// An aborted serialization resets the reused per-session body writer. WriteFixMessageAsync resets
|
|
/// it only on success, so a body handler that throws mid-way left partial bytes at a non-zero
|
|
/// position: the next message was appended after them and shipped as one BodyLength- and
|
|
/// checksum-consistent frame that silently swallowed a real message.
|
|
/// </summary>
|
|
[TestClass]
|
|
public class FixMessageWriteAbortTests : BaseTestClass
|
|
{
|
|
[TestMethod]
|
|
public async Task WriteFixMessageAsync_HandlerThrows_ResetsBodyWriter()
|
|
{
|
|
var writer = new TextFixWriter(new MemoryStream(), Encoding.UTF8, ownsStream: true);
|
|
var bodyWriter = new TextFixWriter(new MemoryStream(), Encoding.UTF8, ownsStream: true);
|
|
var parser = new FastDateTimeParser(FixExtensions.TimeStampFormat);
|
|
|
|
var threw = false;
|
|
try
|
|
{
|
|
await writer.WriteFixMessageAsync(bodyWriter, "FIX.4.4", "0", "S", "T", parser, 1,
|
|
(bw, ct) => throw new InvalidOperationException("body handler failure"), CancellationToken);
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
threw = true;
|
|
}
|
|
|
|
threw.AssertTrue("the aborted write should have propagated the handler exception");
|
|
bodyWriter.Stream.Position.AssertEqual(0L,
|
|
"an aborted write must reset the reused body writer, else the next message ships prepended with the aborted body");
|
|
}
|
|
}
|