public void ReserializeTest() { var jsonFormatter = new JsonEventFormatter(); var avroFormatter = new AvroEventFormatter(); var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonv10)); var avroData = avroFormatter.EncodeStructuredEvent(cloudEvent, out var contentType); var cloudEvent2 = avroFormatter.DecodeStructuredEvent(avroData); 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 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.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonv10)); var avroData = avroFormatter.EncodeStructuredEvent(cloudEventJ, out var contentType); var cloudEvent = avroFormatter.DecodeStructuredEvent(avroData); 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"]); }
public void StructuredParseWithExtensionsSuccess() { var jsonFormatter = new JsonEventFormatter(); var avroFormatter = new AvroEventFormatter(); var extensionAttribute = CloudEventAttribute.CreateExtension("comexampleextension1", CloudEventAttributeType.String); var cloudEventJ = jsonFormatter.DecodeStructuredModeText(jsonv10, new[] { extensionAttribute }); var avroData = avroFormatter.EncodeStructuredModeMessage(cloudEventJ, out var contentType); var cloudEvent = avroFormatter.DecodeStructuredModeMessage(avroData, contentType, new[] { extensionAttribute }); 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", cloudEvent[extensionAttribute]); }
public void StructuredParseWithExtensionsSuccess10() { var jsonFormatter = new JsonEventFormatter(); var avroFormatter = new AvroEventFormatter(); var cloudEventJ = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonv10), new ComExampleExtension1Extension()); var avroData = avroFormatter.EncodeStructuredEvent(cloudEventJ, out var contentType); var cloudEvent = avroFormatter.DecodeStructuredEvent(avroData, new ComExampleExtension1Extension()); 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); Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), cloudEvent.Time.Value.ToUniversalTime()); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("value", cloudEvent.Extension <ComExampleExtension1Extension>().ComExampleExtension1); }