Fix for Memory issue with context menu items (#4597)

* Added the inotifyPropertyChanged to all the properties and that stops the memory for shooting up

* some more inotify properties added

(cherry picked from commit 26fa05d9b661dadc5ab0257d540ab838a07c43a6)

* Revert "some more inotify properties added"

This reverts commit 845a94c9b2.

* Removed unnecessary inotifypropertychanged interfaces and cleaned up the code

* removed the ctrl+c from folder plugin

* removed unnecessary init

* Added unit test to check if PropertyChanged is called

* renamed var

* refactored the tests

* formatting and adding comments

* changed access modifier in test

* Used observable collection instead of a list

* clearing the observable collection instead of setting it to a new one
This commit is contained in:
Alekhya
2020-07-02 13:48:41 -07:00
committed by GitHub
parent 593ab6b014
commit 18f4e9db31
5 changed files with 91 additions and 19 deletions

View File

@@ -44,6 +44,7 @@
<ProjectReference Include="..\Wox.Core\Wox.Core.csproj" />
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
<ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj" />
<ProjectReference Include="..\Wox\Wox.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,58 @@
using System.Windows.Input;
using NUnit.Framework;
using Wox.Plugin;
using Wox.ViewModel;
using System.Runtime.CompilerServices;
namespace Wox.Test
{
[TestFixture]
public class Wox
{
// A Dummy class to test that OnPropertyChanged() is called while we set the variable
public class DummyTestClass : BaseModel
{
public bool isFunctionCalled = false;
private ICommand _item;
public ICommand Item
{
get
{
return this._item;
}
set
{
if (value != this._item)
{
this._item = value;
OnPropertyChanged();
}
}
}
// Overriding the OnPropertyChanged() function to test if it is being called
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
isFunctionCalled = true;
}
}
[Test]
public void AnyVariable_MustCallOnPropertyChanged_WhenSet()
{
// Arrange
DummyTestClass testClass = new DummyTestClass();
// Act
testClass.Item = new RelayCommand(null);
// Assert
Assert.IsTrue(testClass.isFunctionCalled);
}
}
}