public void Connect() { try { DisposeWorkersAndTimer(); ControlWorker = WorkerFactory.CreateControlWorker(); ControlWorker.Disconnected += ControlSocketOnDisconnected; CommandWorker = WorkerFactory.CreateCommandWorker(); NavDataWorker = WorkerFactory.CreateNavDataWorker(); NavDataWorker.NavDataReceived += NavDataWorkerOnNavDataReceived; ControlWorker.Run(); CommandWorker.Run(); CommandTimer = TimerFactory.CreateTimer(); NavDataWorker.Run(); QueueInitialCommands(); Connected = true; } catch { Disconnect(); throw; } }
public void Run_CallsSocketConnectAndEnqueuesInitialCommands() { // Arrange const string pmodeCommand = "pmodeCommand"; const string miscCommand = "miscCommand"; const string configIdsCommand = "configIdsCommand"; const string sessionIdConfigCommand = "sessionIdConfigCommand"; const string profileIdConfigCommand = "profileIdConfigCommand"; const string applicationIdConfigCommand = "applicationIdConfigCommand"; const string applicationDescConfigCommand = "applicationDescConfigCommand"; const string profileDescConfigCommand = "profileDescConfigCommand"; const string sessionDescConfigCommand = "sessionDescConfigCommand"; const string expectedConfigCommand = configIdsCommand + sessionIdConfigCommand + configIdsCommand + profileIdConfigCommand + configIdsCommand + applicationIdConfigCommand + configIdsCommand + applicationDescConfigCommand + configIdsCommand + profileDescConfigCommand + configIdsCommand + sessionDescConfigCommand; _mockCommandFormatter.Setup(x => x.CreateCommand(CommandWorker.PmodeCommand, "2")).Returns(pmodeCommand); _mockCommandFormatter.Setup(x => x.CreateCommand(CommandWorker.MiscCommand, "2,20,2000,3000")).Returns(miscCommand); SetupCommandFormatterForConfigIdsCommand(configIdsCommand); SetupCommandFormatterForConfigCommand(CommandWorker.SessionIdConfigKey, _target.SessionId, sessionIdConfigCommand); SetupCommandFormatterForConfigCommand(CommandWorker.ProfileIdConfigKey, _target.ProfileId, profileIdConfigCommand); SetupCommandFormatterForConfigCommand(CommandWorker.ApplicationIdConfigKey, _target.ApplicationId, applicationIdConfigCommand); SetupCommandFormatterForConfigCommand(CommandWorker.ApplicationDescConfigKey, "AR Drone Remote", applicationDescConfigCommand); SetupCommandFormatterForConfigCommand(CommandWorker.ProfileDescConfigKey, ".Primary Profile", profileDescConfigCommand); SetupCommandFormatterForConfigCommand(CommandWorker.SessionDescConfigKey, "Session " + _target.SessionId, sessionDescConfigCommand); // Act _target.Run(); // Assert _mockUdpSocket.Verify(x => x.Connect()); _mockCommandQueue.Verify(x => x.Enqueue(pmodeCommand)); _mockCommandQueue.Verify(x => x.Enqueue(miscCommand)); _mockCommandQueue.Verify(x => x.Enqueue(expectedConfigCommand)); }