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


C# Bus.StartConsuming方法代码示例

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


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

示例1: StartMessageShouldCreateANewMessageBusReadStream

        public void StartMessageShouldCreateANewMessageBusReadStream()
        {
            // Arrange
            var bus = new Bus(_mockConfiguration.Object);

            var mockStream = new Mock<IMessageBusReadStream>();
            mockStream.Setup(x => x.HandlerCount).Returns(1);
            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));
            var mockProcessor = new Mock<IStreamProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IStreamProcessor>(It.Is<Dictionary<string, object>>(y => y["container"] == _mockContainer.Object))).Returns(mockProcessor.Object);
            mockProcessor.Setup(x => x.ProcessMessage(It.IsAny<FakeMessage1>(), mockStream.Object));
            _mockConfiguration.Setup(x => x.GetMessageBusReadStream()).Returns(mockStream.Object);
            var message = new FakeMessage1(Guid.NewGuid())
            {
                Username = "Tim"
            };

            bus.StartConsuming();

            // Act
            _fakeEventHandler(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)), typeof(FakeMessage1).AssemblyQualifiedName, new Dictionary<string, object>
            {
                { "Start", "" },
                { "SequenceId", Encoding.UTF8.GetBytes("TestSequence") },
                { "SourceAddress", Encoding.UTF8.GetBytes("Source") },
                { "RequestMessageId", Encoding.UTF8.GetBytes("MessageId") },
                { "MessageType", Encoding.UTF8.GetBytes("ByteStream")}
            });

            // Assert
            mockProcessor.Verify(x => x.ProcessMessage(It.IsAny<FakeMessage1>(), It.IsAny<IMessageBusReadStream>()), Times.Once);
        }
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:32,代码来源:ProcessStreamMessageTests.cs

示例2: StartConsumingShouldGetAllHandlerTypesFromContainer

        public void StartConsumingShouldGetAllHandlerTypesFromContainer()
        {
            // Arrange
            var bus = new Bus(_mockConfiguration.Object);
            _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(new List<HandlerReference>());

            // Act
            bus.StartConsuming();

            // Assert
            // One time for handlers and one time for aggregators
            _mockContainer.Verify(x => x.GetHandlerTypes(), Times.Exactly(2));
            _mockContainer.VerifyAll();
        }
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:14,代码来源:BusTests.cs

示例3: ShouldMutateMessage

        public void ShouldMutateMessage()
        {
            // Arrange
            var bus = new Bus(_mockConfiguration.Object);

            var headers = new Dictionary<string, object>
            {
                { "MessageType", Encoding.ASCII.GetBytes("Send") }
            };

            _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(_handlerReferences);
            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));
            var mockMessageHandlerProcessor = new Mock<IMessageHandlerProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IMessageHandlerProcessor>(It.Is<Dictionary<string, object>>(y => y["container"] == _mockContainer.Object))).Returns(mockMessageHandlerProcessor.Object);
            mockMessageHandlerProcessor.Setup(x => x.ProcessMessage<FakeMessage1>(It.IsAny<string>(), It.Is<IConsumeContext>(y => y.Headers == headers)));
            var mockProcessManagerProcessor = new Mock<IProcessManagerProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IProcessManagerProcessor>(It.IsAny<Dictionary<string, object>>())).Returns(mockProcessManagerProcessor.Object);
            mockProcessManagerProcessor.Setup(x => x.ProcessMessage<FakeMessage1>(It.IsAny<string>(), It.Is<IConsumeContext>(y => y.Headers == headers)));

            _mockConfiguration.Setup(x => x.BeforeConsumingFilters).Returns(new List<Type>
            {
                typeof (BeforeFilter1)
            });

            bus.StartConsuming();

            var message = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new FakeMessage1(Guid.NewGuid())
            {
                Username = "Tim Watson"
            }));

            // Act
            _fakeEventHandler(message, typeof(FakeMessage1).AssemblyQualifiedName, headers);

            // Assert
            mockMessageHandlerProcessor.Verify(x => x.ProcessMessage<FakeMessage1>(It.Is<string>(j => JsonConvert.DeserializeObject<FakeMessage1>(j).Username == "mutated"), It.IsAny<IConsumeContext>()), Times.Once);
        }
