Пример #1
0
        public void Send_WhenReceiveNAK_2ndTime_ShouldTryAgain()
        {
            using (var stream = new RWStream())
                using (var sut = new StreamRawPinPad(stream))
                {
                    var payload       = Encoding.ASCII.GetBytes("OPN000");
                    var expectedBytes = new ByteArrayBuilder()
                                        .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e)
                                        .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e)
                                        .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e)
                                        .Add(Bytes.CAN)
                                        .ToArray();

                    Should.CompleteIn(async() =>
                    {
                        var taskSend = sut.SendRawMessageAsync(new RawRequestMessage(payload));
                        await Task.Delay(100);
                        stream.PushByteToRead(Bytes.NAK);
                        await Task.Delay(100);
                        stream.PushByteToRead(Bytes.NAK);
                        await taskSend;
                    }, TimeSpan.FromMilliseconds(100 + 100 + TimeoutMilliseconds + ToleranceMilliseconds));

                    stream.GetBytesWritten().ShouldBe(expectedBytes);
                }
        }
Пример #2
0
        public void Send_WhenDoesNotReceiveReplyAndTimeout_ShouldAddCANandAbort()
        {
            using (var stream = new RWStream())
                using (var sut = new StreamRawPinPad(stream))
                {
                    var payload       = Encoding.ASCII.GetBytes("OPN000");
                    var expectedBytes = new ByteArrayBuilder()
                                        .Add(Bytes.SYN).Add(payload).Add(Bytes.ETB).Add(0x77, 0x5e)
                                        .Add(Bytes.CAN)
                                        .ToArray();

                    Should.CompleteIn(async() =>
                    {
                        await sut.SendRawMessageAsync(new RawRequestMessage(payload));
                    }, TimeSpan.FromMilliseconds(TimeoutMilliseconds + ToleranceMilliseconds));

                    stream.GetBytesWritten().ShouldBe(expectedBytes);
                }
        }