Settings.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System.Collections.Generic;
 6  using Microsoft.CmdPal.Ext.Shell.Helpers;
 7  
 8  namespace Microsoft.CmdPal.Ext.Shell.UnitTests;
 9  
10  public class Settings : ISettingsInterface
11  {
12      private readonly bool leaveShellOpen;
13      private readonly string shellCommandExecution;
14      private readonly bool runAsAdministrator;
15      private readonly Dictionary<string, int> count;
16  
17      public Settings(
18          bool leaveShellOpen = false,
19          string shellCommandExecution = "0",
20          bool runAsAdministrator = false,
21          Dictionary<string, int> count = null)
22      {
23          this.leaveShellOpen = leaveShellOpen;
24          this.shellCommandExecution = shellCommandExecution;
25          this.runAsAdministrator = runAsAdministrator;
26          this.count = count ?? new Dictionary<string, int>();
27      }
28  
29      public bool LeaveShellOpen => leaveShellOpen;
30  
31      public string ShellCommandExecution => shellCommandExecution;
32  
33      public bool RunAsAdministrator => runAsAdministrator;
34  
35      public Dictionary<string, int> Count => count;
36  
37      public void AddCmdHistory(string cmdName)
38      {
39          count[cmdName] = count.TryGetValue(cmdName, out var currentCount) ? currentCount + 1 : 1;
40      }
41  
42      public static Settings CreateDefaultSettings() => new Settings();
43  
44      public static Settings CreateLeaveShellOpenSettings() => new Settings(leaveShellOpen: true);
45  
46      public static Settings CreatePowerShellSettings() => new Settings(shellCommandExecution: "1");
47  
48      public static Settings CreateAdministratorSettings() => new Settings(runAsAdministrator: true);
49  }