Beispiel #1
0
        public void It_should_capture_messages_after_start()
        {
            var messages = new[]
            {
                new TestMessage("123"),
                new TestMessage("456"),
                new TestMessage("789")
            };

            _source.Publish(new TestMessage("000"));
            using var listener = MessageListener.Start(_source);

            foreach (var msg in messages)
            {
                _source.Publish(msg);
            }

            Assert.That(listener.GetMessages <TestMessage>(), Is.EquivalentTo(messages));
        }
        public async Task EnsureReceived_returns_latest_message_matching_criteria_if_it_has_been_already_received()
        {
            using var listener = MessageListener.Start(_source);
            _source.Publish(new TestMessage("001")
            {
                Text = "foo"
            });
            _source.Publish(new TestMessage("002")
            {
                Text = "bar"
            });
            var msg3 = _source.Publish(new TestMessage("003")
            {
                Text = "foo"
            });

            var actual = await listener.EnsureReceived <TestMessage>(x => x.Text == "foo");

            Assert.That(actual, Is.SameAs(msg3));
        }
        public void GetMessages_Of_Object_should_return_all_received_messages()
        {
            var msg1 = 55;
            var msg2 = "string";
            var msg3 = new TestMessage("000");

            using var listener = MessageListener.Start(_source);
            _source.Publish(msg1);
            _source.Publish(msg2);
            _source.Publish(msg3);
            Assert.That(listener.GetMessages <object>(), Is.EquivalentTo(new object[] { msg1, msg2, msg3 }));
        }
        public async Task EnsureReceivedMany_returns_specified_amount_of_messages_matching_criteria_in_order_from_latest_to_oldest()
        {
            using var listener = MessageListener.Start(_source);
            var msg1 = _source.Publish(new TestMessage("001")
            {
                Text = "foo"
            });

            _source.Publish(new TestMessage("002")
            {
                Text = "bar"
            });
            var msg3 = _source.Publish(new TestMessage("003")
            {
                Text = "foo"
            });

            var receiveTask = listener.EnsureReceivedMany <TestMessage>(4, x => x.Text == "foo");
            var msg4        = _source.Publish(new TestMessage("004")
            {
                Text = "foo"
            });
            var msg5 = _source.Publish(new TestMessage("005")
            {
                Text = "foo"
            });

            _source.Publish(new TestMessage("006")
            {
                Text = "foo"
            });

            var actual = await receiveTask;

            Assert.That(actual, Is.EqualTo(new[] { msg5, msg4, msg3, msg1 }));
        }