CloseOnEnterTests.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.Globalization;
 6  using System.Linq;
 7  using Microsoft.CmdPal.Ext.Calc.Helper;
 8  using Microsoft.CommandPalette.Extensions.Toolkit;
 9  using Microsoft.VisualStudio.TestTools.UnitTesting;
10  using Windows.Foundation;
11  
12  namespace Microsoft.CmdPal.Ext.Calc.UnitTests;
13  
14  [TestClass]
15  public class CloseOnEnterTests
16  {
17      [TestMethod]
18      public void PrimaryIsCopy_WhenCloseOnEnterTrue()
19      {
20          var settings = new Settings(closeOnEnter: true);
21          TypedEventHandler<object, object> handleSave = (s, e) => { };
22          TypedEventHandler<object, object> handleReplace = (s, e) => { };
23  
24          var item = ResultHelper.CreateResult(
25              4m,
26              CultureInfo.CurrentCulture,
27              CultureInfo.CurrentCulture,
28              "2+2",
29              settings,
30              handleSave,
31              handleReplace);
32  
33          Assert.IsNotNull(item);
34          Assert.IsInstanceOfType(item.Command, typeof(CopyTextCommand));
35  
36          var firstMore = item.MoreCommands.First();
37          Assert.IsInstanceOfType(firstMore, typeof(CommandContextItem));
38          Assert.IsInstanceOfType(((CommandItem)firstMore).Command, typeof(SaveCommand));
39      }
40  
41      [TestMethod]
42      public void PrimaryIsSave_WhenCloseOnEnterFalse()
43      {
44          var settings = new Settings(closeOnEnter: false);
45          TypedEventHandler<object, object> handleSave = (s, e) => { };
46          TypedEventHandler<object, object> handleReplace = (s, e) => { };
47  
48          var item = ResultHelper.CreateResult(
49              4m,
50              CultureInfo.CurrentCulture,
51              CultureInfo.CurrentCulture,
52              "2+2",
53              settings,
54              handleSave,
55              handleReplace);
56  
57          Assert.IsNotNull(item);
58          Assert.IsInstanceOfType(item.Command, typeof(SaveCommand));
59  
60          var firstMore = item.MoreCommands.First();
61          Assert.IsInstanceOfType(firstMore, typeof(CommandContextItem));
62          Assert.IsInstanceOfType(((CommandItem)firstMore).Command, typeof(CopyTextCommand));
63      }
64  }