public async Task Should_pass_message_and_headers_to_container_information_extractor()
        {
            object capturedMessageInstanceFromContainerInformationExtractor = null;
            IReadOnlyDictionary <string, string> capturedHeadersFromContainerInformationExtractor = null;
            var containerInformationExtractor = new ContainerInformationExtractor(
                (object msg, IReadOnlyDictionary <string, string> headers,
                 out ContainerInformation? containerInformation) =>
            {
                containerInformation = null;
                capturedMessageInstanceFromContainerInformationExtractor = msg;
                capturedHeadersFromContainerInformationExtractor         = headers;
                return(true);
            });

            var behavior = new TransactionInformationBeforeTheLogicalOutboxBehavior(new PartitionKeyExtractor(), containerInformationExtractor);

            var messageHeaders = new Dictionary <string, string> {
                { "HeaderKey", "HeaderValue" }
            };
            var messageInstance = new object();
            var context         = new TestableIncomingLogicalMessageContext
            {
                MessageHeaders = messageHeaders,
                Message        = new LogicalMessage(new MessageMetadata(typeof(object)), messageInstance)
            };

            await behavior.Invoke(context, _ => Task.CompletedTask);

            Assert.That(capturedMessageInstanceFromContainerInformationExtractor, Is.Not.Null.And.EqualTo(messageInstance));
            Assert.That(capturedHeadersFromContainerInformationExtractor, Is.Not.Null.And.EqualTo(messageHeaders));
        }
Ejemplo n.º 2
0
        public async Task Should_not_set_container_when_container_information_extractor_returns_false()
        {
            var containerInformationExtractor = new ContainerInformationExtractor(
                (IReadOnlyDictionary <string, string> headers, out ContainerInformation? container) =>
            {
                container = null;
                return(false);
            });

            var behavior = new TransactionInformationBeforeThePhysicalOutboxBehavior(new PartitionKeyExtractor(), containerInformationExtractor);

            var context = new TestableTransportReceiveContext();

            await behavior.Invoke(context, _ => Task.CompletedTask);

            Assert.That(context.Extensions.TryGet <ContainerInformation>(out _), Is.False);
        }
Ejemplo n.º 3
0
        public async Task Should_set_container_when_container_information_extractor_returns_true()
        {
            var containerInformationExtractor = new ContainerInformationExtractor(
                (IReadOnlyDictionary <string, string> headers, out ContainerInformation? container) =>
            {
                container = new ContainerInformation("containerName", new PartitionKeyPath("/deep/down"));
                return(true);
            });

            var behavior = new TransactionInformationBeforeThePhysicalOutboxBehavior(new CosmosDB.PartitionKeyExtractor(), containerInformationExtractor);

            var context = new TestableTransportReceiveContext();

            await behavior.Invoke(context, _ => Task.CompletedTask);

            Assert.That(context.Extensions.TryGet <ContainerInformation>(out var containerInformation), Is.True);
            Assert.AreEqual(new ContainerInformation("containerName", new PartitionKeyPath("/deep/down")), containerInformation);
        }
Ejemplo n.º 4
0
        public async Task Should_pass_headers_to_container_information_extractor()
        {
            IReadOnlyDictionary <string, string> capturedHeaders = null;
            var containerInformationExtractor = new ContainerInformationExtractor(
                (IReadOnlyDictionary <string, string> headers, out ContainerInformation? container) =>
            {
                container       = null;
                capturedHeaders = headers;
                return(false);
            });

            var behavior = new TransactionInformationBeforeThePhysicalOutboxBehavior(new PartitionKeyExtractor(), containerInformationExtractor);

            var context = new TestableTransportReceiveContext();

            context.Message.Headers.Add("TheAnswer", "Is42");

            await behavior.Invoke(context, _ => Task.CompletedTask);

            Assert.That(capturedHeaders, Is.EqualTo(context.Message.Headers));
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            fakePartitionKeyPath = new PartitionKeyPath("/deep/down");

            extractor = new ContainerInformationExtractor();
        }