public void When_there_is_an_outstanding_message_in_the_outbox()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutbox(Connection);

            var args = new Dictionary <string, object> {
                { EventStoreOutbox.StreamArg, StreamName }
            };

            var outstandingMessage       = CreateMessage(0, StreamName);
            var dispatchedMessage        = CreateMessage(1, StreamName);
            var outstandingRecentMessage = CreateMessage(3, StreamName);

            eventStoreOutbox.Add(outstandingMessage);
            eventStoreOutbox.Add(dispatchedMessage);
            Task.Delay(1000).Wait();
            eventStoreOutbox.MarkDispatched(dispatchedMessage.Id, DateTime.UtcNow, args);
            eventStoreOutbox.Add(outstandingRecentMessage);

            // act
            var messages = eventStoreOutbox.OutstandingMessages(500, 100, 1, args);

            // assert
            messages.Should().BeEquivalentTo(outstandingMessage);
        }
Exemple #2
0
        public void When_there_are_multiple_messages_in_the_outbox_and_a_range_is_fetched()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutbox(Connection);

            var message1 = CreateMessage(0, StreamName);
            var message2 = CreateMessage(1, StreamName);
            var message3 = CreateMessage(2, StreamName);

            eventStoreOutbox.Add(message1);
            Task.Delay(100);
            eventStoreOutbox.Add(message2);
            Task.Delay(100);
            eventStoreOutbox.Add(message3);

            var args = new Dictionary <string, object> {
                { EventStoreOutbox.StreamArg, StreamName }
            };

            // act
            var messages = eventStoreOutbox.Get(1, 3, args);

            // assert
            messages.Should().ContainSingle().Which.Should().BeEquivalentTo(message3);
        }
Exemple #3
0
        public void When_marking_a_message_as_dispatched_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 }
            };

            eventStoreOutbox.Add(messageToMarkAsDispatched);

            // act
            eventStoreOutbox.MarkDispatched(messageToMarkAsDispatched.Id, dispatchedAt, args);

            // assert
            var messages = eventStoreOutbox.Get(1, 2, args);

            messages.Should().ContainSingle().Which.Header.Bag[Globals.DispatchedAtKey].Should().Be(dispatchedAt);
        }
Exemple #4
0
        public void When_there_are_multiple_messages_in_the_outbox_and_a_range_is_fetched()
        {
            // 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);

            eventStoreOutbox.Add(message1);
            Task.Delay(100);
            eventStoreOutbox.Add(message2);
            Task.Delay(100);
            eventStoreOutbox.Add(message3);

            var args = new Dictionary <string, object> {
                { Globals.StreamArg, StreamName }
            };

            // act
            var messages = eventStoreOutbox.Get(1, 3, args);

            // assert
            messages.Should().ContainSingle().Which.Should().BeEquivalentTo(message3);
        }
Exemple #5
0
        public void When_there_is_an_outstanding_message_in_the_outbox()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutbox(Connection);

            var args = new Dictionary <string, object> {
                { Globals.StreamArg, StreamName }
            };

            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 outstandingMessage = 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 dispatchedMessage = 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", 3);
            header2.Bag.Add("streamId", StreamName);
            var outstandingRecentMessage = new Message(header2, body2);

            eventStoreOutbox.Add(outstandingMessage);
            eventStoreOutbox.Add(dispatchedMessage);
            Task.Delay(1000).Wait();
            eventStoreOutbox.MarkDispatched(dispatchedMessage.Id, DateTime.UtcNow, args);
            eventStoreOutbox.Add(outstandingRecentMessage);

            // act
            var messages = eventStoreOutbox.OutstandingMessages(500, 100, 1, args);

            // assert
            messages.Should().BeEquivalentTo(outstandingMessage);
        }
        public void When_Writing_Messages_To_The_Outbox_Async()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutbox(Connection);

            var message1 = CreateMessage(0, StreamName);
            var message2 = CreateMessage(1, StreamName);

            // act
            eventStoreOutbox.Add(message1);
            eventStoreOutbox.Add(message2);

            // assert
            var messages = eventStoreOutbox.Get(StreamName, 0, 2);

            messages.Count(m => MessagesEqualApartFromTimestamp(m, message1)).Should().Be(1);
            messages.Count(m => MessagesEqualApartFromTimestamp(m, message2)).Should().Be(1);
        }
        public void Establish()
        {
            _eventStoreNodeStarted     = false;
            _eventStoreClientConnected = false;

            var noneIp = new IPEndPoint(IPAddress.None, 0);

            _eventStoreNode = EmbeddedVNodeBuilder
                              .AsSingleNode()
                              .RunInMemory()
                              .WithExternalTcpOn(noneIp)
                              .WithInternalTcpOn(noneIp)
                              .WithExternalHttpOn(noneIp)
                              .WithInternalHttpOn(noneIp)
                              .Build();
            _eventStoreNode.NodeStatusChanged +=
                (sender, e) => { if (e.NewVNodeState == VNodeState.Master)
                                 {
                                     _eventStoreNodeStarted = true;
                                 }
            };
            _eventStoreNode.Start();

            _eventStore            = EmbeddedEventStoreConnection.Create(_eventStoreNode);
            _eventStore.Connected += (sender, e) => { _eventStoreClientConnected = true; };
            _eventStore.ConnectAsync().Wait();

            _eventStoreOutbox = new EventStoreMessageStore(_eventStore);

            _message1 = CreateMessage(0);
            _message2 = CreateMessage(1);

            EnsureEventStoreNodeHasStartedAndTheClientHasConnected();

            _eventStoreOutbox.Add(_message1);
            _eventStoreOutbox.Add(_message2);
        }
Exemple #8
0
        public void When_marking_a_message_as_dispatched_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 }
            };

            eventStoreOutbox.Add(messageToMarkAsDispatched);

            // act
            eventStoreOutbox.MarkDispatched(messageToMarkAsDispatched.Id, dispatchedAt, args);

            // assert
            var messages = eventStoreOutbox.Get(1, 2, args);

            messages.Should().ContainSingle().Which.Header.Bag[EventStoreOutbox.DispatchedAtKey].Should().Be(dispatchedAt);
        }
Exemple #9
0
        public void When_Writing_Messages_To_The_Outbox()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutbox(Connection);

            var body   = new MessageBody("{companyId:123}");
            var header = new MessageHeader(
                messageId: Guid.NewGuid(),
                topic: "Topic",
                messageType: MessageType.MT_EVENT,
                timeStamp: DateTime.UtcNow,
                correlationId: Guid.NewGuid(),
                replyTo: "ReplyTo",
                contentType: "text/plain");

            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(
                messageId: Guid.NewGuid(),
                topic: "Topic",
                messageType: MessageType.MT_EVENT,
                timeStamp: DateTime.UtcNow,
                correlationId: Guid.NewGuid(),
                replyTo: "ReplyTo",
                contentType: "text/plain");

            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
            eventStoreOutbox.Add(message1);
            eventStoreOutbox.Add(message2);

            // assert
            var messages = eventStoreOutbox.Get(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);
        }