Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Not all command line arguments provided.\nPlease provide accessCode and TeamId.\nPress any key to continue...");
                Console.ReadKey();
                return;
            }

            var serverUrl  = args[0];
            var accessCode = args[1];
            var teamName   = args[2];

            IConnectionFactory connectionFactory = new ConnectionFactory()
            {
                HostName = serverUrl
            };
            IRabbitClient rabbitClient = new RabbitClient(teamName, accessCode, new ChannelRegistry(), new QueueRegistry(), connectionFactory);
            IPilotApi     pilotApi     = new PilotApi(rabbitClient, accessCode, teamName);
            IPilot        pilot        = new Pilot.Pilot(pilotApi);

            pilotApi.ConnectToRabbitMq();
            pilot.SubscribeToAllChannels();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void GivenRabbitClient_WhenSubscribedToStop_ThenReceivesMessages()
        {
            var pilotApi = new PilotApi(rabbitClientMock.Object, "Team-0", "Team-0");

            pilotApi.SubscribeOnRaceEnd((message) => { });
            rabbitClientMock.Verify(mock => mock.Subscribe(It.IsAny <Action <StopMessage> >()));
        }
Exemplo n.º 3
0
        public void GivenRabbitClient_WhenPowerMessageSent_ThenRabbitReceivesAMessage()
        {
            var pilotApi = new PilotApi(rabbitClientMock.Object, "Team-0", "Team-0");

            pilotApi.SetPower(100);

            rabbitClientMock.Verify(mock => mock.Publish(It.IsAny <string>(), RoutingKeyNames.Power, It.IsAny <string>()));
        }
Exemplo n.º 4
0
        public void GivenPilotApiAndRabbitClient_WhenHostNameIsOkAndServerIsRunning_ThenConnectionCreationIsCalled()
        {
            var rabbitClient = new RabbitClient("Team-0", "Team-0", new ChannelRegistry(), new QueueRegistry(), connectionFactoryMock.Object);

            rabbitClient.Log = logMock.Object;

            var pilotApi = new PilotApi(rabbitClient, "Team-0", "Team-0");

            pilotApi.ConnectToRabbitMq();

            connectionFactoryMock.Verify(connectionFactory => connectionFactory.CreateConnection());
        }
Exemplo n.º 5
0
        public void GivenPilotApiAndRabbitClient_WhenConnectionIsCreatedAndSubscribeCalled_ThenSubscriptionIsBeingCreated()
        {
            var connectionFactory = new ConnectionFactory()
            {
                HostName = "localhost"
            };
            var rabbitClient = new RabbitClient("Team-0", "Team-0", channelRegistryMock.Object, queueRegistryMock.Object, connectionFactory);

            rabbitClient.Log = logMock.Object;

            var pilotApi = new PilotApi(rabbitClient, "Team-0", "Team-0");

            pilotApi.ConnectToRabbitMq();
            pilotApi.SubscribeOnSensor((msg) => { });

            logMock.Verify(mock => mock.Info("Subscribed to sensor messages."));
        }
Exemplo n.º 6
0
        public void GivenPilotApiAndRabbitClient_WhenConnectionIsCreatedAndPublishCalled_ThenChannelExchangeDeclareIsCalled()
        {
            ChannelRegistry channelRegistry;
            var             connectionFactory = new ConnectionFactory()
            {
                HostName = "localhost"
            };
            var rabbitClient = new RabbitClient("Team-0", "Team-0", channelRegistry = new ChannelRegistry(), new QueueRegistry(), connectionFactory);

            rabbitClient.Log = logMock.Object;

            var pilotApi = new PilotApi(rabbitClient, "Team-0", "Team-0");

            pilotApi.ConnectToRabbitMq();
            channelRegistry.Channels["Team-0" + "-" + RoutingKeyNames.Power] = channelMock.Object;

            pilotApi.SetPower(120);

            channelMock.Verify(mock => mock.ExchangeDeclare(It.IsAny <string>(), "direct", false, false, null));
        }