public void UnserialiseStringToObject() { var ReadCardJSON = @"{ ""headers"":{ ""name"":""CardReader.ReadRawData"", ""requestId"":""b34800d0-9dd2-4d50-89ea-92d1b13df54b"", ""type"":""command"" }, ""payload"":{ ""timeout"":5000, ""track1"":true, ""track2"": true, ""track3"":true, ""chip"":true, ""security"":true, ""fluxInactive"":true, ""watermark"":true, ""memoryChip"":true, ""track1Front"":true, ""frontImage"":true, ""backImage"":true, ""track1JIS"":true, ""track3JIS"":true, ""ddi"":true } }"; var assemblyName = Assembly.GetAssembly(typeof(ReadRawDataCommand))?.GetName(); IsNotNull(assemblyName); var decoder = new MessageDecoder(MessageDecoder.AutoPopulateType.Command, assemblyName) { { typeof(ReadRawDataCommand) } }; bool rc = decoder.TryUnserialise(ReadCardJSON, out object resultMessage); IsTrue(rc); IsNotNull(resultMessage); Command <ReadRawDataCommand.PayloadData> result = resultMessage as Command <ReadRawDataCommand.PayloadData> ?? throw new Exception(); IsNotNull(result); IsInstanceOfType(result, typeof(ReadRawDataCommand)); ReadRawDataCommand readCardCommand = result as ReadRawDataCommand; IsNotNull(readCardCommand); IsNotNull(readCardCommand.Payload); ReadRawDataCommand.PayloadData readCardPayload = readCardCommand.Payload as ReadRawDataCommand.PayloadData; IsNotNull(readCardPayload); AreEqual(true, readCardPayload.Track1); }
public async Task <ReadRawDataCompletion.PayloadData> ReadRawData(ICardReaderConnection connection, ReadRawDataCommand.PayloadData payload, CancellationToken cancellation) { await Task.Delay(2000, cancellation); connection.MediaInsertedEvent(); await Task.Delay(1000, cancellation); MediaStatus = StatusCompletion.PayloadData.CardReaderClass.MediaEnum.Present; return(new ReadRawDataCompletion.PayloadData(MessagePayload.CompletionCodeEnum.Success, "ok", null, new ReadRawDataCompletion.PayloadData.Track1Class(ReadRawDataCompletion.PayloadData.Track1Class.StatusEnum.Ok, "B1234567890123456^SMITH/JOHN.MR^020945852301200589800568000000"), new ReadRawDataCompletion.PayloadData.Track2Class(ReadRawDataCompletion.PayloadData.Track2Class.StatusEnum.Ok, "1234567890123456=0209458523012005898"), new ReadRawDataCompletion.PayloadData.Track3Class(ReadRawDataCompletion.PayloadData.Track3Class.StatusEnum.Ok, "011234567890123456==000667788903609640040000006200013010000020000098120209105123==00568000999999"))); }