Exemplo n.º 1
0
        private static void ReadHeaderInformation(NavData result, BinaryReader reader)
        {
            result._header  = reader.ReadUInt32();
            result._state   = reader.ReadInt32();
            result.Sequence = reader.ReadUInt32();
            result._vision  = reader.ReadUInt32();

            result.ValidateHeader();
        }
Exemplo n.º 2
0
        public static NavData FromBytes(byte[] buffer)
        {
            var result = new NavData();

            using (var stream = new MemoryStream(buffer))
                using (var reader = new BinaryReader(stream))
                {
                    ReadHeaderInformation(result, reader);

                    NavDataTag optionId;
                    do
                    {
                        optionId = (NavDataTag)reader.ReadUInt16();
                        ushort size = reader.ReadUInt16();
                        result.AddOption(optionId, size, reader);
                    } while (optionId != NavDataTag.Checksum);
                }

            result.ValidateChecksum(buffer);

            return(result);
        }
        public void OnSocketReceivedEvent_ReturnsInSequenceData_RaisesEvents()
        {
            // Arrange
            NavData.NavData navDataReceived = null;
            _target.NavDataReceived += (sender, args) => navDataReceived = args.NavData;

            var firstData = new NavData.NavData {
                Sequence = 1
            };
            var firstBytes = new byte[] { 1 };
            var firstDataReceivedEventArgs = new DataReceivedEventArgs(firstBytes);

            _mockNavDataFactory.Setup(x => x.Create(firstBytes)).Returns(firstData);

            var secondData = new NavData.NavData {
                Sequence = 2
            };
            var secondBytes = new byte[] { 2 };
            var secondDataReceivedEventArgs = new DataReceivedEventArgs(secondBytes);

            _mockNavDataFactory.Setup(x => x.Create(secondBytes)).Returns(secondData);

            _target.Run();

            // Act
            _mockUdpSocket.Raise(x => x.DataReceived += null, firstDataReceivedEventArgs);

            // Assert
            navDataReceived.Should().Be(firstData);

            // Act
            _mockUdpSocket.Raise(x => x.DataReceived += null, secondDataReceivedEventArgs);

            // Assert
            navDataReceived.Should().Be(secondData);
        }
 public NavDataReceivedEventArgs(NavData navData)
 {
     NavData = navData;
 }