using LanTian_Sinopec_PumpIcCardReader; using Microsoft.Extensions.DependencyInjection; using Microsoft.VisualStudio.TestTools.UnitTesting; using Edge.Core.Parser.BinaryParser.Util; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; namespace LanTian_Sinopec_PumpIcCardReader_Test { [TestClass] public class MessageTests { public static bool ValueEquals(IEnumerable array1, IEnumerable array2) { if (array1 == null && array2 == null) { return true; } if ((array1 == null) || (array2 == null)) { return false; } if (array1.Count() != array2.Count()) { return false; } if (array1.Equals(array2)) { return true; } else { for (int Index = 0; Index < array1.Count(); Index++) { if (!Equals(array1.ElementAt(Index), array2.ElementAt(Index))) { return false; } } } return true; } [TestMethod] public void PcGenericInquiryRequest_TestMethod1() { var expect = "30 20190918133637 00C4 78 C2 A8 01 C2 00 00 45 6D".ToBytes(); var request = new PcGenericInquiryRequest { PC_TIME = DateTime.ParseExact("20190918133637", "yyyyMMddHHmmss", new CultureInfo("zh-CN")),//; new DateTime(2019, 9, 18, 13, 36, 37), BL_VER = 0xC4, ADD_BL_VER = 0x78, DEL_BL_VER = 0xC2, WH_VER = 0xA8, PRC_VER = 0x01, Sta_VER = 0xC2, SELF_D_VER = 0x00, SOFT_FLAG = 0x00 }; var parser = new LanTian_Sinopec_PumpIcCardReader.Parser(); var actual = parser.Serialize(request); Assert.AreEqual(true, ValueEquals(expect.Take(expect.Length - 2), actual.Skip(6).Take(actual.Length - 6 - 2))); } //[TestMethod] //public void PumpRealTimeStateResponse_TestMethod1() //{ // var raw = "FA 00 03 5E 00 24 31 02020000708F002585012C00000001000004D17B460102108BF1".ToBytes(); // var parser = new LanTian_Sinopec_PumpIcCardReader.Parser(); // var actual = parser.Deserialize(raw) as PumpRealTimeStateResponse; // Assert.AreEqual(true, actual != null); //} } }