public void ValidateMajorVersionEqMinorVersionEq( [Values(DataSetFieldContentMask.None, DataSetFieldContentMask.RawData, // list here all possible DataSetFieldContentMask DataSetFieldContentMask.ServerPicoSeconds, DataSetFieldContentMask.ServerTimestamp, DataSetFieldContentMask.SourcePicoSeconds, DataSetFieldContentMask.SourceTimestamp, DataSetFieldContentMask.StatusCode, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.SourcePicoSeconds, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.SourceTimestamp, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.StatusCode, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp | DataSetFieldContentMask.SourcePicoSeconds, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp | DataSetFieldContentMask.SourceTimestamp, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp | DataSetFieldContentMask.StatusCode, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp | DataSetFieldContentMask.SourcePicoSeconds | DataSetFieldContentMask.SourceTimestamp, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp | DataSetFieldContentMask.SourcePicoSeconds | DataSetFieldContentMask.StatusCode, DataSetFieldContentMask.ServerPicoSeconds | DataSetFieldContentMask.ServerTimestamp | DataSetFieldContentMask.SourcePicoSeconds | DataSetFieldContentMask.SourceTimestamp | DataSetFieldContentMask.StatusCode )] DataSetFieldContentMask dataSetFieldContentMask) { const int VersionValue = 2; // Arrange UadpDataSetMessage uadpDataSetMessage = GetFirstDataSetMessage(dataSetFieldContentMask); // Act uadpDataSetMessage.SetMessageContentMask(UadpDataSetMessageContentMask.MajorVersion | UadpDataSetMessageContentMask.MinorVersion); uadpDataSetMessage.MetaDataVersion.MajorVersion = VersionValue; uadpDataSetMessage.MetaDataVersion.MinorVersion = VersionValue * 10; IServiceMessageContext messageContextEncode = new ServiceMessageContext(); byte[] bytes; var memoryStream = new MemoryStream(); using (BinaryEncoder encoder = new BinaryEncoder(memoryStream, messageContextEncode, true)) { uadpDataSetMessage.Encode(encoder); _ = encoder.Close(); bytes = ReadBytes(memoryStream); } UadpDataSetMessage uaDataSetMessageDecoded = new UadpDataSetMessage(); BinaryDecoder decoder = new BinaryDecoder(bytes, messageContextEncode); // Make sure the reader MajorVersion and MinorVersion are the same with the ones on the dataset message DataSetReaderDataType reader = (DataSetReaderDataType)m_firstDataSetReaderType.MemberwiseClone(); reader.DataSetMetaData.ConfigurationVersion.MajorVersion = VersionValue; reader.DataSetMetaData.ConfigurationVersion.MinorVersion = VersionValue * 10; // workaround uaDataSetMessageDecoded.DataSetWriterId = TestDataSetWriterId; uaDataSetMessageDecoded.DecodePossibleDataSetReader(decoder, reader); decoder.Dispose(); // Assert Assert.AreEqual(DataSetDecodeErrorReason.NoError, uaDataSetMessageDecoded.DecodeErrorReason); Assert.AreEqual(false, uaDataSetMessageDecoded.IsMetadataMajorVersionChange); Assert.AreNotEqual(null, uaDataSetMessageDecoded.DataSet); // compare uadpDataSetMessage with uaDataSetMessageDecoded CompareUadpDataSetMessages(uadpDataSetMessage, uaDataSetMessageDecoded); }
/// <summary> /// Compare encoded/decoded dataset messages /// </summary> /// <param name="uadpDataSetMessage"></param> /// <returns></returns> private void CompareEncodeDecode(UadpDataSetMessage uadpDataSetMessage) { IServiceMessageContext messageContextEncode = new ServiceMessageContext(); byte[] bytes; var memoryStream = new MemoryStream(); using (BinaryEncoder encoder = new BinaryEncoder(memoryStream, messageContextEncode, true)) { uadpDataSetMessage.Encode(encoder); _ = encoder.Close(); bytes = ReadBytes(memoryStream); } UadpDataSetMessage uaDataSetMessageDecoded = new UadpDataSetMessage(); BinaryDecoder decoder = new BinaryDecoder(bytes, messageContextEncode); // workaround uaDataSetMessageDecoded.DataSetWriterId = TestDataSetWriterId; uaDataSetMessageDecoded.DecodePossibleDataSetReader(decoder, m_firstDataSetReaderType); decoder.Dispose(); // compare uadpDataSetMessage with uaDataSetMessageDecoded CompareUadpDataSetMessages(uadpDataSetMessage, uaDataSetMessageDecoded); }
/// <summary> /// Compare encoded/decoded dataset messages /// </summary> /// <param name="uadpDataSetMessage"></param> /// <returns></returns> private void CompareEncodeDecode(UadpDataSetMessage uadpDataSetMessage) { ServiceMessageContext messageContextEncode = new ServiceMessageContext(); BinaryEncoder encoder = new BinaryEncoder(messageContextEncode); uadpDataSetMessage.Encode(encoder); byte[] bytes = ReadBytes(encoder.BaseStream); encoder.Dispose(); UadpDataSetMessage uaDataSetMessageDecoded = new UadpDataSetMessage(); BinaryDecoder decoder = new BinaryDecoder(bytes, messageContextEncode); // workaround uaDataSetMessageDecoded.DataSetWriterId = TestDataSetWriterId; uaDataSetMessageDecoded.DecodePossibleDataSetReader(decoder, m_firstDataSetReaderType); decoder.Dispose(); // compare uadpDataSetMessage with uaDataSetMessageDecoded CompareUadpDataSetMessages(uadpDataSetMessage, uaDataSetMessageDecoded); }