Skip to content

Commit

Permalink
fix Test
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 12, 2024
1 parent c2c4bd1 commit 77dfd1f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions XUnitTest/JsonEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void CreateRequest()
// 简洁请求
{
var req = encoder.CreateRequest(name, null);
var pk = (ArrayPacket)req.Payload;
var pk = (OwnerPacket)req.Payload;
Assert.Equal(1 + name.Length, pk.Total);
Assert.Null(pk.Next);
Assert.Equal(8, pk.Offset);
Expand Down Expand Up @@ -178,14 +178,14 @@ public void CreateRequestWithEmptyArgs()
{
var args = new Object();
var req = encoder.CreateRequest(name, args);
var pk = (ArrayPacket)req.Payload;
var pk = (OwnerPacket)req.Payload;
Assert.Equal(1 + name.Length + 4 + args.ToJson().Length, pk.Total);
Assert.NotNull(pk.Next);
Assert.Equal(8, pk.Offset);

// 拷贝一次,拉平。因为SpanReader不支持跨包读取
pk = (ArrayPacket)req.Payload.ToArray();
var reader = new SpanReader(pk.GetSpan());
var pk2 = (ArrayPacket)req.Payload.ToArray();
var reader = new SpanReader(pk2.GetSpan());

Assert.Equal(name, reader.ReadString());

Expand Down Expand Up @@ -219,7 +219,7 @@ public void CreateRequestFull()
{
var args = new UserInfo { Name = "Stone", Age = 18 };
var req = encoder.CreateRequest(name, args);
var pk = (ArrayPacket)req.Payload;
var pk = (OwnerPacket)req.Payload;
Assert.Equal(1 + name.Length + 4 + args.ToJson().Length, pk.Total);
Assert.NotNull(pk.Next);
Assert.Equal(8, pk.Offset);
Expand Down Expand Up @@ -258,7 +258,7 @@ public void CreateResponse()
{
// 错误码200等同于0,表示成功
var res = encoder.CreateResponse(req, name, 200, null);
var pk = (ArrayPacket)res.Payload;
var pk = (OwnerPacket)res.Payload;
Assert.Equal(1 + name.Length, pk.Total);
Assert.Null(pk.Next);
Assert.Equal(8, pk.Offset);
Expand Down Expand Up @@ -296,14 +296,14 @@ public void CreateResponseWithError()
{
var value = "this is an error message";
var res = encoder.CreateResponse(req, name, 500, value);
var pk = (ArrayPacket)res.Payload;
var pk = (OwnerPacket)res.Payload;
Assert.Equal(1 + name.Length + 4 + 4 + value.Length, pk.Total);
Assert.NotNull(pk.Next);
Assert.Equal(8, pk.Offset);

// 拷贝一次,拉平。因为SpanReader不支持跨包读取
pk = (ArrayPacket)pk.ToArray();
var reader = new SpanReader(pk.GetSpan());
var pk2 = (ArrayPacket)pk.ToArray();
var reader = new SpanReader(pk2.GetSpan());

Assert.Equal(name, reader.ReadString());
Assert.Equal(500, reader.ReadInt32());
Expand Down Expand Up @@ -340,14 +340,14 @@ public void CreateResponseFull()
{
var value = new UserInfo { Name = "Stone", Age = 18 };
var res = encoder.CreateResponse(req, name, 0, value);
var pk = (ArrayPacket)res.Payload;
var pk = (OwnerPacket)res.Payload;
Assert.Equal(1 + name.Length + 4 + value.ToJson().Length, pk.Total);
Assert.NotNull(pk.Next);
Assert.Equal(8, pk.Offset);

// 拷贝一次,拉平。因为SpanReader不支持跨包读取
pk = (ArrayPacket)pk.ToArray();
var reader = new SpanReader(pk.GetSpan());
var pk2 = (ArrayPacket)pk.ToArray();
var reader = new SpanReader(pk2.GetSpan());

Assert.Equal(name, reader.ReadString());

Expand Down

0 comments on commit 77dfd1f

Please sign in to comment.