예제 #1
0
        public void EncodeStructuredModeMessage_AllAttributeTypes()
        {
            var cloudEvent = new CloudEvent(AllTypesExtensions)
            {
                ["binary"]       = SampleBinaryData,
                ["boolean"]      = true,
                ["integer"]      = 10,
                ["string"]       = "text",
                ["timestamp"]    = SampleTimestamp,
                ["uri"]          = SampleUri,
                ["urireference"] = SampleUriReference
            };

            // We're not going to check these.
            cloudEvent.PopulateRequiredAttributes();

            JsonElement element  = EncodeAndParseStructured(cloudEvent);
            var         asserter = new JsonElementAsserter
            {
                { "binary", JsonValueKind.String, SampleBinaryDataBase64 },
                { "boolean", JsonValueKind.True, true },
                { "integer", JsonValueKind.Number, 10 },
                { "string", JsonValueKind.String, "text" },
                { "timestamp", JsonValueKind.String, SampleTimestampText },
                { "uri", JsonValueKind.String, SampleUriText },
                { "urireference", JsonValueKind.String, SampleUriReferenceText },
            };

            asserter.AssertProperties(element, assertCount: false);
        }
예제 #2
0
        public void ConvertToProto_AllAttributeTypes()
        {
            var cloudEvent = new CloudEvent(AllTypesExtensions)
            {
                ["binary"]       = SampleBinaryData,
                ["boolean"]      = true,
                ["integer"]      = 10,
                ["string"]       = "text",
                ["timestamp"]    = SampleTimestamp,
                ["uri"]          = SampleUri,
                ["urireference"] = SampleUriReference
            };

            // We're not going to check these.
            cloudEvent.PopulateRequiredAttributes();

            var proto = new ProtobufEventFormatter().ConvertToProto(cloudEvent);

            var expectedAttributes = new MapField <string, CloudEventAttributeValue>
            {
                { "binary", BinaryAttribute(SampleBinaryData) },
                { "boolean", BooleanAttribute(true) },
                { "integer", IntegerAttribute(10) },
                { "string", StringAttribute("text") },
                { "timestamp", TimestampAttribute(SampleTimestamp) },
                { "uri", UriAttribute(SampleUriText) },
                { "urireference", UriRefAttribute(SampleUriReferenceText) }
            };

            Assert.Equal(proto.Attributes, expectedAttributes);
        }