コード例 #1
0
        internal void CanSerializeAndDeserialize_InstrumentResponses()
        {
            // Arrange
            var dataSerializer = new InstrumentSerializer();
            var instrument     = StubInstrumentProvider.AUDUSD();
            var correlationId  = Guid.NewGuid();

            Instrument[] instruments           = { instrument };
            var          serializedInstruments = dataSerializer.Serialize(instruments);

            var metadata = new Dictionary <string, string> {
                { "Symbol", instrument.Symbol.ToString() }
            };
            var data = dataSerializer.SerializeBlob(serializedInstruments, metadata);

            var response = new DataResponse(
                data,
                typeof(Instrument[]).Name,
                dataSerializer.BlobEncoding,
                correlationId,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            // Act
            var serializedResponse   = this.serializer.Serialize(response);
            var deserializedResponse = (DataResponse)this.serializer.Deserialize(serializedResponse);
            var deserializedData     = dataSerializer.DeserializeBlob(deserializedResponse.Data);

            // Assert
            Assert.Equal(response, deserializedResponse);
            Assert.Equal(instrument, deserializedData[0]);
            Assert.Equal(correlationId, deserializedResponse.CorrelationId);
            this.Output.WriteLine(Convert.ToBase64String(serializedResponse));
            this.Output.WriteLine(Encoding.UTF8.GetString(serializedResponse));
        }
コード例 #2
0
        internal void CanSerializeAndDeserializeInstrument()
        {
            // Arrange
            var serializer = new InstrumentSerializer();
            var instrument = StubInstrumentProvider.AUDUSD();

            // Act
            var packed   = serializer.Serialize(instrument);
            var unpacked = serializer.Deserialize(packed);

            // Assert
            Assert.Equal(instrument, unpacked);
            this.Output.WriteLine(Convert.ToBase64String(packed));
            this.Output.WriteLine(Encoding.UTF8.GetString(packed));
        }