Example #1
0
        public void BinaryUDPPackageWriterTestMethod()
        {
            int _port = 35678;

            using (BinaryUDPPackageWriter _writer = new BinaryUDPPackageWriter("localhost", _port, new Helpers.UABinaryEncoderImplementation()))
            {
                Assert.AreEqual <int>(0, _writer.m_NumberOfSentBytes);
                Assert.AreEqual <int>(0, _writer.m_NumberOfAttachToNetwork);
                Assert.AreEqual <int>(0, _writer.m_NumberOfSentMessages);
                Assert.AreEqual <HandlerState>(HandlerState.Disabled, _writer.State.State);
                _writer.AttachToNetwork();
                Assert.AreEqual <HandlerState>(HandlerState.Operational, _writer.State.State);
                Assert.AreEqual <int>(1, _writer.m_NumberOfAttachToNetwork);
                Assert.AreEqual <int>(0, _writer.m_NumberOfSentBytes);
                Assert.AreEqual <int>(0, _writer.m_NumberOfSentMessages);
                ProducerBinding _binding = new ProducerBinding()
                {
                    Value = String.Empty
                };
                int          _sentItems        = 0;
                Guid         m_Guid            = CommonDefinitions.TestGuid;
                DataSelector _testDataSelector = new DataSelector()
                {
                    DataSetWriterId = CommonDefinitions.DataSetId, PublisherId = CommonDefinitions.TestGuid
                };
                ((IMessageWriter)_writer).Send((x) => { _binding.Value = CommonDefinitions.TestValues[x]; _sentItems++; return(_binding); },
                                               Convert.ToUInt16(CommonDefinitions.TestValues.Length),
                                               UInt64.MaxValue,
                                               FieldEncodingEnum.VariantFieldEncoding,
                                               _testDataSelector,
                                               0,
                                               CommonDefinitions.TestMinimalDateTime, new ConfigurationVersionDataType()
                {
                    MajorVersion = 0, MinorVersion = 0
                }
                                               );
                Assert.AreEqual(CommonDefinitions.TestValues.Length, _sentItems);
                Assert.AreEqual <int>(1, _writer.m_NumberOfAttachToNetwork);
                Assert.AreEqual <int>(115, _writer.m_NumberOfSentBytes);
                Assert.AreEqual <int>(1, _writer.m_NumberOfSentMessages);
                byte[] _shouldBeInBuffer = CommonDefinitions.GetTestBinaryArrayVariant4Consumer();
                byte[] _outputBuffer     = _writer.DoUDPRead();
                CollectionAssert.AreEqual(_outputBuffer, _shouldBeInBuffer);
            }
        }
 public void BinaryUDPPackageWriterTestMethod()
 {
     int _port = 35678;
       using (BinaryUDPPackageWriter _writer = new BinaryUDPPackageWriter("localhost", _port, new Helpers.UABinaryEncoderImplementation()))
       {
     Assert.AreEqual<int>(0, _writer.m_NumberOfSentBytes);
     Assert.AreEqual<int>(0, _writer.m_NumberOfAttachToNetwork);
     Assert.AreEqual<int>(0, _writer.m_NumberOfSentMessages);
     Assert.AreEqual<HandlerState>(HandlerState.Disabled, _writer.State.State);
     _writer.AttachToNetwork();
     Assert.AreEqual<HandlerState>(HandlerState.Operational, _writer.State.State);
     Assert.AreEqual<int>(1, _writer.m_NumberOfAttachToNetwork);
     Assert.AreEqual<int>(0, _writer.m_NumberOfSentBytes);
     Assert.AreEqual<int>(0, _writer.m_NumberOfSentMessages);
     ProducerBinding _binding = new ProducerBinding() { Value = String.Empty };
     int _sentItems = 0;
     Guid m_Guid = CommonDefinitions.TestGuid;
     DataSelector _testDataSelector = new DataSelector() { DataSetWriterId = CommonDefinitions.DataSetId, PublisherId = CommonDefinitions.TestGuid  };
     ((IMessageWriter)_writer).Send((x) => { _binding.Value = CommonDefinitions.TestValues[x]; _sentItems++; return _binding; },
                                 Convert.ToUInt16(CommonDefinitions.TestValues.Length),
                                 UInt64.MaxValue,
                                 FieldEncodingEnum.VariantFieldEncoding,
                                 _testDataSelector,
                                 0,
                                 CommonDefinitions.TestMinimalDateTime, new ConfigurationVersionDataType() { MajorVersion = 0, MinorVersion = 0 }
                                );
     Assert.AreEqual(CommonDefinitions.TestValues.Length, _sentItems);
     Assert.AreEqual<int>(1, _writer.m_NumberOfAttachToNetwork);
     Assert.AreEqual<int>(115, _writer.m_NumberOfSentBytes);
     Assert.AreEqual<int>(1, _writer.m_NumberOfSentMessages);
     byte[] _shouldBeInBuffer = CommonDefinitions.GetTestBinaryArrayVariant4Consumer();
     byte[] _outputBuffer = _writer.DoUDPRead();
     CollectionAssert.AreEqual(_outputBuffer, _shouldBeInBuffer);
       }
 }