Beispiel #1
0
        public void Constructor3HappyPath3()
        {
            // All attributes provided

            var receiverMessage = new FakeReceiverMessage("Hello, world!");

            var source          = "http://MySource";
            var dataContentType = "application/mycontenttype";
            var dataSchema      = "http://MySource";
            var time            = DateTime.UtcNow;

            receiverMessage.Headers.Add(CloudEvent.SpecVersionAttribute, "1.0");
            receiverMessage.Headers.Add(CloudEvent.IdAttribute, "MyId");
            receiverMessage.Headers.Add(CloudEvent.SourceAttribute, source);
            receiverMessage.Headers.Add(CloudEvent.TypeAttribute, "MyType");
            receiverMessage.Headers.Add(CloudEvent.DataContentTypeAttribute, dataContentType);
            receiverMessage.Headers.Add(CloudEvent.DataSchemaAttribute, dataSchema);
            receiverMessage.Headers.Add(CloudEvent.SubjectAttribute, "MySubject");
            receiverMessage.Headers.Add(CloudEvent.TimeAttribute, time);

            var cloudEvent = new CloudEvent(receiverMessage);

            cloudEvent.SpecVersion.Should().Be("1.0");
            cloudEvent.Id.Should().Be("MyId");
            cloudEvent.Source.Should().BeSameAs(source);
            cloudEvent.Type.Should().Be("MyType");
            cloudEvent.DataContentType.Should().BeSameAs(dataContentType);
            cloudEvent.DataSchema.Should().BeSameAs(dataSchema);
            cloudEvent.Subject.Should().Be("MySubject");
            cloudEvent.Time.Should().Be(time);
        }
Beispiel #2
0
        public void Constructor3HappyPath1()
        {
            var binaryData = new byte[] { 1, 2, 3, 4 };

            var receiverMessage = new FakeReceiverMessage(binaryData);

            var cloudEvent = new CloudEvent(receiverMessage);

            cloudEvent.BinaryData.Should().BeSameAs(binaryData);
            cloudEvent.StringData.Should().BeNull();
        }
Beispiel #3
0
        public void Constructor3HappyPath2()
        {
            var stringData = "Hello, world!";

            var receiverMessage = new FakeReceiverMessage(stringData);

            var cloudEvent = new CloudEvent(receiverMessage);

            cloudEvent.StringData.Should().BeSameAs(stringData);
            cloudEvent.BinaryData.Should().BeNull();
        }
Beispiel #4
0
        public void Constructor3SadPath2()
        {
            // Invalid specversion

            var receiverMessage = new FakeReceiverMessage("Hello, world!");

            receiverMessage.Headers.Add(CloudEvent.SpecVersionAttribute, "0.0");

            Action act = () => new CloudEvent(receiverMessage);

            act.Should().ThrowExactly <CloudEventValidationException>();
        }
        public void Constructor3HappyPath7()
        {
            // Non-default protocol binding

            using var receiverMessage = new FakeReceiverMessage("Hello, world!");
            receiverMessage.Headers.Add("foo", "abc");
            receiverMessage.Headers.Add("test-" + CloudEvent.IdAttribute, "MyId");

            var mockProtocolBinding = new Mock <IProtocolBinding>().SetupTestProtocolBinding();

            var cloudEvent = new CloudEvent(receiverMessage, mockProtocolBinding.Object);

            cloudEvent.Id.Should().Be("MyId");
            cloudEvent.Headers.Should().ContainKey("foo").WhoseValue.Should().Be("abc");
        }
Beispiel #6
0
        public void Constructor3HappyPath4()
        {
            // No attributes provided

            var receiverMessage = new FakeReceiverMessage("Hello, world!");

            var cloudEvent = new CloudEvent(receiverMessage);

            cloudEvent.SpecVersion.Should().Be("1.0");
            cloudEvent.Source.Should().BeNull();
            cloudEvent.Type.Should().BeNull();
            cloudEvent.DataContentType.Should().BeNull();
            cloudEvent.DataSchema.Should().BeNull();
            cloudEvent.Subject.Should().BeNull();
            cloudEvent.Attributes.Should().BeEmpty();
        }
        public void Constructor3HappyPath6()
        {
            // Additional attributes provided

            using var receiverMessage = new FakeReceiverMessage("Hello, world!");
            receiverMessage.Headers.Add("test-foo", "abc");
            receiverMessage.Headers.Add("test-bar", 123);

            var mockProtocolBinding = new Mock <IProtocolBinding>().SetupTestProtocolBinding();

            var cloudEvent = new CloudEvent(receiverMessage, mockProtocolBinding.Object);

            cloudEvent.Attributes.Should().HaveCount(2);
            cloudEvent.Attributes.Should().ContainKey("foo").WhoseValue.Should().Be("abc");
            cloudEvent.Attributes.Should().ContainKey("bar").WhoseValue.Should().Be(123);
        }
Beispiel #8
0
        public void KafkaProtocolBindingBindMethod2HappyPath1()
        {
            var receiverMessage = new FakeReceiverMessage("")
            {
                Headers = { ["Kafka.Key"] = "MyKafkaKey" }
            };
            var cloudEvent = new CloudEvent
            {
                Attributes = { ["Kafka.Key"] = "MyKafkaKey" }
            };

            cloudEvent.Attributes.Should().HaveCount(1);
            cloudEvent.Attributes.Should().ContainKey("Kafka.Key");
            cloudEvent.Headers.Should().BeEmpty();

            ProtocolBindings.Kafka.Bind(receiverMessage, cloudEvent);

            cloudEvent.Attributes.Should().HaveCount(1);
            cloudEvent.Attributes.Should().ContainKey("partitionkey");
            cloudEvent.Headers.Should().BeEmpty();
        }
Beispiel #9
0
        public void DefaultProtocolBindingBindMethod2HappyPath()
        {
            var receiverMessage = new FakeReceiverMessage("")
            {
                Headers =
                {
                    ["source"] = "MySource",
                    ["type"]   = "MyType",
                    ["foo"]    = "abc",
                    ["bar"]    = "xyz",
                }
            };
            var cloudEvent = new CloudEvent();

            cloudEvent.Attributes.Should().BeEmpty();
            cloudEvent.Headers.Should().BeEmpty();

            ProtocolBindings.Default.Bind(receiverMessage, cloudEvent);

            cloudEvent.Attributes.Should().BeEmpty();
            cloudEvent.Headers.Should().BeEmpty();
        }
Beispiel #10
0
        public void Constructor3HappyPath5()
        {
            // Alternate property types provided

            var receiverMessage = new FakeReceiverMessage("Hello, world!");

            var source          = new Uri("http://MySource").ToString();
            var dataContentType = new ContentType("application/mycontenttype").ToString();
            var dataSchema      = new Uri("http://MySource").ToString();
            var time            = DateTime.UtcNow.ToString("O");

            receiverMessage.Headers.Add(CloudEvent.SourceAttribute, source);
            receiverMessage.Headers.Add(CloudEvent.DataContentTypeAttribute, dataContentType);
            receiverMessage.Headers.Add(CloudEvent.DataSchemaAttribute, dataSchema);
            receiverMessage.Headers.Add(CloudEvent.TimeAttribute, time);

            var cloudEvent = new CloudEvent(receiverMessage);

            cloudEvent.Source.ToString().Should().Be(source);
            cloudEvent.DataContentType.ToString().Should().Be(dataContentType);
            cloudEvent.DataSchema.ToString().Should().Be(dataSchema);
            cloudEvent.Time.ToString("O").Should().Be(time);
        }