diff --git a/src/JT809.Protocol.Test/AnalyzeTest.cs b/src/JT809.Protocol.Test/AnalyzeTest.cs index 7f75239..cad3a73 100644 --- a/src/JT809.Protocol.Test/AnalyzeTest.cs +++ b/src/JT809.Protocol.Test/AnalyzeTest.cs @@ -209,7 +209,7 @@ namespace JT809.Protocol.Test hex = "00160000002100"; json = JT809_2019_Serializer.Analyze(hex.ToHexBytes()); - hex = "02736D616C6C6368690000000000000D10000000057265706C79"; + hex = "00000D10000000057265706C79"; json = JT809Serializer.Analyze(hex.ToHexBytes()); hex = "00616664617366330000000000000004D200000014CFC2BCB6C6BDCCA8CBF9CAF4B5A5D2BBC6BDCCA8"; diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs index 1410a8e..e88abec 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs @@ -8,37 +8,73 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using Xunit.Abstractions; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9300_0x9301Test { private JT809Serializer JT809Serializer = new JT809Serializer(); - [Fact] + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); + readonly ITestOutputHelper testOutput; + + public JT809_0x9300_0x9301Test(ITestOutputHelper testOutput) + { + this.testOutput = testOutput; + } + + [Fact(DisplayName = "2011版序列化")] public void Test1() { JT809_0x9300_0x9301 jT809_0x9300_0x9301 = new JT809_0x9300_0x9301 { - ObjectID="smallchi", - ObjectType= JT809_0x9301_ObjectType.下级平台所属单一业户, - InfoContent="reply", + ObjectID = "smallchi", + ObjectType = JT809_0x9301_ObjectType.下级平台所属单一业户, + InfoContent = "reply", InfoID = 3344, }; var hex = JT809Serializer.Serialize(jT809_0x9300_0x9301).ToHexString(); + testOutput.WriteLine(hex); // "02 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 0D 10 00 00 00 05 72 65 70 6C 79" - Assert.Equal("02736D616C6C6368690000000000000D10000000057265706C79", hex); + Assert.Equal("00000D10000000057265706C79", hex); } - [Fact] + [Fact(DisplayName = "2011版反序化")] public void Test2() { - var bytes = "02 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 0D 10 00 00 00 05 72 65 70 6C 79".ToHexBytes(); + var bytes = "00000D10000000057265706C79".ToHexBytes(); JT809_0x9300_0x9301 jT809_0x9300_0x9301 = JT809Serializer.Deserialize(bytes); + //Assert.Equal(JT809_0x9301_ObjectType.下级平台所属单一业户, jT809_0x9300_0x9301.ObjectType); + Assert.Equal((uint)3344, jT809_0x9300_0x9301.InfoID); + Assert.Equal("reply", jT809_0x9300_0x9301.InfoContent); + //Assert.Equal("smallchi", jT809_0x9300_0x9301.ObjectID); + } + + [Fact(DisplayName = "2019版序列化")] + public void Test3() + { + JT809_0x9300_0x9301 jT809_0x9300_0x9301 = new JT809_0x9300_0x9301 + { + ObjectID = "smallchi", + ObjectType = JT809_0x9301_ObjectType.下级平台所属单一业户, + InfoContent = "reply", + InfoID = 3344, + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0x9300_0x9301).ToHexString(); + testOutput.WriteLine(hex); + Assert.Equal("02736D616C6C636869000000000000000D10000000057265706C79", hex); + } + + [Fact(DisplayName = "2019版反序化")] + public void Test4() + { + var bytes = "02736D616C6C636869000000000000000D10000000057265706C79".ToHexBytes(); + JT809_0x9300_0x9301 jT809_0x9300_0x9301 = JT809_2019_Serializer.Deserialize(bytes); Assert.Equal(JT809_0x9301_ObjectType.下级平台所属单一业户, jT809_0x9300_0x9301.ObjectType); Assert.Equal((uint)3344, jT809_0x9300_0x9301.InfoID); Assert.Equal("reply", jT809_0x9300_0x9301.InfoContent); Assert.Equal("smallchi", jT809_0x9300_0x9301.ObjectID); } - } }