Skip to content

Commit

Permalink
fixed propertychanged with empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas committed Oct 1, 2020
1 parent 2617907 commit ad6a286
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/Prism.Core/Commands/PropertyObserverNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ private void UnsubscribeListener()

private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
// Invoke action when e.PropertyName == null in order to satisfy:
// - DelegateCommandFixture.GenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyName
// - DelegateCommandFixture.NonGenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyName
if (e?.PropertyName == PropertyInfo.Name || e?.PropertyName == null)
if (e?.PropertyName == PropertyInfo.Name || string.IsNullOrEmpty(e?.PropertyName))
{
_action?.Invoke();
}
Expand Down
32 changes: 30 additions & 2 deletions tests/Prism.Core.Tests/Commands/DelegateCommandFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public void NonGenericDelegateCommandShouldNotObserveDuplicateProperties()
}

[Fact]
public void NonGenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyName()
public void NonGenericDelegateCommandObservingPropertyShouldRaiseOnNullPropertyName()
{
bool canExecuteChangedRaised = false;

Expand All @@ -379,6 +379,20 @@ public void NonGenericDelegateCommandObservingPropertyShouldRaiseOnEmptyProperty
Assert.True(canExecuteChangedRaised);
}

[Fact]
public void NonGenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyName()
{
bool canExecuteChangedRaised = false;

var command = new DelegateCommand(() => { }).ObservesProperty(() => IntProperty);

command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

RaisePropertyChanged(string.Empty);

Assert.True(canExecuteChangedRaised);
}

[Fact]
public void NonGenericDelegateCommandShouldObserveOneComplexProperty()
{
Expand Down Expand Up @@ -647,7 +661,7 @@ public void GenericDelegateCommandShouldNotObserveDuplicateProperties()
}

[Fact]
public void GenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyName()
public void GenericDelegateCommandObservingPropertyShouldRaiseOnNullPropertyName()
{
bool canExecuteChangedRaised = false;

Expand All @@ -660,6 +674,20 @@ public void GenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyNam
Assert.True(canExecuteChangedRaised);
}

[Fact]
public void GenericDelegateCommandObservingPropertyShouldRaiseOnEmptyPropertyName()
{
bool canExecuteChangedRaised = false;

var command = new DelegateCommand<object>((o) => { }).ObservesProperty(() => IntProperty);

command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

RaisePropertyChanged(string.Empty);

Assert.True(canExecuteChangedRaised);
}

[Fact]
public void GenericDelegateCommandNotObservingPropertiesShouldNotRaiseOnEmptyPropertyName()
{
Expand Down

0 comments on commit ad6a286

Please sign in to comment.