Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

82 rader
3.3 KiB

  1. using JT808.Protocol.Extensions.JT1078.MessageBody;
  2. using JT808.Protocol.Interfaces;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using Xunit;
  8. using Microsoft.Extensions.Logging;
  9. using Newtonsoft.Json;
  10. namespace JT808.Protocol.Extensions.JT1078.Test
  11. {
  12. public class JT808_0x9201Test
  13. {
  14. JT808Serializer JT808Serializer;
  15. public JT808_0x9201Test()
  16. {
  17. IServiceCollection serviceDescriptors1 = new ServiceCollection();
  18. serviceDescriptors1
  19. .AddJT808Configure()
  20. .AddJT1078Configure();
  21. var ServiceProvider1 = serviceDescriptors1.BuildServiceProvider();
  22. var defaultConfig = ServiceProvider1.GetRequiredService<IJT808Config>();
  23. JT808Serializer = defaultConfig.GetSerializer();
  24. Newtonsoft.Json.JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
  25. {
  26. //日期类型默认格式化处理
  27. return new Newtonsoft.Json.JsonSerializerSettings
  28. {
  29. DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat,
  30. DateFormatString = "yyyy-MM-dd HH:mm:ss"
  31. };
  32. });
  33. }
  34. [Fact]
  35. public void Test1()
  36. {
  37. JT808_0x9201 jT808_0x9201 = new JT808_0x9201()
  38. {
  39. LogicChannelNo = 1,
  40. AVItemType = 2,
  41. BeginTime = Convert.ToDateTime("2019-07-16 10:10:10"),
  42. EndTime = Convert.ToDateTime("2019-07-16 10:10:10"),
  43. FastForwardOrFastRewindMultiples=3,
  44. MemType=5,
  45. PlayBackWay=6,
  46. ServerIp="127.0.0.1",
  47. ServerIpLength=9,
  48. StreamType=7,
  49. TcpPort=80,
  50. UdpPort=8080
  51. };
  52. var hex = JT808Serializer.Serialize(jT808_0x9201).ToHexString();
  53. Assert.Equal("093132372E302E302E3100501F90010207050603190716101010190716101010", hex);
  54. }
  55. [Fact]
  56. public void Test2()
  57. {
  58. var jT808_0x9201 = JT808Serializer.Deserialize<JT808_0x9201>("093132372E302E302E3100501F90010207050603190716101010190716101010".ToHexBytes());
  59. Assert.Equal(1, jT808_0x9201.LogicChannelNo);
  60. Assert.Equal(2, jT808_0x9201.AVItemType);
  61. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:10"), jT808_0x9201.BeginTime);
  62. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:10"), jT808_0x9201.EndTime);
  63. Assert.Equal(3, jT808_0x9201.FastForwardOrFastRewindMultiples);
  64. Assert.Equal(5, jT808_0x9201.MemType);
  65. Assert.Equal(6, jT808_0x9201.PlayBackWay);
  66. Assert.Equal("127.0.0.1", jT808_0x9201.ServerIp);
  67. Assert.Equal(9, jT808_0x9201.ServerIpLength);
  68. Assert.Equal(7, jT808_0x9201.StreamType);
  69. Assert.Equal(80, jT808_0x9201.TcpPort);
  70. Assert.Equal(8080, jT808_0x9201.UdpPort);
  71. }
  72. [Fact]
  73. public void Test3()
  74. {
  75. var jT808_0x9201 = JT808Serializer.Analyze<JT808_0x9201>("093132372E302E302E3100501F90010207050603190716101010190716101010".ToHexBytes());
  76. }
  77. }
  78. }