public void When_marking_a_message_as_dispatched_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 }
            };

            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);
        }
예제 #2
0
        public void When_null_args_are_supplied()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutboxSync(Connection);

            // act
            Action getWithoutArgs = () => eventStoreOutbox.Get(1, 1);

            // assert
            getWithoutArgs.Should().Throw <ArgumentNullException>();
        }
예제 #3
0
        public void When_empty_args_are_supplied()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutboxSync(Connection);
            var args             = new Dictionary <string, object>();

            // act
            Action getWithoutArgs = () => eventStoreOutbox.Get(1, 1, args);

            // assert
            getWithoutArgs.Should().Throw <ArgumentException>();
        }
예제 #4
0
        public void When_There_Is_No_Message_In_The_Outbox()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutboxSync(Connection);

            // act
            var messages = eventStoreOutbox.Get(StreamName, 0, 1);

            // assert
            //_returns_an_empty_list
            messages.Count.Should().Be(0);
        }
예제 #5
0
        public void When_null_stream_arg_supplied()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutboxSync(Connection);
            var args             = new Dictionary <string, object> {
                { Globals.StreamArg, null }
            };

            // act
            Action getWithoutArgs = () => eventStoreOutbox.Get(1, 1, args);

            // assert
            getWithoutArgs.Should().Throw <ArgumentException>();
        }
예제 #6
0
        public void When_there_are_multiple_messages_in_the_outbox_and_a_range_is_fetched()
        {
            // 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);

            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);
        }
예제 #7
0
        public void When_Writing_Messages_To_The_Outbox()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutboxSync(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);
        }