-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle null/empty PropertyName in the INPC.PropertyChanged event (#8418…
…) Fixes #1111 * Remove duplicate classes and fix issue * Fix all overloads and added tests
- Loading branch information
1 parent
5ae30e0
commit 7bc3da8
Showing
6 changed files
with
153 additions
and
192 deletions.
There are no files selected for viewing
48 changes: 0 additions & 48 deletions
48
src/Compatibility/Core/src/Android/CollectionView/PropertyChangedEventArgsExtensions.cs
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
src/Compatibility/Core/src/Windows/PropertyChangedEventArgsExtensions.cs
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
src/Compatibility/Core/src/iOS/CollectionView/PropertyChangedEventArgsExtensions.cs
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
src/Controls/src/Core/Handlers/Items/iOS/PropertyChangedEventArgsExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/Controls/tests/Core.UnitTests/PropertyChangedEventArgsExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using System.ComponentModel; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class PropertyChangedEventArgsExtensionsTests : BaseTestFixture | ||
{ | ||
[Test] | ||
public void IsWithMathingStringValues() | ||
{ | ||
PropertyChangedEventArgs args = new("MyProperty"); | ||
BindableProperty bindable = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.Is(bindable)); | ||
} | ||
|
||
[Test] | ||
public void IsWithNonMathingValues() | ||
{ | ||
PropertyChangedEventArgs args = new("MyProperty"); | ||
BindableProperty bindable = BindableProperty.Create("NotMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsFalse(args.Is(bindable)); | ||
} | ||
|
||
[Test] | ||
[TestCase("")] | ||
[TestCase(null)] | ||
public void IsWithNullOrEmptyValue(string changedPropertyName) | ||
{ | ||
PropertyChangedEventArgs args = new(changedPropertyName); | ||
BindableProperty bindable = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.Is(bindable)); | ||
} | ||
|
||
[Test] | ||
public void IsOneOfTwoParameters() | ||
{ | ||
PropertyChangedEventArgs args = new("MyProperty"); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1)); | ||
} | ||
|
||
[Test] | ||
public void IsOneOfThreeParameters() | ||
{ | ||
PropertyChangedEventArgs args = new("MyProperty"); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable2 = BindableProperty.Create("AlsoMyProperty1", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1, bindable2)); | ||
} | ||
|
||
[Test] | ||
public void IsOneOfFourParameters() | ||
{ | ||
PropertyChangedEventArgs args = new("MyProperty"); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable2 = BindableProperty.Create("AlsoMyProperty1", typeof(object), typeof(object)); | ||
BindableProperty bindable3 = BindableProperty.Create("NotMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1, bindable2, bindable3)); | ||
} | ||
|
||
[Test] | ||
public void IsOneOfFiveParameters() | ||
{ | ||
PropertyChangedEventArgs args = new("MyProperty"); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable2 = BindableProperty.Create("AlsoMyProperty1", typeof(object), typeof(object)); | ||
BindableProperty bindable3 = BindableProperty.Create("NotMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable4 = BindableProperty.Create("AlsNotMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1, bindable2, bindable3, bindable4)); | ||
} | ||
|
||
[Test] | ||
[TestCase("")] | ||
[TestCase(null)] | ||
public void IsOneOfTwoParametersNullOrEmptyValue(string changedPropertyName) | ||
{ | ||
PropertyChangedEventArgs args = new(changedPropertyName); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1)); | ||
} | ||
|
||
[Test] | ||
[TestCase("")] | ||
[TestCase(null)] | ||
public void IsOneOfThreeParametersNullOrEmptyValue(string changedPropertyName) | ||
{ | ||
PropertyChangedEventArgs args = new(changedPropertyName); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable2 = BindableProperty.Create("AlsoMyProperty1", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1, bindable2)); | ||
} | ||
|
||
[Test] | ||
[TestCase("")] | ||
[TestCase(null)] | ||
public void IsOneOfFourParametersNullOrEmptyValue(string changedPropertyName) | ||
{ | ||
PropertyChangedEventArgs args = new(changedPropertyName); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable2 = BindableProperty.Create("AlsoMyProperty1", typeof(object), typeof(object)); | ||
BindableProperty bindable3 = BindableProperty.Create("NotMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1, bindable2, bindable3)); | ||
} | ||
|
||
[Test] | ||
[TestCase("")] | ||
[TestCase(null)] | ||
public void IsOneOfFiveParametersNullOrEmptyValue(string changedPropertyName) | ||
{ | ||
PropertyChangedEventArgs args = new(changedPropertyName); | ||
BindableProperty bindable0 = BindableProperty.Create("MyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable1 = BindableProperty.Create("AlsoMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable2 = BindableProperty.Create("AlsoMyProperty1", typeof(object), typeof(object)); | ||
BindableProperty bindable3 = BindableProperty.Create("NotMyProperty", typeof(object), typeof(object)); | ||
BindableProperty bindable4 = BindableProperty.Create("AlsNotMyProperty", typeof(object), typeof(object)); | ||
|
||
Assert.IsTrue(args.IsOneOf(bindable0, bindable1, bindable2, bindable3, bindable4)); | ||
} | ||
} | ||
} |