コード例 #1
0
        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 void When_null_args_are_supplied()
        {
            // arrange
            var eventStoreOutbox = new EventStoreOutbox(Connection);

            // act
            Func <Task> getWithoutArgs = async() => await eventStoreOutbox.MarkDispatchedAsync(Guid.Empty, DateTime.UtcNow);

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

            // act
            // act
            Func <Task> getWithoutArgs = async() => await eventStoreOutbox.MarkDispatchedAsync(Guid.Empty, DateTime.UtcNow, args);

            // assert
            getWithoutArgs.Should().Throw <ArgumentException>();
        }
        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);
        }