コード例 #1
0
        public void PublishFromHandlerNotRecursiveTest()
        {
            var listener = new Listener6(_messageBus);

            _messageBus.Subscribe(listener);

            var anotherListener = new Listener1();

            _messageBus.Subscribe(anotherListener);

            var message = new Message1();

            Assert.DoesNotThrow(() => _messageBus.Publish(message));

            Assert.That(listener.ProcessedMessages, Has.Exactly(1).Items);
            Assert.AreSame(message, listener.ProcessedMessages[0]);

            Assert.That(anotherListener.ProcessedMessages, Has.Exactly(1).Items);
            Assert.AreSame(message, anotherListener.ProcessedMessages[0]);

            var anotherMessage = new Message1();

            _messageBus.Publish(anotherMessage);

            Assert.That(listener.ProcessedMessages, Has.Exactly(2).Items);
            Assert.AreSame(message, listener.ProcessedMessages[0]);
            Assert.AreSame(anotherMessage, listener.ProcessedMessages[1]);

            Assert.That(anotherListener.ProcessedMessages, Has.Exactly(2).Items);
            Assert.AreSame(message, anotherListener.ProcessedMessages[0]);
            Assert.AreSame(anotherMessage, anotherListener.ProcessedMessages[1]);
        }
        public void CanCreateProxyMethodForBasicTypeWithUpperCasing()
        {
            // Arrange
            var target = new Listener6();
            var source = new { Name = "John", Age = 1234 };

            var targetMethodInfo = target.GetType().GetMethod(nameof(Listener6.Listen));

            // Act
            var adapter  = new ProxyDiagnosticSourceMethodAdapter();
            var callback = adapter.Adapt(targetMethodInfo, source.GetType());

            var result = callback(target, source);

            // Assert
            Assert.True(result);
            Assert.Equal(target.SafeName, source.Name);
            Assert.Equal(target.SafeAge, source.Age);
        }