acdream/tests/AcDream.Core.Net.Tests/WorldSessionVendorTests.cs
Erik 92ea3977b6
Some checks are pending
Headless portability / portable-headless (ubuntu-latest) (push) Waiting to run
Headless portability / portable-headless (windows-latest) (push) Waiting to run
Headless portability / linux-graphical (push) Waiting to run
Headless portability / linux-vulkan (push) Waiting to run
feat(vendor): Slice 6b/6c — move-to-use, buy staging, selling; the vendor arc is functionally complete
C1 an out-of-range Use now approaches first via the existing
client-predicted BeginApproach (Pickup's far-range shape mirrored;
retail's ItemHolder::UseObject @0x00588A80 has no range check and the
dispatch stays immediate). C2 Add-to-List stages into the Buying tab
via VendorStagingList (RemoveProfileFromList's two shapes,
pc:200497-200537), Buy All sends ONE batched 0x005F and flushes
staging on send exactly as retail does (SendShopEvent -> Flush,
pc:204075-204076 — not UseDone-gated), and X-close over a non-empty
staging list shows retail's confirm string recovered verbatim from the
binary data segment (0x007b5bd8) through the existing dialog factory.
C3 the Selling tab's list is the sole drop target (retail's single
IsAncestorOfMe gate, pc:204229-204246); VendorSellAcceptability ports
InqAcceptability with all rejection strings recovered verbatim from
the raw data segment; the sell side prices with BuyPrice (retail's
inverted naming: what the vendor PAYS) and 0x0060 carries no trailing
currency field, unlike Buy. C4 the status-bar reproduction test PASSES
against the production toolbar mount — retail's toolbar shows count +
name with the split bar and NO price parenthetical (that figure is the
vendor row's own cost text); no code change, the live gate referees.
C5 pack order verified correct, untouched.

Register: AP-161 narrowed to its two pre-existing cosmetic gaps;
AP-162 extended over Buy All; AP-164 (non-sellable bitfield
unmodeled), AP-165 (DescStackSize for _maxStackSize in the removal
test, bounded), AP-166 (purse text + pending-sell highlight cosmetic)
filed.

Clean-room complete solution: 11,482 passed / 4 skipped / 0 failed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-08-08 11:43:11 +02:00

130 lines
4 KiB
C#

using System.Net;
using AcDream.Core.Net;
using AcDream.Core.Net.Messages;
namespace AcDream.Core.Net.Tests;
/// <summary>
/// Slice 6.3 — verifies <see cref="WorldSession.SendBuy"/> produces the same
/// wire bytes <see cref="VendorRequests.BuildBuy"/> does directly, using a
/// sequence number drawn from <see cref="WorldSession.NextGameActionSequence"/>.
/// Mirrors <c>WorldSessionChatTests</c>'s <c>GameActionCapture</c> test seam.
/// </summary>
public sealed class WorldSessionVendorTests
{
private static WorldSession NewSession()
{
var ep = new IPEndPoint(IPAddress.Loopback, 65001);
return new WorldSession(ep);
}
[Fact]
public void SendBuy_EmitsBytesIdenticalToVendorRequestsBuildBuy()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendBuy(
vendorGuid: 0x40001000u,
itemGuid: 0x50002000u,
amount: 3,
alternateCurrencyId: 0u);
byte[] expected = VendorRequests.BuildBuy(
gameActionSequence: 1,
vendorGuid: 0x40001000u,
amount: 3,
itemGuid: 0x50002000u,
alternateCurrencyId: 0u);
Assert.NotNull(captured);
Assert.Equal(expected, captured);
}
[Fact]
public void SendBuy_IncrementsTheSharedGameActionSequenceLikeEveryOtherSend()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendTalk("first"); // consumes sequence 1
session.SendBuy(0x40001000u, 0x50002000u, 1, 0u); // should be sequence 2
byte[] expected = VendorRequests.BuildBuy(
gameActionSequence: 2,
vendorGuid: 0x40001000u,
amount: 1,
itemGuid: 0x50002000u,
alternateCurrencyId: 0u);
Assert.Equal(expected, captured);
}
// ---- Slice 6b: the batched "Buy All" SendBuy overload -------------------
[Fact]
public void SendBuy_BatchedOverload_EmitsBytesIdenticalToVendorRequestsBuildBuyWithAList()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
var items = new (int Amount, uint ItemGuid)[]
{
(1, 0x50002000u),
(10, 0x50002001u),
};
session.SendBuy(0x40001000u, items, 0u);
byte[] expected = VendorRequests.BuildBuy(
gameActionSequence: 1,
vendorGuid: 0x40001000u,
items: items,
alternateCurrencyId: 0u);
Assert.NotNull(captured);
Assert.Equal(expected, captured);
}
// ---- Slice 6c: SendSell ---------------------------------------------
[Fact]
public void SendSell_EmitsBytesIdenticalToVendorRequestsBuildSell()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
var items = new (int Amount, uint ItemGuid)[] { (1, 0x50002000u) };
session.SendSell(0x40001000u, items);
byte[] expected = VendorRequests.BuildSell(
gameActionSequence: 1,
vendorGuid: 0x40001000u,
items: items);
Assert.NotNull(captured);
Assert.Equal(expected, captured);
}
[Fact]
public void SendSell_IncrementsTheSharedGameActionSequenceLikeEveryOtherSend()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendTalk("first"); // consumes sequence 1
var items = new (int Amount, uint ItemGuid)[] { (1, 0x50002000u) };
session.SendSell(0x40001000u, items); // should be sequence 2
byte[] expected = VendorRequests.BuildSell(
gameActionSequence: 2,
vendorGuid: 0x40001000u,
items: items);
Assert.Equal(expected, captured);
}
}