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

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

            var formatter = CloudEventFormatterAttribute.CreateFormatter(typeof(AttributedModel));
            var body      = formatter.EncodeStructuredModeMessage(cloudEvent, out _);
            var jobject   = JsonEventFormatterTest.ParseJson(body);

            Assert.False(jobject.ContainsKey("data"));
            Assert.False(jobject.ContainsKey("data_base64"));
        }
        public void EncodeBinaryModeEventData()
        {
            var cloudEvent = new CloudEvent().PopulateRequiredAttributes();

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

            new JTokenAsserter
            {
                { AttributedModel.JsonPropertyName, JTokenType.String, "test" }
            }.AssertProperties(jobject, assertCount: true);
        }
        public void EncodeStructuredMode()
        {
            var cloudEvent = new CloudEvent().PopulateRequiredAttributes();

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

            Assert.False(jobject.ContainsKey("data_base64"));
            var data = (JObject)jobject["data"];

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