ModernUO/Projects/Server.Tests/Tests/Network/Packets/Outgoing/VendorSellPacketTests.cs
Kamron Batman 10a69bf754
feat: Adds a memory mirrored ring buffer for networking. (#1533)
## Breaking Changes

Incoming packet registration signature has changed to:
```cs
delegate* void OnReceiveCallback(NetState state, SpanReader reader, int packetLength);

IncomingPackets.Register(int packetID, int length, bool ingame, OnReceiveCallback onReceive);
```

For example, an incoming packet handler signature would now look like this:
```cs
public static void SomeIncomingPacket(NetState state, SpanReader reader, int packetLength)
{
    // Parse the data
}
```

## Summary

Updates the network Pipe class to use a mirrored memory technique. This technique involves mapping the same physical memory to two contiguous virtual memory spaces so the byte buffer appears duplicated. This allows writing to a double-sized array to wrap around without the need for the `CircularBuffer` classes.

In practice this allows us to use `Span<byte>` as if the buffer was a regular array.


### Bug Fixes

- [X] Fixes bad fixed length string parsing
2023-10-09 00:57:53 -07:00

53 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Server.Network;
using Xunit;
namespace Server.Tests.Network
{
[Collection("Sequential Tests")]
public class VendorSellPacketTests : IClassFixture<ServerFixture>
{
[Fact]
public void TestVendorSellList()
{
var vendor = new Mobile((Serial)0x1024u);
vendor.DefaultMobileInit();
var item1 = new Item(World.NewItem);
var item2 = new Item(World.NewItem) { Name = "Second Item" };
var item3 = new Item(World.NewItem);
var sellStates = new HashSet<SellItemState>
{
new(item1, 100, "Item 1"),
new(item2, 100000, "Item 2"),
new(item3, 1, "Item 3")
};
var expected = new VendorSellList(vendor, sellStates.ToList()).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendVendorSellList(vendor.Serial, sellStates);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
[Fact]
public void TestEndVendorSell()
{
var vendor = new Mobile((Serial)0x1024u);
vendor.DefaultMobileInit();
var expected = new EndVendorBuy(vendor.Serial).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendEndVendorSell(vendor.Serial);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}
}