/ src / modules / cmdpal / Tests / Microsoft.CmdPal.Ext.WebSearch.UnitTests / SettingsManagerTests.cs
SettingsManagerTests.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.Threading.Tasks; 7 8 using Microsoft.CmdPal.Ext.UnitTestBase; 9 using Microsoft.CmdPal.Ext.WebSearch.Helpers; 10 using Microsoft.CmdPal.Ext.WebSearch.Pages; 11 using Microsoft.VisualStudio.TestTools.UnitTesting; 12 13 namespace Microsoft.CmdPal.Ext.WebSearch.UnitTests; 14 15 [TestClass] 16 public class SettingsManagerTests : CommandPaletteUnitTestBase 17 { 18 [TestMethod] 19 public async Task HistoryChangedEventIsRaisedWhenItemIsAdded() 20 { 21 // Setup 22 var settings = new MockSettingsInterface(historyItemCount: 5); 23 var browserInfoService = new MockBrowserInfoService(); 24 25 var page = new WebSearchListPage(settings, browserInfoService); 26 27 var eventRaised = false; 28 29 try 30 { 31 settings.HistoryChanged += Handler; 32 33 // Act 34 settings.AddHistoryItem(new HistoryItem("test event", DateTime.UtcNow)); 35 await Task.Delay(50); 36 37 // Assert 38 Assert.IsTrue(eventRaised, "Expected HistoryChanged to be raised when saving history."); 39 } 40 finally 41 { 42 settings.HistoryChanged -= Handler; 43 page.Dispose(); 44 } 45 46 return; 47 48 void Handler(object s, EventArgs e) => eventRaised = true; 49 } 50 }