public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { StartCommandResult result = StartCommandResult.Sticky; bool?run = null; if (intent != null) { if (intent.GetBooleanExtra(PARAM_START, false)) { LogsManager.Instance.Debug("VPNService.OnStartCommand: START"); run = true; } else if (intent.GetBooleanExtra(PARAM_STOP, false)) { LogsManager.Instance.Debug("VPNService.OnStartCommand: STOP"); run = false; } } else { LogsManager.Instance.Debug("VPNService.OnStartCommand (no intent)"); } if (run != null) { UpdateService(run.Value, intent.GetBundleExtra(EXTRA_RUN_ARGS)); } return(result); }
public void Execute_NewInstanceSucceeds_ReturnsSuccessfulResult() { using (ShimsContext.Create()) { int callsToNewInstance = 0; ShimAutomationSession.NewInstanceCommandParametersIDisposable = (_, __) => { callsToNewInstance++; return(new ShimAutomationSession()); }; StartCommandResult result = StartCommand.Execute(new Dictionary <string, string>(), string.Empty); Assert.AreEqual(1, callsToNewInstance); Assert.AreEqual(true, result.Completed); Assert.AreEqual(true, result.Succeeded); Assert.IsFalse(string.IsNullOrWhiteSpace(result.SummaryMessage)); } }
public void Execute_NewInstanceThrowsAutomationException_ReturnsFailedResult() { const string exceptionMessage = "Hello from your local exception!"; using (ShimsContext.Create()) { int callsToNewInstance = 0; ShimAutomationSession.NewInstanceCommandParametersIDisposable = (_, __) => { callsToNewInstance++; throw new A11yAutomationException(exceptionMessage); }; StartCommandResult result = StartCommand.Execute(new Dictionary <string, string>(), string.Empty); Assert.AreEqual(1, callsToNewInstance); Assert.AreEqual(false, result.Completed); Assert.AreEqual(false, result.Succeeded); Assert.AreEqual(exceptionMessage, result.SummaryMessage); } }