开发者ID:jiangguang5201314,项目名称:R.MessageBus-CSharp,代码行数:37,代码来源:FilterTests.cs

示例4: ShouldSendMessageToAggregatorProcessor

        public void ShouldSendMessageToAggregatorProcessor()
        {
            // Arrange
            
            var bus = new Bus(_mockConfiguration.Object);

            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));
            var mockPersistor = new Mock<IAggregatorPersistor>();
            var mockProcessor = new Mock<IAggregatorProcessor>();
            var fakeAggregator = new FakeAggregator();

            _mockConfiguration.Setup(x => x.GetAggregatorPersistor()).Returns(mockPersistor.Object);
            _mockConfiguration.Setup(x => x.Threads).Returns(1);
            _mockContainer.Setup(x => x.GetInstance<IMessageHandlerProcessor>(It.IsAny<Dictionary<string, object>>())).Returns(new Mock<IMessageHandlerProcessor>().Object);
            _mockContainer.Setup(x => x.GetInstance<IProcessManagerProcessor>(It.IsAny<Dictionary<string, object>>())).Returns(new Mock<IProcessManagerProcessor>().Object);
            _mockConfiguration.Setup(x => x.GetAggregatorProcessor(It.IsAny<IAggregatorPersistor>(), It.IsAny<IBusContainer>(), It.IsAny<Type>())).Returns(mockProcessor.Object);
            _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(new List<HandlerReference>
            {
                new HandlerReference
                {
                    HandlerType = typeof (FakeAggregator),
                    MessageType = typeof (FakeMessage1)
                }
            });
            _mockContainer.Setup(x => x.GetInstance(typeof(FakeAggregator))).Returns(fakeAggregator);
            
            var message = new FakeMessage1(Guid.NewGuid())
            {
                Username = "Tim"
            };

            mockProcessor.Setup(x => x.ProcessMessage<FakeMessage1>(JsonConvert.SerializeObject(message)));
                
            bus.StartConsuming();

            // Act
            _fakeEventHandler(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)), typeof(FakeMessage1).AssemblyQualifiedName, new Dictionary<string, object>
            {
                { "MessageType", Encoding.UTF8.GetBytes("Send")}
            });

            // Assert
            mockProcessor.Verify(x => x.ProcessMessage<FakeMessage1>(It.Is<string>(y => JsonConvert.DeserializeObject<FakeMessage1>(y).Username == "Tim")), Times.Once);
        }
开发者ID:jiangguang5201314,项目名称:R.MessageBus-CSharp,代码行数:44,代码来源:ConsumeMessageEventTests.cs

示例5: ConsumeMessageEventShouldStopStreamIfStopMessageIsRecieved

        public void ConsumeMessageEventShouldStopStreamIfStopMessageIsRecieved()
        {
            // Arrange
            var bus = new Bus(_mockConfiguration.Object);

            var mockStream = new Mock<IMessageBusReadStream>();
            mockStream.Setup(x => x.HandlerCount).Returns(1);
            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));
            var mockProcessor = new Mock<IStreamProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IStreamProcessor>(It.Is<Dictionary<string, object>>(y => y["container"] == _mockContainer.Object))).Returns(mockProcessor.Object);
            mockProcessor.Setup(x => x.ProcessMessage(It.IsAny<FakeMessage1>(), mockStream.Object));
            _mockConfiguration.Setup(x => x.GetMessageBusReadStream()).Returns(mockStream.Object);

            var message = new FakeMessage1(Guid.NewGuid())
            {
                Username = "Tim"
            };

            _mockProducer.Setup(x => x.Send("Source", typeof(StreamResponseMessage), It.IsAny<byte[]>(), It.Is<Dictionary<string, string>>(y => y["ResponseMessageId"] == "MessageId")));

            bus.StartConsuming();

            _fakeEventHandler(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)), typeof(FakeMessage1).AssemblyQualifiedName, new Dictionary<string, object>
            {
                { "Start", "" },
                { "SequenceId", Encoding.UTF8.GetBytes("TestSequence") },
                { "SourceAddress", Encoding.UTF8.GetBytes("Source") },
                { "RequestMessageId", Encoding.UTF8.GetBytes("MessageId") },
                { "MessageType", Encoding.UTF8.GetBytes("ByteStream")},
                 
            });

            var streamMessage = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            // Act
            _fakeEventHandler(streamMessage, typeof(byte[]).AssemblyQualifiedName, new Dictionary<string, object>
            {
                { "SequenceId", Encoding.UTF8.GetBytes("TestSequence") },
                { "SourceAddress", Encoding.UTF8.GetBytes("Source") },
                { "RequestMessageId", Encoding.UTF8.GetBytes("MessageId") },
                { "MessageType", Encoding.UTF8.GetBytes("ByteStream")},
                { "PacketNumber", Encoding.UTF8.GetBytes("2")},
                { "Stop", "" }
            });

            // Assert 
            mockStream.Verify(x => x.Write(It.IsAny<byte[]>(), It.IsAny<long>()), Times.Never);
            mockStream.VerifySet(x => x.LastPacketNumber = 2, Times.Once);
        }
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:49,代码来源:ProcessStreamMessageTests.cs

