Пример #1
0
        public void When_storing_multiple_entries_exists_should_find()
        {
            //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 firstCommandExists = inbox.Exists <SimpleCommand>(commands[0].Id, contextKey);
            var lastCommandExists  = inbox.Exists <SimpleCommand>(commands[4].Id, contextKey);

            //Assert
            firstCommandExists.Should().BeTrue();
            lastCommandExists.Should().BeTrue();
        }
Пример #2
0
        public void WhenInsertingADefaultInboxIntoThePublishPipeline()
        {
            //act
            var @event = new MyEvent();

            _commandProcessor.Publish(@event);

            //assert we are in, and auto-context added us under our name
            var boxed = _inbox.Exists <MyEvent>(@event.Id, typeof(MyGlobalInboxEventHandler).FullName, 100);

            boxed.Should().BeTrue();
        }
Пример #3
0
        public void When_testing_for_a_missing_command()
        {
            //Arrange
            var          inbox      = new InMemoryInbox();
            const string contextKey = "Developer_Test";

            var command = new SimpleCommand();

            //Act
            var exists = inbox.Exists <SimpleCommand>(command.Id, contextKey);

            //Assert
            exists.Should().BeFalse();
        }
Пример #4
0
        public void WhenInsertingADefaultInboxIntoTheSendPipeline()
        {
            //act
            var command = new MyCommand()
            {
                Value = "Inbox Capture"
            };

            _commandProcessor.Send(command);

            //assert we are in, and auto-context added us under our name
            var boxed = _inbox.Exists <MyCommand>(command.Id, typeof(MyCommandHandler).FullName, 100);

            boxed.Should().BeTrue();
        }
Пример #5
0
        public void When_storing_many_but_not_requested_exists_should_not_find()
        {
            //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 firstCommandExists = inbox.Exists <SimpleCommand>(Guid.NewGuid(), contextKey);

            //Assert
            firstCommandExists.Should().BeFalse();
        }
        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();
        }