Reformat / cleanup
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 56s

This commit is contained in:
Joseph Doherty
2026-02-21 08:10:36 -05:00
parent 4c6aaa5a3f
commit a70d8befae
176 changed files with 50555 additions and 49587 deletions

View File

@@ -1,6 +1,5 @@
using ZB.MOM.WW.CBDD.Bson;
using Xunit;
using System.Collections.Concurrent;
using ZB.MOM.WW.CBDD.Bson;
namespace ZB.MOM.WW.CBDD.Tests;
@@ -10,13 +9,17 @@ public class BsonSpanReaderWriterTests
private readonly ConcurrentDictionary<ushort, string> _keys = new();
/// <summary>
/// Initializes a new instance of the <see cref="BsonSpanReaderWriterTests"/> class.
/// Initializes a new instance of the <see cref="BsonSpanReaderWriterTests" /> class.
/// </summary>
public BsonSpanReaderWriterTests()
{
ushort id = 1;
string[] initialKeys = ["name", "age", "active", "_id", "val", "dec", "timestamp", "int32", "int64", "double", "data", "child", "value", "0", "1"];
foreach (var key in initialKeys)
string[] initialKeys =
[
"name", "age", "active", "_id", "val", "dec", "timestamp", "int32", "int64", "double", "data", "child",
"value", "0", "1"
];
foreach (string key in initialKeys)
{
_keyMap[key] = id;
_keys[id] = key;
@@ -25,7 +28,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests write and read simple document.
/// Tests write and read simple document.
/// </summary>
[Fact]
public void WriteAndRead_SimpleDocument()
@@ -33,7 +36,7 @@ public class BsonSpanReaderWriterTests
Span<byte> buffer = stackalloc byte[256];
var writer = new BsonSpanWriter(buffer, _keyMap);
var sizePos = writer.BeginDocument();
int sizePos = writer.BeginDocument();
writer.WriteString("name", "John");
writer.WriteInt32("age", 30);
writer.WriteBoolean("active", true);
@@ -42,29 +45,29 @@ public class BsonSpanReaderWriterTests
var documentBytes = buffer[..writer.Position];
var reader = new BsonSpanReader(documentBytes, _keys);
var size = reader.ReadDocumentSize();
int size = reader.ReadDocumentSize();
size.ShouldBe(writer.Position);
var type1 = reader.ReadBsonType();
var name1 = reader.ReadElementHeader();
var value1 = reader.ReadString();
string name1 = reader.ReadElementHeader();
string value1 = reader.ReadString();
type1.ShouldBe(BsonType.String);
name1.ShouldBe("name");
value1.ShouldBe("John");
var type2 = reader.ReadBsonType();
var name2 = reader.ReadElementHeader();
var value2 = reader.ReadInt32();
string name2 = reader.ReadElementHeader();
int value2 = reader.ReadInt32();
type2.ShouldBe(BsonType.Int32);
name2.ShouldBe("age");
value2.ShouldBe(30);
var type3 = reader.ReadBsonType();
var name3 = reader.ReadElementHeader();
var value3 = reader.ReadBoolean();
string name3 = reader.ReadElementHeader();
bool value3 = reader.ReadBoolean();
type3.ShouldBe(BsonType.Boolean);
name3.ShouldBe("active");
@@ -72,7 +75,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests write and read object id.
/// Tests write and read object id.
/// </summary>
[Fact]
public void WriteAndRead_ObjectId()
@@ -82,7 +85,7 @@ public class BsonSpanReaderWriterTests
var oid = ObjectId.NewObjectId();
var sizePos = writer.BeginDocument();
int sizePos = writer.BeginDocument();
writer.WriteObjectId("_id", oid);
writer.EndDocument(sizePos);
@@ -91,7 +94,7 @@ public class BsonSpanReaderWriterTests
reader.ReadDocumentSize();
var type = reader.ReadBsonType();
var name = reader.ReadElementHeader();
string name = reader.ReadElementHeader();
var readOid = reader.ReadObjectId();
type.ShouldBe(BsonType.ObjectId);
@@ -100,7 +103,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests read write double.
/// Tests read write double.
/// </summary>
[Fact]
public void ReadWrite_Double()
@@ -112,8 +115,8 @@ public class BsonSpanReaderWriterTests
var reader = new BsonSpanReader(buffer, _keys);
var type = reader.ReadBsonType();
var name = reader.ReadElementHeader();
var val = reader.ReadDouble();
string name = reader.ReadElementHeader();
double val = reader.ReadDouble();
type.ShouldBe(BsonType.Double);
name.ShouldBe("val");
@@ -121,7 +124,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests read write decimal128 round trip.
/// Tests read write decimal128 round trip.
/// </summary>
[Fact]
public void ReadWrite_Decimal128_RoundTrip()
@@ -129,13 +132,13 @@ public class BsonSpanReaderWriterTests
var buffer = new byte[256];
var writer = new BsonSpanWriter(buffer, _keyMap);
decimal original = 123456.789m;
var original = 123456.789m;
writer.WriteDecimal128("dec", original);
var reader = new BsonSpanReader(buffer, _keys);
var type = reader.ReadBsonType();
var name = reader.ReadElementHeader();
var val = reader.ReadDecimal128();
string name = reader.ReadElementHeader();
decimal val = reader.ReadDecimal128();
type.ShouldBe(BsonType.Decimal128);
name.ShouldBe("dec");
@@ -143,7 +146,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests write and read date time.
/// Tests write and read date time.
/// </summary>
[Fact]
public void WriteAndRead_DateTime()
@@ -156,7 +159,7 @@ public class BsonSpanReaderWriterTests
var expectedTime = new DateTime(now.Year, now.Month, now.Day,
now.Hour, now.Minute, now.Second, now.Millisecond, DateTimeKind.Utc);
var sizePos = writer.BeginDocument();
int sizePos = writer.BeginDocument();
writer.WriteDateTime("timestamp", expectedTime);
writer.EndDocument(sizePos);
@@ -165,7 +168,7 @@ public class BsonSpanReaderWriterTests
reader.ReadDocumentSize();
var type = reader.ReadBsonType();
var name = reader.ReadElementHeader();
string name = reader.ReadElementHeader();
var readTime = reader.ReadDateTime();
type.ShouldBe(BsonType.DateTime);
@@ -174,7 +177,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests write and read numeric types.
/// Tests write and read numeric types.
/// </summary>
[Fact]
public void WriteAndRead_NumericTypes()
@@ -182,7 +185,7 @@ public class BsonSpanReaderWriterTests
Span<byte> buffer = stackalloc byte[256];
var writer = new BsonSpanWriter(buffer, _keyMap);
var sizePos = writer.BeginDocument();
int sizePos = writer.BeginDocument();
writer.WriteInt32("int32", int.MaxValue);
writer.WriteInt64("int64", long.MaxValue);
writer.WriteDouble("double", 3.14159);
@@ -207,7 +210,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests write and read binary.
/// Tests write and read binary.
/// </summary>
[Fact]
public void WriteAndRead_Binary()
@@ -217,7 +220,7 @@ public class BsonSpanReaderWriterTests
byte[] testData = [1, 2, 3, 4, 5];
var sizePos = writer.BeginDocument();
int sizePos = writer.BeginDocument();
writer.WriteBinary("data", testData);
writer.EndDocument(sizePos);
@@ -226,8 +229,8 @@ public class BsonSpanReaderWriterTests
reader.ReadDocumentSize();
var type = reader.ReadBsonType();
var name = reader.ReadElementHeader();
var readData = reader.ReadBinary(out var subtype);
string name = reader.ReadElementHeader();
var readData = reader.ReadBinary(out byte subtype);
type.ShouldBe(BsonType.Binary);
name.ShouldBe("data");
@@ -236,7 +239,7 @@ public class BsonSpanReaderWriterTests
}
/// <summary>
/// Tests write and read nested document.
/// Tests write and read nested document.
/// </summary>
[Fact]
public void WriteAndRead_NestedDocument()
@@ -244,10 +247,10 @@ public class BsonSpanReaderWriterTests
Span<byte> buffer = stackalloc byte[512];
var writer = new BsonSpanWriter(buffer, _keyMap);
var rootSizePos = writer.BeginDocument();
int rootSizePos = writer.BeginDocument();
writer.WriteString("name", "Parent");
var childSizePos = writer.BeginDocument("child");
int childSizePos = writer.BeginDocument("child");
writer.WriteString("name", "Child");
writer.WriteInt32("value", 42);
writer.EndDocument(childSizePos);
@@ -256,7 +259,7 @@ public class BsonSpanReaderWriterTests
var documentBytes = buffer[..writer.Position];
var reader = new BsonSpanReader(documentBytes, _keys);
var rootSize = reader.ReadDocumentSize();
int rootSize = reader.ReadDocumentSize();
rootSize.ShouldBe(writer.Position);
@@ -276,4 +279,4 @@ public class BsonSpanReaderWriterTests
reader.ReadElementHeader().ShouldBe("value");
reader.ReadInt32().ShouldBe(42);
}
}
}