示例6: CustomExceptionHandlerShouldBeCalledIfConsumeMessageEventThrows

        public void CustomExceptionHandlerShouldBeCalledIfConsumeMessageEventThrows()
        {
            // Arrange
            bool actionCalled = false;
            Action<Exception> action = exception => { actionCalled = true; };
            _mockConfiguration.Setup(x => x.ExceptionHandler).Returns(action);

            var bus = new Bus(_mockConfiguration.Object);

            var handlerReferences = new List<HandlerReference>
            {
                new HandlerReference
                {
                    HandlerType = typeof (FakeHandler1),
                    MessageType = typeof (FakeMessage1)
                },
                new HandlerReference
                {
                    HandlerType = typeof (FakeHandler2),
                    MessageType = typeof (FakeMessage2)
                }
            };

            var headers = new Dictionary<string, object>();

            _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(handlerReferences);

            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));

            var mockMessageHandlerProcessor = new Mock<IMessageHandlerProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IMessageHandlerProcessor>(It.Is<Dictionary<string, object>>(y => y["container"] == _mockContainer.Object))).Returns(mockMessageHandlerProcessor.Object);
            mockMessageHandlerProcessor.Setup(x => x.ProcessMessage<FakeMessage1>(It.IsAny<string>(), It.Is<IConsumeContext>(y => y.Headers == headers))).Throws(new Exception());

            bus.StartConsuming();

            // Act
            _fakeEventHandler(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new FakeMessage1(Guid.NewGuid())
            {
                Username = "Tim Watson"
            })), typeof(FakeMessage2).FullName, headers);

            // Assert
            Assert.True(actionCalled);
        }
开发者ID:R-Suite,项目名称:ServiceConnect-CSharp,代码行数:44,代码来源:BusTests.cs

