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.

92 lines
3.8 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_0x9206Test
  13. {
  14. JT808Serializer JT808Serializer;
  15. public JT808_0x9206Test()
  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_0x9206 jT808_0x9206 = new JT808_0x9206()
  38. {
  39. AlarmFlag=1,
  40. AVResourceType=2,
  41. BeginTime= Convert.ToDateTime("2019-07-16 10:10:10"),
  42. EndTime= Convert.ToDateTime("2019-07-16 10:10:11"),
  43. LogicChannelNo=3,
  44. StreamType =5,
  45. FileUploadPath ="D://1112",
  46. FileUploadPathLength=8,
  47. MemoryPositon=4,
  48. Password="123456",
  49. PasswordLength=6,
  50. Port=808,
  51. ServerIp="127.0.0.1",
  52. ServerIpLength=9,
  53. TaskExcuteCondition=7,
  54. UserName="tk",
  55. UserNameLength=2
  56. };
  57. var hex = JT808Serializer.Serialize(jT808_0x9206).ToHexString();
  58. Assert.Equal("093132372E302E302E31032802746B0631323334353608443A2F2F31313132031907161010101907161010110000000102050407", hex);
  59. }
  60. [Fact]
  61. public void Test2()
  62. {
  63. var jT808_0x9206 = JT808Serializer.Deserialize<JT808_0x9206>("093132372E302E302E31032802746B0631323334353608443A2F2F31313132031907161010101907161010110000000102050407".ToHexBytes());
  64. Assert.Equal(1u, jT808_0x9206.AlarmFlag);
  65. Assert.Equal(2, jT808_0x9206.AVResourceType);
  66. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:10"), jT808_0x9206.BeginTime);
  67. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:11"), jT808_0x9206.EndTime);
  68. Assert.Equal(3, jT808_0x9206.LogicChannelNo);
  69. Assert.Equal(5, jT808_0x9206.StreamType);
  70. Assert.Equal("D://1112", jT808_0x9206.FileUploadPath);
  71. Assert.Equal(8, jT808_0x9206.FileUploadPathLength);
  72. Assert.Equal(4, jT808_0x9206.MemoryPositon);
  73. Assert.Equal("123456", jT808_0x9206.Password);
  74. Assert.Equal(6, jT808_0x9206.PasswordLength);
  75. Assert.Equal(808, jT808_0x9206.Port);
  76. Assert.Equal("127.0.0.1", jT808_0x9206.ServerIp);
  77. Assert.Equal(9, jT808_0x9206.ServerIpLength);
  78. Assert.Equal(7, jT808_0x9206.TaskExcuteCondition);
  79. Assert.Equal("tk", jT808_0x9206.UserName);
  80. Assert.Equal(2, jT808_0x9206.UserNameLength);
  81. }
  82. [Fact]
  83. public void Test3()
  84. {
  85. var jT808_0x9206 = JT808Serializer.Analyze<JT808_0x9206>("093132372E302E302E31032802746B0631323334353608443A2F2F31313132031907161010101907161010110000000102050407".ToHexBytes());
  86. }
  87. }
  88. }