public async Task ExecuteAsync_SetCommandNoValue_SetToDefault() { IFileSystem fileSystem = new MockedFileSystem(); IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider(); UserFolderPreferences preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, TestDefaultPreferences.GetDefaultPreferences()); HttpClient httpClient = new HttpClient(); HttpState httpState = new HttpState(fileSystem, preferences, httpClient); MockedShellState shellState = new MockedShellState(); PrefCommand command = new PrefCommand(preferences); // First, set it to something other than the default and make sure that works. string firstCommandExpectedValue = "BoldMagenta"; string firstCommandText = $"pref set {WellKnownPreference.ProtocolColor} {firstCommandExpectedValue}"; ICoreParseResult firstParseResult = CoreParseResultHelper.Create(firstCommandText); await command.ExecuteAsync(shellState, httpState, firstParseResult, CancellationToken.None); Assert.Empty(shellState.Output); Assert.Equal(firstCommandExpectedValue, preferences.CurrentPreferences[WellKnownPreference.ProtocolColor]); // Then, set it to nothing and make sure it goes back to the default string secondCommandText = $"pref set {WellKnownPreference.ProtocolColor}"; ICoreParseResult secondParseResult = CoreParseResultHelper.Create(secondCommandText); await command.ExecuteAsync(shellState, httpState, secondParseResult, CancellationToken.None); Assert.Empty(shellState.Output); Assert.Equal(preferences.DefaultPreferences[WellKnownPreference.ProtocolColor], preferences.CurrentPreferences[WellKnownPreference.ProtocolColor]); }
public async Task ExecuteAsync_SetDefaultEditorToVSCode_ShowsWarning(string commandText, OSPlatform intendedPlatform) { // Arrange Arrange($"pref set {WellKnownPreference.DefaultEditorCommand} \"{commandText}\"", out HttpState httpState, out MockedShellState shellState, out ICoreParseResult parseResult, out UserFolderPreferences preferences); PrefCommand command = new PrefCommand(preferences, new NullTelemetry()); string expectedWarning = string.Format(Resources.Strings.PrefCommand_Set_VSCode, WellKnownPreference.DefaultEditorArguments).SetColor(httpState.WarningColor); // Act await command.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); // Assert if (RuntimeInformation.IsOSPlatform(intendedPlatform)) { Assert.Contains(expectedWarning, shellState.Output, StringComparer.CurrentCulture); } else { Assert.DoesNotContain(expectedWarning, shellState.Output, StringComparer.CurrentCulture); } }
private static void Arrange(string commandText, out HttpState httpState, out MockedShellState shellState, out ICoreParseResult parseResult, out PrefCommand command, out UserFolderPreferences preferences) { IFileSystem fileSystem = new MockedFileSystem(); IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider(); preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, TestDefaultPreferences.GetDefaultPreferences()); HttpClient httpClient = new HttpClient(); httpState = new HttpState(fileSystem, preferences, httpClient); shellState = new MockedShellState(); parseResult = CoreParseResultHelper.Create(commandText); command = new PrefCommand(preferences); }
public async Task ExecuteAsync_WithGetAndUnknownName_SendsTelemetryWithHashedName() { Arrange("pref set preferenceName value", out HttpState httpState, out MockedShellState shellState, out ICoreParseResult parseResult, out UserFolderPreferences preferences); TelemetryCollector telemetry = new TelemetryCollector(); PrefCommand command = new PrefCommand(preferences, telemetry); await command.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Single(telemetry.Telemetry); TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0]; Assert.Equal("Preference", collectedTelemetry.EventName); Assert.Equal("Set", collectedTelemetry.Properties["GetOrSet"]); Assert.Equal(Sha256Hasher.Hash("preferenceName"), collectedTelemetry.Properties["PreferenceName"]); }
public async Task ExecuteAsync_WithSet_SendsTelemetry() { Arrange($"pref set {WellKnownPreference.DefaultEditorCommand} value", out HttpState httpState, out MockedShellState shellState, out ICoreParseResult parseResult, out UserFolderPreferences preferences); TelemetryCollector telemetry = new TelemetryCollector(); PrefCommand command = new PrefCommand(preferences, telemetry); await command.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Single(telemetry.Telemetry); TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0]; Assert.Equal("Preference", collectedTelemetry.EventName); Assert.Equal("Set", collectedTelemetry.Properties["GetOrSet"]); Assert.Equal(WellKnownPreference.DefaultEditorCommand, collectedTelemetry.Properties["PreferenceName"]); }