You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.2 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. FastForwardOrFastRewindMultiples1=3,
  44. FastForwardOrFastRewindMultiples2=4,
  45. MemType=5,
  46. PlayBackWay=6,
  47. ServerIp="127.0.0.1",
  48. ServerIpLength=9,
  49. StreamType=7,
  50. TcpPort=80,
  51. UdpPort=8080
  52. };
  53. var hex = JT808Serializer.Serialize(jT808_0x9201).ToHexString();
  54. Assert.Equal("093132372E302E302E3100501F9001020705060304190716101010190716101010", hex);
  55. }
  56. [Fact]
  57. public void Test2()
  58. {
  59. var jT808_0x9201 = JT808Serializer.Deserialize<JT808_0x9201>("093132372E302E302E3100501F9001020705060304190716101010190716101010".ToHexBytes());
  60. Assert.Equal(1, jT808_0x9201.LogicChannelNo);
  61. Assert.Equal(2, jT808_0x9201.AVItemType);
  62. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:10"), jT808_0x9201.BeginTime);
  63. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:10"), jT808_0x9201.EndTime);
  64. Assert.Equal(3, jT808_0x9201.FastForwardOrFastRewindMultiples1);
  65. Assert.Equal(4, jT808_0x9201.FastForwardOrFastRewindMultiples2);
  66. Assert.Equal(5, jT808_0x9201.MemType);
  67. Assert.Equal(6, jT808_0x9201.PlayBackWay);
  68. Assert.Equal("127.0.0.1", jT808_0x9201.ServerIp);
  69. Assert.Equal(9, jT808_0x9201.ServerIpLength);
  70. Assert.Equal(7, jT808_0x9201.StreamType);
  71. Assert.Equal(80, jT808_0x9201.TcpPort);
  72. Assert.Equal(8080, jT808_0x9201.UdpPort);
  73. }
  74. }
  75. }