PluginSettingsTests.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;
 6  using System.Reflection;
 7  
 8  using Microsoft.Plugin.WindowWalker.Components;
 9  using Microsoft.VisualStudio.TestTools.UnitTesting;
10  
11  namespace Microsoft.Plugin.WindowWalker.UnitTests
12  {
13      [TestClass]
14      public class PluginSettingsTests
15      {
16          [TestMethod]
17          public void SettingsCount()
18          {
19              // Setup
20              PropertyInfo[] settings = WindowWalkerSettings.Instance?.GetType()?.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance);
21  
22              // Act
23              var result = settings?.Length;
24  
25              // Assert
26              Assert.AreEqual(8, result);
27          }
28  
29          [DataTestMethod]
30          [DataRow("ResultsFromVisibleDesktopOnly")]
31          [DataRow("SubtitleShowPid")]
32          [DataRow("SubtitleShowDesktopName")]
33          [DataRow("ConfirmKillProcess")]
34          [DataRow("KillProcessTree")]
35          [DataRow("OpenAfterKillAndClose")]
36          [DataRow("HideKillProcessOnElevatedProcesses")]
37          [DataRow("HideExplorerSettingInfo")]
38          public void DoesSettingExist(string name)
39          {
40              // Setup
41              Type settings = WindowWalkerSettings.Instance?.GetType();
42  
43              // Act
44              var result = settings?.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance);
45  
46              // Assert
47              Assert.IsNotNull(result);
48          }
49  
50          [DataTestMethod]
51          [DataRow("ResultsFromVisibleDesktopOnly", false)]
52          [DataRow("SubtitleShowPid", false)]
53          [DataRow("SubtitleShowDesktopName", true)]
54          [DataRow("ConfirmKillProcess", true)]
55          [DataRow("KillProcessTree", false)]
56          [DataRow("OpenAfterKillAndClose", false)]
57          [DataRow("HideKillProcessOnElevatedProcesses", false)]
58          [DataRow("HideExplorerSettingInfo", false)]
59          public void DefaultValues(string name, bool valueExpected)
60          {
61              // Setup
62              WindowWalkerSettings setting = WindowWalkerSettings.Instance;
63  
64              // Act
65              PropertyInfo propertyInfo = setting?.GetType()?.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance);
66              var result = propertyInfo?.GetValue(setting);
67  
68              // Assert
69              Assert.AreEqual(valueExpected, result);
70          }
71      }
72  }