#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2014 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
#if UNITTEST
using System;
using System.ComponentModel;
using NUnit.Framework;
namespace Nuclex.Support {
/// Unit tests for the property change event argument helper
[TestFixture]
internal class PropertyChangedEventArgsHelperTest {
#region class TestViewModel
/// Example class on which unit test generates change notifications
public class TestViewModel {
/// Example property that will be reported to have changed
public int SomeProperty { get; set; }
}
#endregion // class TestViewModel
///
/// Verifies that a property change notification matching the property
/// passed to the AreAffecting() method is recognized
///
[Test]
public void MatchingPropertyChangeNotificationIsRecognized() {
var arguments = new PropertyChangedEventArgs("SomeProperty");
Assert.IsTrue(arguments.AreAffecting(() => ViewModel.SomeProperty));
Assert.IsTrue(arguments.AreAffecting("SomeProperty"));
}
///
/// Ensures that a mismatching property change notification will
/// not report the property as being affected.
///
[Test]
public void MismatchingPropertyIsReportedAsUnaffected() {
var arguments = new PropertyChangedEventArgs("AnotherProperty");
Assert.IsFalse(arguments.AreAffecting(() => ViewModel.SomeProperty));
Assert.IsFalse(arguments.AreAffecting("SomeProperty"));
}
///
/// Verifies that any specific property is reported as being affected
/// when the property change notification is a null wildcard
///
[Test]
public void SpecificPropertyIsAffectedByNullWildcard() {
var nullArguments = new PropertyChangedEventArgs(null);
Assert.IsTrue(nullArguments.AreAffecting(() => ViewModel.SomeProperty));
Assert.IsTrue(nullArguments.AreAffecting("SomeProperty"));
}
///
/// Verifies that any specific property is reported as being affected
/// when the property change notification is an empty wildcard
///
[Test]
public void SpecificPropertyIsAffectedByEmptyWildcard() {
var emptyArguments = new PropertyChangedEventArgs(string.Empty);
Assert.IsTrue(emptyArguments.AreAffecting(() => ViewModel.SomeProperty));
Assert.IsTrue(emptyArguments.AreAffecting("SomeProperty"));
}
///
/// Tests whether the helper can recognize a wildcard property change
/// notification using null as the wildcard.
///
[Test]
public void NullWildcardIsRecognized() {
var nullArguments = new PropertyChangedEventArgs(null);
Assert.IsTrue(nullArguments.AffectAllProperties());
}
///
/// Tests whether the helper can recognize a wildcard property change
/// notification using an empty string as the wildcard.
///
[Test]
public void EmptyWildcardIsRecognized() {
var emptyArguments = new PropertyChangedEventArgs(string.Empty);
Assert.IsTrue(emptyArguments.AffectAllProperties());
}
/// Helper used to construct lambda expressions
protected static TestViewModel ViewModel { get; set; }
}
} // namespace Nuclex.Support
#endif // UNITTEST