示例7: ConsumeMessageEventShouldProcessResponseMessage

        public void ConsumeMessageEventShouldProcessResponseMessage()
        {
            // Arrange
            var mockProducer = new Mock<IProducer>();
            var mockRequestConfiguration = new Mock<IRequestConfiguration>();
            _mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);

            var bus = new Bus(_mockConfiguration.Object);

            var handlerReferences = new List<HandlerReference>
            {
                new HandlerReference
                {
                    HandlerType = typeof (FakeHandler1),
                    MessageType = typeof (FakeMessage1)
                },
                new HandlerReference
                {
                    HandlerType = typeof (FakeHandler2),
                    MessageType = typeof (FakeMessage2)
                }
            };

            var headers = new Dictionary<string, object>
            {
                { "MessageType", Encoding.ASCII.GetBytes("Send") }
            };
            _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(handlerReferences);
            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));
            var mockMessageHandlerProcessor = new Mock<IMessageHandlerProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IMessageHandlerProcessor>(It.Is<Dictionary<string, object>>(y => y["container"] == _mockContainer.Object))).Returns(mockMessageHandlerProcessor.Object);
            mockMessageHandlerProcessor.Setup(x => x.ProcessMessage<FakeMessage2>(It.IsAny<string>(), It.Is<IConsumeContext>(y => y.Headers == headers)));
            var mockProcessManagerProcessor = new Mock<IProcessManagerProcessor>();
            _mockContainer.Setup(x => x.GetInstance<IProcessManagerProcessor>(It.IsAny<Dictionary<string, object>>())).Returns(mockProcessManagerProcessor.Object);
            mockProcessManagerProcessor.Setup(x => x.ProcessMessage<FakeMessage2>(It.IsAny<string>(), It.Is<IConsumeContext>(y => y.Headers == headers)));

            _mockConfiguration.Setup(x => x.GetRequestConfiguration(It.Is<Guid>(y => SetCorrelationId(y)))).Returns(mockRequestConfiguration.Object);
            var task = new Task(() => { });
            mockRequestConfiguration.Setup(x => x.SetHandler(It.IsAny<Action<object>>())).Returns(task);

            var id = Guid.NewGuid();

            var message = new FakeMessage1(id)
            {
                Username = "Tim Watson"
            };

            mockProducer.Setup(x => x.Send(It.IsAny<Type>(), It.IsAny<byte[]>(), It.IsAny<Dictionary<string, string>>()));

            bus.SendRequest<FakeMessage1, FakeMessage2>(message, x => { }, null);
            bus.StartConsuming();

            headers["SourceAddress"] = Encoding.ASCII.GetBytes(_correlationId.ToString());

            var message2 = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new FakeMessage2(id)
            {
            }));

            // Act
            _fakeEventHandler(message2, typeof(FakeMessage2).AssemblyQualifiedName, headers);

            // Assert
            mockMessageHandlerProcessor.Verify(x => x.ProcessMessage<FakeMessage2>(It.Is<string>(y => ((FakeMessage2)JsonConvert.DeserializeObject(y, typeof(FakeMessage2))).CorrelationId == id), It.Is<IConsumeContext>(y => y.Headers == headers)), Times.Once);
        }
开发者ID:R-Suite,项目名称:ServiceConnect-CSharp,代码行数:64,代码来源:BusTests.cs

示例8: StartConsumingShouldConsumeAllMessageTypes

        public void StartConsumingShouldConsumeAllMessageTypes()
        {
            // Arrange
            var bus = new Bus(_mockConfiguration.Object);
            _mockConsumer.Setup(x => x.ConsumeMessageType(It.IsAny<string>()));

            var handlerReferences = new List<HandlerReference>
            {
                new HandlerReference
                {
                    HandlerType = typeof (FakeHandler1),
                    MessageType = typeof (FakeMessage1)
                },
                new HandlerReference
                {
                    HandlerType = typeof (FakeHandler2),
                    MessageType = typeof (FakeMessage2)
                }
            };

            _mockContainer.Setup(x => x.GetHandlerTypes()).Returns(handlerReferences);

            _mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.Is<IList<string>>(m => m.Contains(typeof(FakeMessage1).FullName.Replace(".", string.Empty)) && m.Contains(typeof(FakeMessage2).FullName.Replace(".", string.Empty))), It.IsAny<ConsumerEventHandler>(), It.IsAny<IConfiguration>()));

            // Act
            bus.StartConsuming();

            // Assert
            _mockContainer.VerifyAll();
            _mockConsumerPool.Verify(x => x.AddConsumer(It.IsAny<string>(), It.Is<IList<string>>(m => m.Contains(typeof(FakeMessage1).FullName.Replace(".", string.Empty)) && m.Contains(typeof(FakeMessage2).FullName.Replace(".", string.Empty))), It.IsAny<ConsumerEventHandler>(), It.IsAny<IConfiguration>()), Times.Once);
        }
开发者ID:R-Suite,项目名称:ServiceConnect-CSharp,代码行数:31,代码来源:BusTests.cs


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