123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using ShellChina_EPS_Project_CarPlatePay_EpsClient_App.MessageEntity.Base;
- using System.Collections.Generic;
- using System.Linq;
- namespace ShellChina_EPS_Project_CarPlatePay_EpsClient_App_Test
- {
- [TestClass]
- public class MessageBaseUnitTest
- {
- public static bool ValueEquals(IEnumerable<byte> array1, IEnumerable<byte> 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 Serialize_TestMethod1()
- {
- MessageBase msg = new MessageBase();
- msg.TPDU = "3333";
- msg.MessageTypeIdentifier = 1234;
- msg.BitMap = new List<byte>() { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
- msg.Content = new List<byte>() { 0x99, 0x99 };
- var parser
- = new ShellChina_EPS_Project_CarPlatePay_EpsClient_App.Parser();
- var actual = parser.Serialize(msg);
- var expect = new List<byte>() {
- 0x00,0x11,
- 0x00,0x00,0x00,0x33,0x33,
- 0x12,0x34,
- 0x01,0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x99,0x99
- };
- Assert.AreEqual(true, ValueEquals(actual, expect),
- "expect: " + expect.Select(e => e.ToString("X2")).Aggregate((acc, n) => acc + " " + n)
- + "\r\n actual: " + actual.Select(e => e.ToString("X2")).Aggregate((acc, n) => acc + " " + n));
- }
- [TestMethod]
- public void Serialize_TestMethod2()
- {
- MessageBase msg = new MessageBase();
- msg.TPDU = "3333";
- msg.MessageTypeIdentifier = 1234;
- msg.BitMap = new List<byte>() { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
- msg.Content = new List<byte>() { 0x99, 0x99, 0x88, 0x88, 0x77, 0x77 };
- var parser
- = new ShellChina_EPS_Project_CarPlatePay_EpsClient_App.Parser();
- var actual = parser.Serialize(msg);
- var expect = new List<byte>() {
- 0x00,0x15,
- 0x00,0x00,0x00,0x33,0x33,
- 0x12,0x34,
- 0x01,0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x99,0x99, 0x88, 0x88, 0x77, 0x77
- };
- Assert.AreEqual(true, ValueEquals(actual, expect),
- "expect: " + expect.Select(e => e.ToString("X2")).Aggregate((acc, n) => acc + " " + n)
- + "\r\n actual: " + actual.Select(e => e.ToString("X2")).Aggregate((acc, n) => acc + " " + n));
- }
- [TestMethod]
- public void Serialize_TestMethod3()
- {
- MessageBase msg = new MessageBase();
- msg.TPDU = "1234563333";
- msg.MessageTypeIdentifier = 7890;
- msg.BitMap = new List<byte>() { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
- msg.Content = new List<byte>() { 0x99, 0x99, 0x88, 0x88, 0x77, 0x77 };
- var parser
- = new ShellChina_EPS_Project_CarPlatePay_EpsClient_App.Parser();
- var actual = parser.Serialize(msg);
- var expect = new List<byte>() {
- 0x00,0x15,
- 0x12,0x34,0x56,0x33,0x33,
- 0x78,0x90,
- 0x01,0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x99,0x99, 0x88, 0x88, 0x77, 0x77
- };
- Assert.AreEqual(true, ValueEquals(actual, expect),
- "expect: " + expect.Select(e => e.ToString("X2")).Aggregate((acc, n) => acc + " " + n)
- + "\r\n actual: " + actual.Select(e => e.ToString("X2")).Aggregate((acc, n) => acc + " " + n));
- }
- }
- }
|