2020-08-06 05:06:55 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2020-08-11 06:49:36 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-08-06 05:06:55 +08:00
|
|
|
|
using System.Windows.Input;
|
2021-08-16 21:25:06 +08:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2020-07-21 02:22:03 +08:00
|
|
|
|
using PowerLauncher.ViewModel;
|
2020-08-11 06:49:36 +08:00
|
|
|
|
using Wox.Plugin;
|
2020-07-03 04:48:41 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Test
|
|
|
|
|
{
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestClass]
|
2020-08-11 06:49:36 +08:00
|
|
|
|
public class WoxTest
|
2020-07-03 04:48:41 +08:00
|
|
|
|
{
|
|
|
|
|
// A Dummy class to test that OnPropertyChanged() is called while we set the variable
|
2020-10-22 11:13:12 +08:00
|
|
|
|
private class DummyTestClass : BaseModel
|
2020-07-03 04:48:41 +08:00
|
|
|
|
{
|
2020-10-22 11:13:12 +08:00
|
|
|
|
public bool IsFunctionCalled { get; set; }
|
2020-08-11 06:49:36 +08:00
|
|
|
|
|
2020-07-03 04:48:41 +08:00
|
|
|
|
private ICommand _item;
|
|
|
|
|
|
|
|
|
|
public ICommand Item
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-08-11 06:49:36 +08:00
|
|
|
|
return _item;
|
2020-07-03 04:48:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-08-11 06:49:36 +08:00
|
|
|
|
if (value != _item)
|
2020-07-03 04:48:41 +08:00
|
|
|
|
{
|
2020-08-11 06:49:36 +08:00
|
|
|
|
_item = value;
|
2020-07-03 04:48:41 +08:00
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Overriding the OnPropertyChanged() function to test if it is being called
|
|
|
|
|
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
2020-08-11 06:49:36 +08:00
|
|
|
|
IsFunctionCalled = true;
|
2020-07-03 04:48:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:25:06 +08:00
|
|
|
|
[TestMethod]
|
2020-10-22 11:13:12 +08:00
|
|
|
|
public void AnyVariableMustCallOnPropertyChangedWhenSet()
|
2020-07-03 04:48:41 +08:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
DummyTestClass testClass = new DummyTestClass();
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
testClass.Item = new RelayCommand(null);
|
|
|
|
|
|
|
|
|
|
// Assert
|
2020-08-11 06:49:36 +08:00
|
|
|
|
Assert.IsTrue(testClass.IsFunctionCalled);
|
2020-07-03 04:48:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|