当前位置: 首页>>代码示例>>C#>>正文


C# Bus.Publish方法代码示例

本文整理汇总了C#中Bus.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.Publish方法的具体用法?C# Bus.Publish怎么用?C# Bus.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bus的用法示例。


在下文中一共展示了Bus.Publish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanPublish

        public void CanPublish()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var message = new TestMessage();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof(TestMessage));
                SetupResult.For(connFactory.CreateConnection()).Return(conn);
                SetupResult.For(config.Exchange).Return("ex");
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
                SetupResult.For(conn.IsOpen).Return(true);

                Expect.Call(() => conn.Publish<TestMessage>(null))
                    .IgnoreArguments()
                    .WhenCalled(mi =>
                            {
                                var envelope = mi.Arguments[0];

                                Assert.IsAssignableFrom(typeof(IMessageEnvelope<TestMessage>), envelope);
                                Assert.Same(message, ((IMessageEnvelope<TestMessage>)envelope).Message);
                            });
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.Publish(message);
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:35,代码来源:BusTests.cs

示例2: EventTest

        public void EventTest()
        {
            var bus = new Bus(null, new HandlerRegistry());
            int called = 0;
            bus.Subscribe<WidgetCreatedEvent>((x) => called++);

            bus.Subscribe<WidgetCreatedEvent>((x) => called++);

            bus.Publish(new WidgetCreatedEvent());
            Assert.AreEqual(2, called);
        }
开发者ID:adbrowne,项目名称:Samples,代码行数:11,代码来源:BusTests.cs

示例3: When_testing_something

    public void When_testing_something()
    {
        var bus1 = new Bus();

            bus1.Subscribe("first", x => _output.WriteLine("Bus1 => ({0}) => {1}", "first", x.Json));
            bus1.Subscribe("second", x => _output.WriteLine("Bus1 => ({0}) => {1}", "second", x.Json));

            var bus2 = new Bus();

            bus2.Subscribe("first", x => _output.WriteLine("Bus2 => ({0}) => {1}", "first", x.Json));
            bus2.Subscribe("second", x => _output.WriteLine("Bus2 => ({0}) => {1}", "second", x.Json));

            var exchange = new Exchange();
            exchange.AddBus(bus1);
            exchange.AddBus(bus2);

            bus1.Publish("first", new Message { Json = "a message"});
    }
开发者ID:Pondidum,项目名称:InProcessMicroServices,代码行数:18,代码来源:notes.cs

示例4: PublishShouldGetProducerFromContainer

        public void PublishShouldGetProducerFromContainer()
        {
            // Arrange
            var mockConfiguration = new Mock<IConfiguration>();
            var mockProducer = new Mock<IProducer>();
            var mockContainer = new Mock<IBusContainer>();
            var mockProessManagerFinder = new Mock<IProcessManagerFinder>();

            mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
            mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
            mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
            mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings ());

            // Act
            var bus = new Bus(mockConfiguration.Object);
            bus.Publish(new FakeMessage1(Guid.NewGuid()), null);

            // Assert
            mockConfiguration.Verify(x => x.GetProducer(), Times.Once());
        }
开发者ID:R-Suite,项目名称:ServiceConnect-CSharp,代码行数:20,代码来源:BusTests.cs

示例5: CreatesNewConnectionIfConnectionClosedWhenPublishing

        public void CreatesNewConnectionIfConnectionClosedWhenPublishing()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var message = new TestMessage();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof (TestMessage));
                SetupResult.For(config.Exchange).Return("ex");
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
                SetupResult.For(conn.IsOpen).Return(false);

                Expect.Call(connFactory.CreateConnection()).Repeat.Times(4).Return(conn);
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.Publish(message);
                bus.Publish(message);
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:27,代码来源:BusTests.cs


注:本文中的Bus.Publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。