Esempio n. 1
0
        public void When_storing_multiple_entries_retrieve_the_right_one()
        {
            //Arrange
            var          inbox      = new InMemoryInbox();
            const string contextKey = "Developer_Test";

            var commands = new SimpleCommand[] { new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand(), new SimpleCommand() };

            foreach (var command in commands)
            {
                inbox.Add(command, contextKey);
            }

            //Act
            var firstCommand = inbox.Get <SimpleCommand>(commands[0].Id, contextKey);
            var lastCommand  = inbox.Get <SimpleCommand>(commands[4].Id, contextKey);

            //Assert
            firstCommand.Should().NotBeNull();
            lastCommand.Should().NotBeNull();

            firstCommand.Id.Should().Be(commands[0].Id, contextKey);
            lastCommand.Id.Should().Be(commands[4].Id, contextKey);
        }
Esempio n. 2
0
        public void When_storing_a_seen_message_in_the_inbox()
        {
            //Arrange
            var          inbox      = new InMemoryInbox();
            const string contextKey = "Developer_Test";

            var command = new SimpleCommand();

            //Act
            inbox.Add(command, contextKey);

            var storedCommand = inbox.Get <SimpleCommand>(command.Id, contextKey);

            //Assert
            storedCommand.Should().NotBeNull();
            storedCommand.Id.Should().Be(command.Id);
        }
        public void When_expiring_a_cache_entry_no_longer_there()
        {
            //Arrange
            const string contextKey = "Inbox_Cache_Expiry_Tests";

            var inbox = new InMemoryInbox()
            {
                //set some aggressive outbox reclamation times for the test
                EntryTimeToLive        = TimeSpan.FromMilliseconds(50),
                ExpirationScanInterval = TimeSpan.FromMilliseconds(100)
            };

            var command = new SimpleCommand();

            //Act
            inbox.Add(command, contextKey);

            Task.Delay(500).Wait(); //give the entry to time to expire

            //Trigger a cache clean
            SimpleCommand foundCommand = null;

            try
            {
                foundCommand = inbox.Get <SimpleCommand>(command.Id, contextKey);
            }
            catch (Exception e) when(e is RequestNotFoundException <SimpleCommand> || e is TypeLoadException)
            {
                //early sweeper run means it doesn't exist already
            }

            Task.Delay(500).Wait(); //Give the sweep time to run

            var afterExpiryExists = inbox.Exists <SimpleCommand>(command.Id, contextKey);

            //Assert
            foundCommand.Should().NotBeNull();
            afterExpiryExists.Should().BeFalse();
        }