public void When_There_Is_No_Message_In_The_Outbox() { AsyncContext.Run(async() => s_messages = await s_eventStoreOutbox.GetAsync(EmptyStreamName, 0, 1)); //_returns_an_empty_list 0.Should().Be(s_messages.Count); }
public async Task When_marking_a_message_as_dispatched_async_tests() { // arrange var eventStoreOutbox = new EventStoreOutbox(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 EventStoreOutbox(Connection); var message1 = CreateMessage(0, StreamName); var message2 = CreateMessage(1, StreamName); var message3 = CreateMessage(2, StreamName); await eventStoreOutbox.AddAsync(message1); await eventStoreOutbox.AddAsync(message2); await eventStoreOutbox.AddAsync(message3); var args = new Dictionary <string, object> { { EventStoreOutbox.StreamArg, StreamName } }; // act var messages = await eventStoreOutbox.GetAsync(1, 3, args); // assert messages.Should().ContainSingle().Which.Should().BeEquivalentTo(message3); }
public void When_Writing_Messages_To_The_Outbox_Async() { AsyncContext.Run(async() => _messages = await _eventStoreOutbox.GetAsync(StreamName, 0, 2)); //_gets_message1 Assert.AreEqual(_messages.Count(m => MessagesEqualApartFromTimestamp(m, _message1)), 1); //_gets_message2 Assert.AreEqual(_messages.Count(m => MessagesEqualApartFromTimestamp(m, _message2)), 1); }
public async Task When_null_args_are_supplied() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); // act Func <Task> getWithoutArgs = () => eventStoreOutbox.GetAsync(1, 1); // assert await Assert.ThrowsAsync <ArgumentNullException>(getWithoutArgs); }
public async Task When_There_Is_No_Message_In_The_Outbox() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); // act var messages = await eventStoreOutbox.GetAsync(StreamName, 0, 1); // assert //_returns_an_empty_list messages.Count.Should().Be(0); }
public async Task When_empty_args_are_supplied() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); var args = new Dictionary <string, object>(); // act Func <Task> getWithoutArgs = async() => await eventStoreOutbox.GetAsync(1, 1, args); // assert await Assert.ThrowsAsync <ArgumentException>(getWithoutArgs); }
public async Task When_null_stream_arg_supplied() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); var args = new Dictionary <string, object> { { Globals.StreamArg, null } }; // act Func <Task> getWithoutArgs = async() => await eventStoreOutbox.GetAsync(1, 1, args); // assert await Assert.ThrowsAsync <ArgumentException>(getWithoutArgs); }
public async Task When_wrong_args_are_supplied() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); var args = new Dictionary <string, object> { { "Foo", "Bar" } }; // act Func <Task> getWithoutArgs = async() => await eventStoreOutbox.GetAsync(1, 1, args); // assert getWithoutArgs.Should().Throw <ArgumentException>(); }
public async Task When_there_are_multiple_messages_in_the_outbox_and_a_range_is_fetched_async() { // arrange var eventStoreOutbox = new EventStoreOutbox(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 EventStoreOutbox(Connection); var message1 = CreateMessage(0, StreamName); var message2 = CreateMessage(1, StreamName); // act await eventStoreOutbox.AddAsync(message1); await eventStoreOutbox.AddAsync(message2); // assert var messages = await eventStoreOutbox.GetAsync(StreamName, 0, 2); messages.Count(m => MessagesEqualApartFromTimestamp(m, message1)).Should().Be(1); messages.Count(m => MessagesEqualApartFromTimestamp(m, message2)).Should().Be(1); }
public async Task When_Writing_Messages_To_The_Outbox_Async() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); var message1 = CreateMessage(0, StreamName); var message2 = CreateMessage(1, StreamName); // 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 //should read the message header first bag item from the sql outbox messages[0].Header.Bag["impersonatorId"].Should().Be(123); //should read the message header second bag item from the sql outbox messages[0].Header.Bag["eventNumber"].Should().Be(0); messages[0].Header.Bag["streamId"].Should().Be(StreamName); //Bag serialization //should read the message header first bag item from the sql outbox messages[1].Header.Bag["impersonatorId"].Should().Be(123); //should read the message header second bag item from the sql outbox messages[1].Header.Bag["eventNumber"].Should().Be(1); messages[1].Header.Bag["streamId"].Should().Be(StreamName); }
public async Task When_marking_a_message_as_dispatched_async_tests() { // arrange var eventStoreOutbox = new EventStoreOutbox(Connection); var messageToMarkAsDispatched = CreateMessage(0, StreamName); var dispatchedAt = DateTime.UtcNow; var args = new Dictionary <string, object> { { EventStoreOutbox.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[EventStoreOutbox.DispatchedAtKey].Should().Be(dispatchedAt); }
public async Task When_Writing_Messages_To_The_Outbox_Async() { // arrange var eventStoreOutbox = new EventStoreOutbox(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); }