public async Task When_marking_a_message_as_dispatched_async_tests() { // arrange var eventStoreOutbox = new EventStoreOutboxSync(Connection); var body = new MessageBody("{companyId:123}"); var header = new MessageHeader(Guid.NewGuid(), "Topic", MessageType.MT_EVENT); header.Bag.Add("impersonatorId", 123); header.Bag.Add("eventNumber", 0); header.Bag.Add("streamId", StreamName); var messageToMarkAsDispatched = new Message(header, body); var dispatchedAt = DateTime.UtcNow; var args = new Dictionary <string, object> { { Globals.StreamArg, StreamName } }; await eventStoreOutbox.AddAsync(messageToMarkAsDispatched); // act await eventStoreOutbox.MarkDispatchedAsync(messageToMarkAsDispatched.Id, dispatchedAt, args); // assert var messages = await eventStoreOutbox.GetAsync(1, 2, args); messages.Should().ContainSingle().Which.Header.Bag[Globals.DispatchedAtKey].Should().Be(dispatchedAt); }
public async Task When_there_are_multiple_messages_in_the_outbox_and_a_range_is_fetched_async() { // arrange var eventStoreOutbox = new EventStoreOutboxSync(Connection); var body = new MessageBody("{companyId:123}"); var header = new MessageHeader(Guid.NewGuid(), "Topic", MessageType.MT_EVENT); header.Bag.Add("impersonatorId", 123); header.Bag.Add("eventNumber", 0); header.Bag.Add("streamId", StreamName); var message1 = new Message(header, body); var body1 = new MessageBody("{companyId:123}"); var header1 = new MessageHeader(Guid.NewGuid(), "Topic", MessageType.MT_EVENT); header1.Bag.Add("impersonatorId", 123); header1.Bag.Add("eventNumber", 1); header1.Bag.Add("streamId", StreamName); var message2 = new Message(header1, body1); var body2 = new MessageBody("{companyId:123}"); var header2 = new MessageHeader(Guid.NewGuid(), "Topic", MessageType.MT_EVENT); header2.Bag.Add("impersonatorId", 123); header2.Bag.Add("eventNumber", 2); header2.Bag.Add("streamId", StreamName); var message3 = new Message(header2, body2); await eventStoreOutbox.AddAsync(message1); await eventStoreOutbox.AddAsync(message2); await eventStoreOutbox.AddAsync(message3); var args = new Dictionary <string, object> { { Globals.StreamArg, StreamName } }; // act var messages = await eventStoreOutbox.GetAsync(1, 3, args); // assert messages.Should().ContainSingle().Which.Should().BeEquivalentTo(message3); }
public async Task When_Writing_Messages_To_The_Outbox_Async() { // arrange var eventStoreOutbox = new EventStoreOutboxSync(Connection); var body = new MessageBody("{companyId:123}"); var header = new MessageHeader(Guid.NewGuid(), "Topic", MessageType.MT_EVENT); header.Bag.Add("impersonatorId", 123); header.Bag.Add("eventNumber", 0); header.Bag.Add("streamId", StreamName); var conversationId = Guid.NewGuid(); header.Bag.Add("conversationId", conversationId); var now = DateTime.UtcNow; header.Bag.Add("timeStamp", now); var message1 = new Message(header, body); var body1 = new MessageBody("{companyId:123}"); var header1 = new MessageHeader(Guid.NewGuid(), "Topic", MessageType.MT_EVENT); header1.Bag.Add("impersonatorId", 123); header1.Bag.Add("eventNumber", 1); header1.Bag.Add("streamId", StreamName); header1.Bag.Add("conversationId", conversationId); header1.Bag.Add("timeStamp", now); var message2 = new Message(header1, body1); // act await eventStoreOutbox.AddAsync(message1); await eventStoreOutbox.AddAsync(message2); // assert var messages = await eventStoreOutbox.GetAsync(StreamName, 0, 2); //should read the message from the outbox messages[0].Body.Value.Should().Be(message1.Body.Value); //should read the header from the outbox messages[0].Header.Topic.Should().Be(message1.Header.Topic); messages[0].Header.MessageType.Should().Be(message1.Header.MessageType); messages[0].Header.TimeStamp.Should().Be(message1.Header.TimeStamp); messages[0].Header.HandledCount.Should().Be(0); // -- should be zero when read from outbox messages[0].Header.DelayedMilliseconds.Should().Be(0); // -- should be zero when read from outbox messages[0].Header.CorrelationId.Should().Be(message1.Header.CorrelationId); messages[0].Header.ReplyTo.Should().Be(message1.Header.ReplyTo); messages[0].Header.ContentType.Should().Be(message1.Header.ContentType); //Bag serialization messages[0].Header.Bag["impersonatorId"].Should().Be(123); messages[0].Header.Bag["eventNumber"].Should().Be(0); messages[0].Header.Bag["streamId"].Should().Be(StreamName); messages[0].Header.Bag["conversationId"].Should().Be(conversationId); messages[0].Header.Bag["timeStamp"].Should().Be(now); messages[1].Header.Bag["impersonatorId"].Should().Be(123); messages[1].Header.Bag["eventNumber"].Should().Be(1); messages[1].Header.Bag["streamId"].Should().Be(StreamName); messages[1].Header.Bag["conversationId"].Should().Be(conversationId); messages[1].Header.Bag["timeStamp"].Should().Be(now); }