public async Task Should_get_messages()
        {
            var persister = new OutboxPersister(store, testEndpointName, CreateTestSessionOpener());

            var messageId = Guid.NewGuid().ToString();

            //manually store an OutboxRecord to control the OutboxRecordId format
            using (var session = OpenAsyncSession())
            {
                var newRecord = new OutboxRecord
                {
                    MessageId           = messageId,
                    Dispatched          = false,
                    TransportOperations = new[]
                    {
                        new OutboxRecord.OutboxOperation
                        {
                            Message   = new byte[1024 * 5],
                            Headers   = new Dictionary <string, string>(),
                            MessageId = messageId,
                            Options   = new Dictionary <string, string>()
                        }
                    }
                };
                var fullDocumentId = "Outbox/TestEndpoint/" + messageId;
                await session.StoreAsync(newRecord, fullDocumentId);

                await session.SaveChangesAsync();
            }

            var result = await persister.Get(messageId, new ContextBag());

            Assert.NotNull(result);
            Assert.AreEqual(messageId, result.MessageId);
        }
Пример #2
0
        public async Task Should_get_the_message()
        {
            // arrange
            var persister         = new OutboxPersister("TestEndpoint", CreateTestSessionOpener(), default);
            var context           = new ContextBag();
            var incomingMessageId = SimulateIncomingMessage(context).MessageId;
            var outboxOperation   = new OutboxRecord.OutboxOperation
            {
                MessageId = "outgoingMessageId",
                Headers   = new Dictionary <string, string> {
                    { "headerName1", "headerValue1" }
                },
                Message = new byte[] { 1, 2, 3 },
                Options = new Dictionary <string, string> {
                    { "optionName1", "optionValue1" }
                },
            };

            //manually store an OutboxRecord to control the OutboxRecordId format
            using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency())
            {
                var outboxRecord = new OutboxRecord
                {
                    MessageId           = incomingMessageId,
                    Dispatched          = false,
                    TransportOperations = new[] { outboxOperation }
                };

                var outboxRecordId = "Outbox/TestEndpoint/" + incomingMessageId;

                await session.StoreAsync(outboxRecord, outboxRecordId);

                await session.SaveChangesAsync();
            }

            // act
            var outboxMessage = await persister.Get(incomingMessageId, context);

            // assert
            Assert.NotNull(outboxMessage);
            Assert.AreEqual(incomingMessageId, outboxMessage.MessageId);
            Assert.AreEqual(1, outboxMessage.TransportOperations.Length);

            var outgoingMessage = outboxMessage.TransportOperations[0];

            Assert.AreEqual(outboxOperation.MessageId, outgoingMessage.MessageId);
            Assert.AreEqual(outboxOperation.Headers, outgoingMessage.Headers);
            Assert.AreEqual(outboxOperation.Message, outgoingMessage.Body);
            Assert.AreEqual(outboxOperation.Options, outgoingMessage.Options);
        }
Пример #3
0
        public async Task Should_not_include_dispatched_transport_operations()
        {
            var messageId = Guid.NewGuid().ToString("N");

            using (var session = SessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var transportOperations = new List <OutboxOperation>
                    {
                        new OutboxOperation
                        {
                            MessageId = "1",
                            Headers   = new Dictionary <string, string>(),
                            Options   = new Dictionary <string, string>(),
                            Message   = new byte[0]
                        },
                        new OutboxOperation
                        {
                            MessageId = "2",
                            Headers   = new Dictionary <string, string>(),
                            Options   = new Dictionary <string, string>(),
                            Message   = new byte[0]
                        },
                    };
                    var outboxRecord = new OutboxRecord
                    {
                        Dispatched          = true,
                        DispatchedAt        = DateTime.UtcNow,
                        MessageId           = messageId,
                        TransportOperations = ObjectSerializer.Serialize(transportOperations)
                    };
                    session.Save(outboxRecord);
                    transaction.Commit();
                }
            }

            var outboxMessage = await persister.Get(messageId, new ContextBag());

            Assert.AreEqual(0, outboxMessage.TransportOperations.Length);
        }
Пример #4
0
        public static void StoreSchemaVersionInMetadata(this IAsyncDocumentSession session, OutboxRecord entity)
        {
            var metadata = session.Advanced.GetMetadataFor(entity);

            metadata[OutboxRecordSchemaVersionMetadataKey] = OutboxRecord.SchemaVersion;
        }