Ejemplo n.º 1
0
        public DynamoDbOutboxMessageAlreadyExistsTests()
        {
            _messageEarliest = new Message(new MessageHeader(Guid.NewGuid(), "test_topic", MessageType.MT_DOCUMENT), new MessageBody("message body"));
            _dynamoDbOutbox  = new DynamoDbOutbox(Client, new DynamoDbConfiguration(Credentials, RegionEndpoint.EUWest1, TableName));

            _dynamoDbOutbox.AddAsync(_messageEarliest).Wait();
        }
        public async Task When_the_message_is_already_in_the_outbox_async()
        {
            await DynamoDbOutbox.AddAsync(_messageEarliest);

            _exception = await Catch.ExceptionAsync(() => DynamoDbOutbox.AddAsync(_messageEarliest));

            //_should_ignore_the_duplicate_key_and_still_succeed
            _exception.Should().BeNull();
        }
        public async Task When_writing_messages_to_the_outbox_async()
        {
            await DynamoDbOutbox.AddAsync(_messageEarliest);

            await DynamoDbOutbox.AddAsync(_message2);

            await DynamoDbOutbox.AddAsync(_messageLatest);

            var retrievedMessages = (await _dynamoDbTestHelper.Scan()).ToList();

            //_should_read_the_messages_from_the__outbox
            retrievedMessages.Should().HaveCount(3);
            retrievedMessages.Single(m => m.MessageId == _guids[0].ToString()).Should().NotBeNull();
            retrievedMessages.Single(m => m.MessageId == _guids[1].ToString()).Should().NotBeNull();
            retrievedMessages.Single(m => m.MessageId == _guids[2].ToString()).Should().NotBeNull();
        }
        public async Task When_there_are_multiple_messages_in_the_outbox_and_a_range_by_index_is_fetched()
        {
            await DynamoDbOutbox.AddAsync(_messageEarliest);

            await Task.Delay(100);

            await DynamoDbOutbox.AddAsync(_message1);

            await Task.Delay(100);

            await DynamoDbOutbox.AddAsync(_message2);

            var exception = await Catch.ExceptionAsync(() => DynamoDbOutbox.GetAsync(1, 3));

            exception.Should().BeOfType <NotSupportedException>();
        }
        public async Task When_writing_a_message_to_the_dynamo_db_outbox()
        {
            await _dynamoDbOutbox.AddAsync(_messageEarliest);

            _storedMessage = await _dynamoDbOutbox.GetAsync(_messageEarliest.Id);

            //_should_read_the_message_from_the__sql_outbox
            _storedMessage.Body.Value.Should().Be(_messageEarliest.Body.Value);
            //_should_read_the_message_header_first_bag_item_from_the__sql_outbox
            _storedMessage.Header.Bag.ContainsKey(_key1).Should().BeTrue();
            _storedMessage.Header.Bag[_key1].Should().Be(_value1);
            //_should_read_the_message_header_second_bag_item_from_the__sql_outbox
            _storedMessage.Header.Bag.ContainsKey(_key2).Should().BeTrue();
            _storedMessage.Header.Bag[_key2].Should().Be(_value2);
            //_should_read_the_message_header_timestamp_from_the__sql_outbox
            _storedMessage.Header.TimeStamp.Should().Be(_messageEarliest.Header.TimeStamp);
            //_should_read_the_message_header_topic_from_the__sql_outbox
            _storedMessage.Header.Topic.Should().Be(_messageEarliest.Header.Topic);
            //_should_read_the_message_header_type_from_the__sql_outbox
            _storedMessage.Header.MessageType.Should().Be(_messageEarliest.Header.MessageType);
        }