コード例 #1
0
            // Commented because AxoCover does not respect Ignore and Explicit attributes.
            //[Test, Explicit("Integration test. Only valid if a modem/phone is connected.")]
            public void TestPhysicalPort()
            {
                var serialPort = new SystemSerialPort();
                var manager    = new SmsManager(serialPort);

                manager.OpenPort("COM9", 9600, 8, 300, 300);
                var result = manager.ExecCommand(serialPort, "AT", 300, "No phone connected");

                manager.ClosePort(serialPort);

                // Since ATE1 is the default the AT command is echoed back.
                Assert.AreEqual("AT\r\r\nOK\r\n", result);
            }
コード例 #2
0
            public void SuccessfullyExecutes()
            {
                // https://stackoverflow.com/questions/7582087/how-to-mock-serialdatareceivedeventargs
                var constructor = typeof(SerialDataReceivedEventArgs).GetConstructor(
                    BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(SerialData) }, null);
                var eventArgs = (SerialDataReceivedEventArgs)constructor.Invoke(new object[] { SerialData.Chars });

                //_serialPort.When(sp => sp.ReadExisting().Returns("\r\nOK\r\n")).Do(sp => _serialPort.DataReceived += Raise.Event<SerialDataReceivedEventHandler>(eventArgs));
                _serialPort.When(sp => sp.Write(Arg.Any <string>())).Do(sp => _serialPort.DataReceived += Raise.Event <SerialDataReceivedEventHandler>(eventArgs));

                //_serialPort.When(call => call.Write(Arg.Any<string>())); //.Do(callback => { throw new IOException(); });
                _serialPort.ReadExisting().Returns("\r\nOK\r\n");
                var manager = new SmsManager(_serialPort);

                manager.OpenPort("COM2", 9600, 8, 300, 300);
                //_serialPort.DataReceived += Raise.Event<SerialDataReceivedEventHandler>(eventArgs);
                var result = manager.ExecCommand(_serialPort, "AT", 300, "No phone connected");

                manager.ClosePort(_serialPort);

                Assert.AreEqual(result, "\r\nOK\r\n");
            }