Exemplo n.º 1
0
        public void EventSubscriberListensOnAppropriateQueue_And_InvokesMemberLocationReceivedEvent()
        {
            var logger       = new Mock <ILogger <AMQPEventingConsumer> >();
            var logger2      = new Mock <ILogger <AMQPEventSubscriber> >();
            var queueOptions = new QueueOptions {
                ProximityDetectedEventQueueName      = "proximitydetected",
                MemberLocationRecordedEventQueueName = "memberlocationrecorded"
            };
            var options = new Mock <IOptions <QueueOptions> >();

            options.Setup(o => o.Value).Returns(queueOptions);

            var factory    = new Mock <IConnectionFactory>();
            var connection = new Mock <IConnection>();
            var model      = new Mock <IModel>();

            connection.Setup(c => c.CreateModel()).Returns(model.Object);
            factory.Setup(f => f.CreateConnection()).Returns(connection.Object);

            var consumer = new FakeConsumer(logger.Object, factory.Object);

            AMQPEventSubscriber         subscriber    = new AMQPEventSubscriber(logger2.Object, options.Object, consumer);
            MemberLocationRecordedEvent deliveredMLRE = null;

            subscriber.MemberLocationRecordedEventReceived += (mlre) => {
                deliveredMLRE = mlre;
            };

            consumer.TriggerBasicDeliver();
            Assert.NotNull(deliveredMLRE);
            Assert.Equal(consumer.MLRE.MemberID, deliveredMLRE.MemberID);
            Assert.Equal(consumer.MLRE.Longitude, deliveredMLRE.Longitude);
        }
Exemplo n.º 2
0
        public AMQPEventPublisher(IHostingEnvironment env, AMQPEventSubscriber aMQPEventSubscriber, IConfiguration configuration)
        {
            connectionFactory = new ConnectionFactory();
            _configuration    = configuration;


            var username    = configuration["amqp:username"];
            var password    = configuration["amqp:password"];
            var hostname    = configuration["amqp:hostname"];
            var uri         = configuration["amqp:uri"];
            var virtualhost = configuration["amqp:virtualhost"];

            connectionFactory = new ConnectionFactory()
            {
                UserName    = username,
                Password    = password,
                HostName    = hostname,
                Uri         = new Uri(uri),
                VirtualHost = virtualhost
            };
        }