public void ResponseReadValue()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            foreach (Medium_T _enumIdx in Enum.GetValues(typeof(Medium_T)))
            {
                using (SBUSNet_message _frame = new SBUSNet_message(null))
                {
                    Assert.IsNotNull(_frame, "Message is not created.");
                    BlockAddress _tb = new BlockAddress((short)_enumIdx, c_station, C_startAddress, C_RegistersCount);
                    _frame.Test_PrepareRequest(_tb.station, _tb);
                    List <byte> _frameList = _frame.GetManagedBuffer().ToList();
                    Assert.AreEqual(m_TestTable[_enumIdx].Count, _frame.userDataLength, "The length of the request is not valid");
                    string _msg = String.Format("Frame must be equal to the template. Failed for {0} ", _enumIdx);
                    m_TestTable[_enumIdx][7] = _frameList[7]; // sequence numbers must be the same
                    CollectionAssert.AreEqual(m_TestTable[_enumIdx], _frameList, _msg);
                    using (SBUSNet_message _dateFrame = new SBUSNet_message(null))
                    {
                        _dateFrame.InitMsg(_frame);
                        ushort _expectedFrameLength = c_HeaderLength + c_ATLength;
                        switch (_enumIdx)
                        {
                        case Medium_T.Flag:
                        case Medium_T.Input:
                        case Medium_T.Output:
                            _expectedFrameLength += (C_RegistersCount - 1) / 8 + 1; //<header><AT>{fio-count}+
                            CheckExpectedLength(_enumIdx, _dateFrame, _expectedFrameLength);
                            TestContent <bool>(_dateFrame, false, CompareType <bool>);
                            break;

                        case Medium_T.Register:
                        case Medium_T.Timer:
                        case Medium_T.Counter:
                            _expectedFrameLength += C_RegistersCount * 4;
                            CheckExpectedLength(_enumIdx, _dateFrame, _expectedFrameLength);
                            TestContent <int>(_dateFrame, 123, CompareType <int>);
                            break;

                        case Medium_T.Text:
                            _expectedFrameLength += C_RegistersCount;
                            CheckExpectedLength(_enumIdx, _dateFrame, _expectedFrameLength);
                            TestContent <string>(_dateFrame, "1234567890123".Substring(0, _tb.length), CompareString);
                            break;

                        default:
                            Assert.Fail("Application error: unknown requested data type");
                            break;
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void ResponseWriteValue()
        {
#if !DEBUG
            Assert.Inconclusive("This test requires DEBUG context");
#endif
            using (SBUSNet_message _frame = new SBUSNet_message(null))
            {
                Assert.IsNotNull(_frame, "Message is not created.");
                BlockAddress _tb = new BlockAddress((short)Medium_T.Text);
                _frame.Test_PrepareRequest(_tb.station, _tb);
                Assert.AreEqual(16, _frame.userDataLength, "The length of the request is not valid");
                using (SBUSNet_message _dateFrame = new SBUSNet_message(null))
                {
                    _dateFrame.InitMsg(_frame);
                    _dateFrame.WriteValue("sassasasa", 0);
                }
            }
        }