public void CorrelationIdPropertyHappyPath1()
        {
            var cloudEvent = new PartitionedEvent();

            cloudEvent.PartitionKey = "123";

            cloudEvent.PartitionKey.Should().Be("123");
        }
        public void ValidateMethodHappyPath()
        {
            var cloudEvent = new PartitionedEvent
            {
                Type         = "MyType",
                Source       = "/MySource",
                PartitionKey = "123"
            };

            cloudEvent.Invoking(ce => ce.Validate())
            .Should().NotThrow();
        }
        public void ValidateMethodSadPath(string partitionKey)
        {
            var cloudEvent = new PartitionedEvent
            {
                Type         = "MyType",
                Source       = "/MySource",
                PartitionKey = partitionKey
            };

            cloudEvent.Invoking(ce => ce.Validate())
            .Should().ThrowExactly <CloudEventValidationException>()
            .WithMessage("PartitionKey cannot be null or empty.");
        }
        public void ValidateStaticMethodSadPath()
        {
            // Missing PartitionKey

            var senderMessage = new SenderMessage("Hello, world!");

            senderMessage.Headers.Add(CloudEvent.IdAttribute, "MyId");
            senderMessage.Headers.Add(CloudEvent.SourceAttribute, new Uri("http://MySource"));
            senderMessage.Headers.Add(CloudEvent.TypeAttribute, "MyType");
            senderMessage.Headers.Add(CloudEvent.TimeAttribute, DateTime.UtcNow);

            Action act = () => PartitionedEvent.Validate(senderMessage);

            act.Should().ThrowExactly <CloudEventValidationException>();
        }
        public void ValidateStaticMethodHappyPath1()
        {
            var senderMessage = new SenderMessage("Hello, world!");

            senderMessage.Headers.Add(PartitionedEvent.PartitionKeyAttribute, "123");

            senderMessage.Headers.Add(CloudEvent.SpecVersionAttribute, "1.0");
            senderMessage.Headers.Add(CloudEvent.IdAttribute, "MyId");
            senderMessage.Headers.Add(CloudEvent.SourceAttribute, new Uri("http://MySource"));
            senderMessage.Headers.Add(CloudEvent.TypeAttribute, "MyType");
            senderMessage.Headers.Add(CloudEvent.TimeAttribute, DateTime.UtcNow);

            Action act = () => PartitionedEvent.Validate(senderMessage);

            act.Should().NotThrow();
        }
        public void ValidateStaticMethodHappyPath2()
        {
            // Non-default protocol binding

            var senderMessage = new SenderMessage("Hello, world!");

            senderMessage.Headers.Add("test-" + PartitionedEvent.PartitionKeyAttribute, "123");

            senderMessage.Headers.Add("test-" + CloudEvent.SpecVersionAttribute, "1.0");
            senderMessage.Headers.Add("test-" + CloudEvent.IdAttribute, "MyId");
            senderMessage.Headers.Add("test-" + CloudEvent.SourceAttribute, new Uri("http://MySource"));
            senderMessage.Headers.Add("test-" + CloudEvent.TypeAttribute, "MyType");
            senderMessage.Headers.Add("test-" + CloudEvent.TimeAttribute, DateTime.UtcNow);

            var mockProtocolBinding = new Mock <IProtocolBinding>();

            mockProtocolBinding.Setup(m => m.GetHeaderName(It.IsAny <string>())).Returns <string>(header => "test-" + header);

            Action act = () => PartitionedEvent.Validate(senderMessage, mockProtocolBinding.Object);

            act.Should().NotThrow();
        }