Пример #1
0
        public void AmqpStructuredMessageTest()
        {
            // the AMQPNetLite library is factored such
            // that we don't need to do a wire test here


            var jsonEventFormatter = new JsonEventFormatter();
            var cloudEvent         = new CloudEvent(CloudEventsSpecVersion.V0_3,
                                                    "com.github.pull.create",
                                                    source: new Uri("https://github.com/cloudevents/spec/pull"),
                                                    subject: "123")
            {
                Id              = "A234-1234-1234",
                Time            = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
                DataContentType = new ContentType(MediaTypeNames.Text.Xml),
                Data            = "<much wow=\"xml\"/>"
            };

            var attrs = cloudEvent.GetAttributes();

            attrs["comexampleextension1"] = "value";
            attrs["comexampleextension2"] = new { othervalue = 5 };

            var message = new AmqpCloudEventMessage(cloudEvent, ContentMode.Structured, new JsonEventFormatter());

            Assert.True(message.IsCloudEvent());
            var encodedAmqpMessage = message.Encode();

            var message1 = Message.Decode(encodedAmqpMessage);

            Assert.True(message1.IsCloudEvent());
            var receivedCloudEvent = message1.ToCloudEvent();

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

            var attr = receivedCloudEvent.GetAttributes();

            Assert.Equal("value", (string)attr["comexampleextension1"]);
            Assert.Equal(5, (int)((dynamic)attr["comexampleextension2"]).othervalue);
        }
Пример #2
0
        public void AmqpBinaryMessageTest()
        {
            // the AMQPNetLite library is factored such
            // that we don't need to do a wire test here


            var jsonEventFormatter = new JsonEventFormatter();
            var cloudEvent         = new CloudEvent("com.github.pull.create",
                                                    new Uri("https://github.com/cloudevents/spec/pull/123"))
            {
                Id              = "A234-1234-1234",
                Time            = new DateTimeOffset(2018, 4, 5, 17, 31, 0, TimeSpan.Zero),
                DataContentType = new ContentType(MediaTypeNames.Text.Xml),
                Data            = "<much wow=\"xml\"/>"
            };

            var attrs = cloudEvent.GetAttributes();

            attrs["comexampleextension1"] = "value";

            var message = new AmqpCloudEventMessage(cloudEvent, ContentMode.Binary, new JsonEventFormatter());

            Assert.True(message.IsCloudEvent());
            var encodedAmqpMessage = message.Encode();

            var message1 = Message.Decode(encodedAmqpMessage);

            Assert.True(message1.IsCloudEvent());
            var receivedCloudEvent = message1.ToCloudEvent();

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

            var attr = receivedCloudEvent.GetAttributes();

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