ModernUO/Projects/Server.Tests/Tests/Buffers/ValueStringBuilderTests.cs
Kamron Batman 6f0e1a22f9
fix(core): Core cleanup, adds event loop synchronization, and fixes gumps (#429)
- [X] Cleans up gump packets
- [X] Adds event loop task synchronization
- [X] Moves timer pause and cleans up the delay task timer class
- [X] Cleans up the conserve cpu
- [X] Renames variables to make them consistent with the new style
- [X] Removes process delta recursion checking.
- [X] Properly diposes net states. This fixes edge cases that may cause hanging connections to stay open longer than they should.
- [X] Fixes an issue with gump items not compiling properly

Users can now utilize `Timer.Pause()` since the code will be executed on the proper thread.

```cs
public void async void Talk()
{
    _canTalk = false;
    await Timer.Pause(Utility.RandomMinMax(5000, 8000)); // Talk after 5-8 seconds
    DoTalk();
    await Timer.Pause(Utility.RandomMinMax(12000, 25000)); // Reset ability to talk after 12-25 seconds
    _canTalk = true;
}
```
2021-01-25 21:06:46 -08:00

34 lines
969 B
C#

using Server.Buffers;
using Xunit;
namespace Server.Tests.Buffers
{
public class ValueStringBuilderTests
{
[Theory]
[InlineData("Admin Kamron", "Kamron", 0, 6)]
[InlineData("Admin Kamron", "Admin ron", 6, 3)]
[InlineData("Admin Kamron", "Admin", 5, 7)]
public void TestRemove(string original, string removed, int startIndex, int length)
{
using var sb = new ValueStringBuilder(stackalloc char[64]);
sb.Append(original);
sb.Remove(startIndex, length);
Assert.Equal(removed, sb.ToString());
}
[Theory]
[InlineData(8)]
[InlineData(9876)]
[InlineData(-5)]
[InlineData(-130984209)]
public void TestAppendInt32(int value)
{
using var sb = new ValueStringBuilder(stackalloc char[64]);
sb.Append(value);
Assert.Equal(value.ToString(), sb.ToString());
}
}
}