Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thenameless314159/5eba29575e7bb64cf48ecd8e7bd7a410 to your computer and use it in GitHub Desktop.
Save thenameless314159/5eba29575e7bb64cf48ecd8e7bd7a410 to your computer and use it in GitHub Desktop.
public class CustomVarTests
{
private static readonly ISizing Sizing = new SizingBuilder()
.Register(new CustomVarInt16SizeStorage())
.Register(new CustomVarUInt16SizeStorage())
.Register(new CustomVarInt32SizeStorage())
.Register(new CustomVarUInt32SizeStorage())
.Register(new CustomVarInt64SizeStorage())
.Register(new CustomVarUInt64SizeStorage()).Build();
private static readonly IBinaryFactory BinaryFactory = new BinaryBuilder(Sizing, Endianness.BigEndian)
.Register(new CustomVarInt16BinaryStorage())
.Register(new CustomVarUInt16BinaryStorage())
.Register(new CustomVarInt32BinaryStorage())
.Register(new CustomVarUInt32BinaryStorage())
.Register(new CustomVarInt64BinaryStorage())
.Register(new CustomVarUInt64BinaryStorage()).Build();
[Fact]
public void Should_Read_Write_CustomInt16()
{
var cShort = new CustomVar<short>(16385);
var writer = BinaryFactory.Get(3);
writer.WriteValue(cShort);
var reader = BinaryFactory.Get(writer.GetBuffer());
var cShortRead = reader.ReadValue<CustomVar<short>>();
Assert.Equal(cShort.Value, cShortRead.Value);
}
[Fact]
public void Should_Read_Write_CustomUInt16()
{
var cUShort = new CustomVar<ushort>(16385);
var writer = BinaryFactory.Get(3);
writer.WriteValue(cUShort);
var reader = BinaryFactory.Get(writer.GetBuffer());
var cUShortRead = reader.ReadValue<CustomVar<ushort>>();
Assert.Equal(cUShort.Value, cUShortRead.Value);
}
[Fact]
public void Should_Read_Write_CustomInt32()
{
var cInt = new CustomVar<int>(2097156);
var writer = BinaryFactory.Get(5);
writer.WriteValue(cInt);
var reader = BinaryFactory.Get(writer.GetBuffer());
var cIntRead = reader.ReadValue<CustomVar<int>>();
Assert.Equal(cInt.Value, cIntRead.Value);
}
[Fact]
public void Should_Read_Write_CustomUInt32()
{
var cUInt = new CustomVar<uint>(2097155);
var writer = BinaryFactory.Get(5);
writer.WriteValue(cUInt);
var reader = BinaryFactory.Get(writer.GetBuffer());
var cUIntRead = reader.ReadValue<CustomVar<uint>>();
Assert.Equal(cUInt.Value, cUIntRead.Value);
}
[Theory,
InlineData(uint.MaxValue),
InlineData(long.MaxValue)]
public void Should_Read_Write_CustomInt64_With(long value)
{
var cLong = new CustomVar<long>(value);
var writer = BinaryFactory.Get(9);
writer.WriteValue(cLong);
var reader = BinaryFactory.Get(writer.GetBuffer());
var cLongRead = reader.ReadValue<CustomVar<long>>();
Assert.Equal(cLong.Value, cLongRead.Value);
}
[Theory,
InlineData(uint.MaxValue),
InlineData(long.MaxValue)]
public void Should_Read_Write_CustomUInt64_With(ulong value)
{
var cLong = new CustomVar<ulong>(value);
var writer = BinaryFactory.Get(10);
writer.WriteValue(cLong);
var reader = BinaryFactory.Get(writer.GetBuffer());
var cLongRead = reader.ReadValue<CustomVar<ulong>>();
Assert.Equal(cLong.Value, cLongRead.Value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment