Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

81 řádky
3.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Xunit;
  5. using JT809.Protocol;
  6. using JT809.Protocol.Extensions;
  7. using JT809.Protocol.MessageBody;
  8. using JT809.Protocol.Exceptions;
  9. using JT809.Protocol.SubMessageBody;
  10. using JT809.Protocol.Enums;
  11. using Xunit.Abstractions;
  12. using JT809.Protocol.Internal;
  13. namespace JT809.Protocol.Test.JT809SubMessageBody
  14. {
  15. public class JT809_0x9300_0x9301Test
  16. {
  17. private JT809Serializer JT809Serializer = new JT809Serializer();
  18. private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 });
  19. readonly ITestOutputHelper testOutput;
  20. public JT809_0x9300_0x9301Test(ITestOutputHelper testOutput)
  21. {
  22. this.testOutput = testOutput;
  23. }
  24. [Fact(DisplayName = "2011版序列化")]
  25. public void Test1()
  26. {
  27. JT809_0x9300_0x9301 jT809_0x9300_0x9301 = new JT809_0x9300_0x9301
  28. {
  29. ObjectID = "smallchi",
  30. ObjectType = JT809_0x9301_ObjectType.下级平台所属单一业户,
  31. InfoContent = "reply",
  32. InfoID = 3344,
  33. };
  34. var hex = JT809Serializer.Serialize(jT809_0x9300_0x9301).ToHexString();
  35. testOutput.WriteLine(hex);
  36. // "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"
  37. Assert.Equal("00000D10000000057265706C79", hex);
  38. }
  39. [Fact(DisplayName = "2011版反序化")]
  40. public void Test2()
  41. {
  42. var bytes = "00000D10000000057265706C79".ToHexBytes();
  43. JT809_0x9300_0x9301 jT809_0x9300_0x9301 = JT809Serializer.Deserialize<JT809_0x9300_0x9301>(bytes);
  44. //Assert.Equal(JT809_0x9301_ObjectType.下级平台所属单一业户, jT809_0x9300_0x9301.ObjectType);
  45. Assert.Equal((uint)3344, jT809_0x9300_0x9301.InfoID);
  46. Assert.Equal("reply", jT809_0x9300_0x9301.InfoContent);
  47. //Assert.Equal("smallchi", jT809_0x9300_0x9301.ObjectID);
  48. }
  49. [Fact(DisplayName = "2019版序列化")]
  50. public void Test3()
  51. {
  52. JT809_0x9300_0x9301 jT809_0x9300_0x9301 = new JT809_0x9300_0x9301
  53. {
  54. ObjectID = "smallchi",
  55. ObjectType = JT809_0x9301_ObjectType.下级平台所属单一业户,
  56. InfoContent = "reply",
  57. InfoID = 3344,
  58. };
  59. var hex = JT809_2019_Serializer.Serialize(jT809_0x9300_0x9301).ToHexString();
  60. testOutput.WriteLine(hex);
  61. Assert.Equal("02736D616C6C6368690000000000000000000000000000000D10000000057265706C79", hex);
  62. }
  63. [Fact(DisplayName = "2019版反序化")]
  64. public void Test4()
  65. {
  66. var bytes = "02736D616C6C6368690000000000000000000000000000000D10000000057265706C79".ToHexBytes();
  67. JT809_0x9300_0x9301 jT809_0x9300_0x9301 = JT809_2019_Serializer.Deserialize<JT809_0x9300_0x9301>(bytes);
  68. Assert.Equal(JT809_0x9301_ObjectType.下级平台所属单一业户, jT809_0x9300_0x9301.ObjectType);
  69. Assert.Equal((uint)3344, jT809_0x9300_0x9301.InfoID);
  70. Assert.Equal("reply", jT809_0x9300_0x9301.InfoContent);
  71. Assert.Equal("smallchi", jT809_0x9300_0x9301.ObjectID);
  72. }
  73. }
  74. }