Esempio n. 1
0
        public void Parse()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent    = jsonFormatter.DecodeStructuredModeText(sampleJson, Sequence.AllAttributes);

            Assert.Equal("Integer", cloudEvent[Sequence.SequenceTypeAttribute]);
            Assert.Equal("25", cloudEvent[Sequence.SequenceAttribute]);
        }
Esempio n. 2
0
        public void SamplingParse()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent    = jsonFormatter.DecodeStructuredModeText(sampleJson, Sampling.AllAttributes);

            Assert.Equal(1, cloudEvent["sampledrate"]);
            Assert.Equal(1, cloudEvent.GetSampledRate());
        }
Esempio n. 3
0
        public void ParseJson()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent    = jsonFormatter.DecodeStructuredModeText(sampleJson);

            Assert.Equal("abc", cloudEvent["partitionkey"]);
            Assert.Equal("abc", cloudEvent[Partitioning.PartitionKeyAttribute]);
            Assert.Equal("abc", cloudEvent.GetPartitionKey());
        }
Esempio n. 4
0
        public void ParseJson()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent    = jsonFormatter.DecodeStructuredModeText(sampleJson, DistributedTracing.AllAttributes);

            Assert.Equal(SampleParent, cloudEvent[DistributedTracing.TraceParentAttribute]);
            Assert.Equal(SampleParent, cloudEvent.GetTraceParent());
            Assert.Equal(SampleState, cloudEvent[DistributedTracing.TraceStateAttribute]);
            Assert.Equal(SampleState, cloudEvent.GetTraceState());
        }
Esempio n. 5
0
        public void Transcode()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent1   = jsonFormatter.DecodeStructuredModeText(sampleJson);
            var jsonData      = jsonFormatter.EncodeStructuredModeMessage(cloudEvent1, out var contentType);
            var cloudEvent    = jsonFormatter.DecodeStructuredModeMessage(jsonData, contentType, Sequence.AllAttributes);

            Assert.Equal("Integer", cloudEvent[Sequence.SequenceTypeAttribute]);
            Assert.Equal("25", cloudEvent[Sequence.SequenceAttribute]);
        }
Esempio n. 6
0
        public void Transcode()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent1   = jsonFormatter.DecodeStructuredModeText(sampleJson);
            var jsonData      = jsonFormatter.EncodeStructuredModeMessage(cloudEvent1, out var contentType);
            var cloudEvent    = jsonFormatter.DecodeStructuredModeMessage(jsonData, contentType, null);

            Assert.Equal("abc", cloudEvent["partitionkey"]);
            Assert.Equal("abc", cloudEvent[Partitioning.PartitionKeyAttribute]);
            Assert.Equal("abc", cloudEvent.GetPartitionKey());
        }
Esempio n. 7
0
        public void Transcode()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent1   = jsonFormatter.DecodeStructuredModeText(sampleJson);
            var jsonData      = jsonFormatter.EncodeStructuredModeMessage(cloudEvent1, out var contentType);
            var cloudEvent    = jsonFormatter.DecodeStructuredModeMessage(jsonData, contentType, DistributedTracing.AllAttributes);

            Assert.Equal(SampleParent, cloudEvent[DistributedTracing.TraceParentAttribute]);
            Assert.Equal(SampleParent, cloudEvent.GetTraceParent());
            Assert.Equal(SampleState, cloudEvent[DistributedTracing.TraceStateAttribute]);
            Assert.Equal(SampleState, cloudEvent.GetTraceState());
        }
Esempio n. 8
0
        public void SamplingJsonTranscode()
        {
            var jsonFormatter = new JsonEventFormatter();
            var cloudEvent1   = jsonFormatter.DecodeStructuredModeText(sampleJson);

            // Note that the value is just a string here, as we don't know the attribute type.
            Assert.Equal("1", cloudEvent1["sampledrate"]);

            var jsonData   = jsonFormatter.EncodeStructuredModeMessage(cloudEvent1, out var contentType);
            var cloudEvent = jsonFormatter.DecodeStructuredModeMessage(jsonData, contentType, Sampling.AllAttributes);

            // When parsing with the attributes in place, the value is propagated as an integer.
            Assert.Equal(1, cloudEvent["sampledrate"]);
            Assert.Equal(1, cloudEvent.GetSampledRate());
        }
        public void ReserializeTest()
        {
            var jsonFormatter = new JsonEventFormatter();
            var avroFormatter = new AvroEventFormatter();
            var cloudEvent    = jsonFormatter.DecodeStructuredModeText(jsonv10);
            var avroData      = avroFormatter.EncodeStructuredModeMessage(cloudEvent, out var contentType);
            var cloudEvent2   = avroFormatter.DecodeStructuredModeMessage(avroData, contentType, extensionAttributes: null);

            Assert.Equal(cloudEvent2.SpecVersion, cloudEvent.SpecVersion);
            Assert.Equal(cloudEvent2.Type, cloudEvent.Type);
            Assert.Equal(cloudEvent2.Source, cloudEvent.Source);
            Assert.Equal(cloudEvent2.Id, cloudEvent.Id);
            AssertTimestampsEqual(cloudEvent2.Time.Value, cloudEvent.Time.Value);
            Assert.Equal(cloudEvent2.DataContentType, cloudEvent.DataContentType);
            Assert.Equal(cloudEvent2.Data, cloudEvent.Data);
        }
        public void StructuredParseSuccess()
        {
            var jsonFormatter = new JsonEventFormatter();
            var avroFormatter = new AvroEventFormatter();
            var cloudEventJ   = jsonFormatter.DecodeStructuredModeText(jsonv10);
            var avroData      = avroFormatter.EncodeStructuredModeMessage(cloudEventJ, out var contentType);
            var cloudEvent    = avroFormatter.DecodeStructuredModeMessage(avroData, contentType, extensionAttributes: null);

            Assert.Equal(CloudEventsSpecVersion.V1_0, cloudEvent.SpecVersion);
            Assert.Equal("com.github.pull.create", cloudEvent.Type);
            Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
            Assert.Equal("A234-1234-1234", cloudEvent.Id);
            AssertTimestampsEqual("2018-04-05T17:31:00Z", cloudEvent.Time.Value);
            Assert.Equal(MediaTypeNames.Text.Xml, cloudEvent.DataContentType);
            Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);

            Assert.Equal("value", (string)cloudEvent["comexampleextension1"]);
        }