WoxTest.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.Runtime.CompilerServices; 6 using System.Windows.Input; 7 8 using Microsoft.VisualStudio.TestTools.UnitTesting; 9 using PowerLauncher.ViewModel; 10 using Wox.Plugin; 11 12 namespace Wox.Test 13 { 14 [TestClass] 15 public class WoxTest 16 { 17 // A Dummy class to test that OnPropertyChanged() is called while we set the variable 18 private sealed class DummyTestClass : BaseModel 19 { 20 public bool IsFunctionCalled { get; set; } 21 22 private ICommand _item; 23 24 public ICommand Item 25 { 26 get 27 { 28 return _item; 29 } 30 31 set 32 { 33 if (value != _item) 34 { 35 _item = value; 36 OnPropertyChanged(); 37 } 38 } 39 } 40 41 // Overriding the OnPropertyChanged() function to test if it is being called 42 protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) 43 { 44 IsFunctionCalled = true; 45 } 46 } 47 48 [TestMethod] 49 public void AnyVariableMustCallOnPropertyChangedWhenSet() 50 { 51 // Arrange 52 DummyTestClass testClass = new DummyTestClass(); 53 54 // Act 55 testClass.Item = new RelayCommand(null); 56 57 // Assert 58 Assert.IsTrue(testClass.IsFunctionCalled); 59 } 60 } 61 }