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.

66 lines
2.4 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_0x9202Test
  13. {
  14. JT808Serializer JT808Serializer;
  15. public JT808_0x9202Test()
  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_0x9202 jT808_0x9202 = new JT808_0x9202()
  38. {
  39. AVChannelNo=1,
  40. DragPlaybackPosition=Convert.ToDateTime("2019-07-16 10:10:10"),
  41. FastForwardOrFastRewindMultiples=2,
  42. PlayBackControl=3
  43. };
  44. var hex = JT808Serializer.Serialize(jT808_0x9202).ToHexString();
  45. Assert.Equal("010302190716101010", hex);
  46. }
  47. [Fact]
  48. public void Test2()
  49. {
  50. var jT808_0x9202 = JT808Serializer.Deserialize<JT808_0x9202>("010302190716101010".ToHexBytes());
  51. Assert.Equal(1, jT808_0x9202.AVChannelNo);
  52. Assert.Equal(Convert.ToDateTime("2019-07-16 10:10:10"), jT808_0x9202.DragPlaybackPosition);
  53. Assert.Equal(2, jT808_0x9202.FastForwardOrFastRewindMultiples);
  54. Assert.Equal(3, jT808_0x9202.PlayBackControl);
  55. }
  56. [Fact]
  57. public void Test3()
  58. {
  59. var jT808_0x9202 = JT808Serializer.Analyze<JT808_0x9202>("010302190716101010".ToHexBytes());
  60. }
  61. }
  62. }