MessageTests.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using LanTian_Sinopec_PumpIcCardReader;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Edge.Core.Parser.BinaryParser.Util;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Linq;
  9. namespace LanTian_Sinopec_PumpIcCardReader_Test
  10. {
  11. [TestClass]
  12. public class MessageTests
  13. {
  14. public static bool ValueEquals(IEnumerable<byte> array1, IEnumerable<byte> array2)
  15. {
  16. if (array1 == null && array2 == null)
  17. {
  18. return true;
  19. }
  20. if ((array1 == null) || (array2 == null))
  21. {
  22. return false;
  23. }
  24. if (array1.Count() != array2.Count())
  25. {
  26. return false;
  27. }
  28. if (array1.Equals(array2))
  29. {
  30. return true;
  31. }
  32. else
  33. {
  34. for (int Index = 0; Index < array1.Count(); Index++)
  35. {
  36. if (!Equals(array1.ElementAt(Index), array2.ElementAt(Index)))
  37. {
  38. return false;
  39. }
  40. }
  41. }
  42. return true;
  43. }
  44. [TestMethod]
  45. public void PcGenericInquiryRequest_TestMethod1()
  46. {
  47. var expect = "30 20190918133637 00C4 78 C2 A8 01 C2 00 00 45 6D".ToBytes();
  48. var request = new PcGenericInquiryRequest
  49. {
  50. PC_TIME = DateTime.ParseExact("20190918133637", "yyyyMMddHHmmss", new CultureInfo("zh-CN")),//; new DateTime(2019, 9, 18, 13, 36, 37),
  51. BL_VER = 0xC4,
  52. ADD_BL_VER = 0x78,
  53. DEL_BL_VER = 0xC2,
  54. WH_VER = 0xA8,
  55. PRC_VER = 0x01,
  56. Sta_VER = 0xC2,
  57. SELF_D_VER = 0x00,
  58. SOFT_FLAG = 0x00
  59. };
  60. var parser = new LanTian_Sinopec_PumpIcCardReader.Parser();
  61. var actual = parser.Serialize(request);
  62. Assert.AreEqual(true, ValueEquals(expect.Take(expect.Length - 2), actual.Skip(6).Take(actual.Length - 6 - 2)));
  63. }
  64. //[TestMethod]
  65. //public void PumpRealTimeStateResponse_TestMethod1()
  66. //{
  67. // var raw = "FA 00 03 5E 00 24 31 02020000708F002585012C00000001000004D17B460102108BF1".ToBytes();
  68. // var parser = new LanTian_Sinopec_PumpIcCardReader.Parser();
  69. // var actual = parser.Deserialize(raw) as PumpRealTimeStateResponse;
  70. // Assert.AreEqual(true, actual != null);
  71. //}
  72. }
  73. }