/// <summary>
        /// Convenience method to format a CloudEvent with a specialized formatter in
        /// structured mode, then parse the result as a JObject.
        /// </summary>
        private static JsonElement EncodeAndParseStructured(CloudEvent cloudEvent)
        {
            var formatter = new SpecializedFormatter();
            var encoded   = formatter.EncodeStructuredModeMessage(cloudEvent, out _);

            return(JsonEventFormatterTest.ParseJson(encoded));
        }
Example #2
0
        public void EncodeStructuredMode_NoData()
        {
            var cloudEvent = new CloudEvent().PopulateRequiredAttributes();

            var formatter = CreateFormatter <AttributedModel>();
            var body      = formatter.EncodeStructuredModeMessage(cloudEvent, out _);
            var element   = JsonEventFormatterTest.ParseJson(body);

            Assert.False(element.TryGetProperty("data", out _));
            Assert.False(element.TryGetProperty("data_base64", out _));
        }
Example #3
0
        public void EncodeBinaryModeEventData()
        {
            var cloudEvent = new CloudEvent().PopulateRequiredAttributes();

            cloudEvent.Data = new AttributedModel {
                AttributedProperty = "test"
            };
            var formatter = CreateFormatter <AttributedModel>();
            var body      = formatter.EncodeBinaryModeEventData(cloudEvent);
            var jobject   = JsonEventFormatterTest.ParseJson(body);

            new JsonElementAsserter
            {
                { AttributedModel.JsonPropertyName, JsonValueKind.String, "test" }
            }.AssertProperties(jobject, assertCount: true);
        }
Example #4
0
        public void EncodeStructuredMode()
        {
            var cloudEvent = new CloudEvent().PopulateRequiredAttributes();

            cloudEvent.Data = new AttributedModel {
                AttributedProperty = "test"
            };
            var formatter = CreateFormatter <AttributedModel>();
            var body      = formatter.EncodeStructuredModeMessage(cloudEvent, out _);
            var element   = JsonEventFormatterTest.ParseJson(body);

            Assert.False(element.TryGetProperty("data_base64", out _));
            var data = element.GetProperty("data");

            new JsonElementAsserter
            {
                { AttributedModel.JsonPropertyName, JsonValueKind.String, "test" }
            }.AssertProperties(data, assertCount: true);
        }