Exemplo n.º 1
0
        private static IHandlingRule FakeHandlingRule(string pattern, QueueName queueName, QueueOptions queueOptions)
        {
            var messageSpec    = new MessageNamePatternSpecification(pattern);
            var messageHandler = new DelegateMessageHandler((o, ctx) => { });

            return(new HandlingRule(messageSpec, messageHandler, queueName, queueOptions));
        }
Exemplo n.º 2
0
        private async Task AssertRulesAdded()
        {
            var handlingRules = Configuration.HandlingRules.ToList();

            Assert.Equal(2, handlingRules.Count);

            var expectedASpec = new MessageNamePatternSpecification(@"^A$");
            var aRules        = handlingRules.Where(r => expectedASpec.Equals(r.Specification)).ToList();

            Assert.Single(aRules);

            var expectedBSpec = new MessageNamePatternSpecification(@"^B$");
            var bRules        = handlingRules.Where(r => expectedBSpec.Equals(r.Specification)).ToList();

            Assert.Single(bRules);

            var mockContext       = new Mock <IMessageContext>();
            var cancellationToken = default(CancellationToken);

            mockContext.Setup(x => x.SendReply("A", null, cancellationToken)).Returns(Task.FromResult(0)).Verifiable();
            mockContext.Setup(x => x.SendReply("B", null, cancellationToken)).Returns(Task.FromResult(0)).Verifiable();

            await aRules[0].MessageHandler.HandleMessage(new A(), mockContext.Object, cancellationToken);
            await bRules[0].MessageHandler.HandleMessage(new B(), mockContext.Object, cancellationToken);

            mockContext.Verify();
        }
Exemplo n.º 3
0
        private void AssertExplicitQueueNames()
        {
            var handlingRules = Configuration.HandlingRules.ToList();

            Assert.Equal(2, handlingRules.Count);

            var expectedASpec = new MessageNamePatternSpecification(@"^A$");
            var aRules        = handlingRules.Where(r => expectedASpec.Equals(r.Specification)).ToList();

            Assert.Single(aRules);
            Assert.Equal((QueueName)"QHA", aRules[0].QueueName);

            var expectedBSpec = new MessageNamePatternSpecification(@"^B$");
            var bRules        = handlingRules.Where(r => expectedBSpec.Equals(r.Specification)).ToList();

            Assert.Single(bRules);
            Assert.Equal((QueueName)"QHB", bRules[0].QueueName);
        }
Exemplo n.º 4
0
        protected async Task <Bus> GivenConfiguredBus(ITransportService transportService)
        {
            var allMessages            = new MessageNamePatternSpecification(".*");
            var noMatchSpecification   = new Mock <IMessageSpecification>().Object;
            var messageQueueingService = new Mock <IMessageQueueingService>();

            Configuration.AddEndpoint(DefaultEndpointName, new Endpoint(DefaultEndpointUri, DefaultEndpointCredentials));
            Configuration.AddSendRule(new SendRule(allMessages, DefaultEndpointName));

            Configuration.AddEndpoint(OtherEndpointName, new Endpoint(OtherEndpointUri, OtherEndpointCredentials));
            Configuration.AddSendRule(new SendRule(noMatchSpecification, OtherEndpointName));

            var baseUri = new Uri("http://localhost/platibus");
            var bus     = new Bus(Configuration, baseUri, transportService, messageQueueingService.Object);
            await bus.Init();

            return(bus);
        }
Exemplo n.º 5
0
        private async Task TryHandleMessages()
        {
            var handlingRules = Configuration.HandlingRules.ToList();

            Assert.Equal(2, handlingRules.Count);

            var expectedASpec = new MessageNamePatternSpecification(@"^A$");
            var aRules        = handlingRules.Where(r => expectedASpec.Equals(r.Specification)).ToList();

            Assert.Single(aRules);

            var expectedBSpec = new MessageNamePatternSpecification(@"^B$");
            var bRules        = handlingRules.Where(r => expectedBSpec.Equals(r.Specification)).ToList();

            Assert.Single(bRules);

            var mockContext       = new Mock <IMessageContext>();
            var cancellationToken = default(CancellationToken);

            await aRules[0].MessageHandler.HandleMessage(new A(), mockContext.Object, cancellationToken);
            await bRules[0].MessageHandler.HandleMessage(new B(), mockContext.Object, cancellationToken);
        }