Tortuga-TestMonkey
Tortuga-TestMonkey copied to clipboard
INotifyPropertyChanged Tests
@{
foreach (var property in Class.Properties.Where(p => !p.IsIndexer && p.CanRead && p.CanWrite && p.Type.HasCommonValues))
{
<text>
@Tag("INotifyPropertyChanged")
@TestAttribute
public void @(Test.ClassName + "_Property_" + property.Name + "_NotifyPropertyChanged_SelfAssign") ()
{
var objectUnderTest = CreateObject();
var events = new List<PropertyChangedEventArgs>();
((INotifyPropertyChanged)objectUnderTest).PropertyChanged += (s, e) => events.Add(e);
//Setting the value to the current value should always work and not raise any events
var originalValue = [email protected];
[email protected] = originalValue;
@Assert.IsTrue("events.Count() == 0", "\"No change events should have been raised, the property's value didn't change.\"")
}
</text>
<text>
@Tag("INotifyPropertyChanged")
@TestAttribute
public void @(Test.ClassName + "_Property_" + property.Name + "_NotifyPropertyChanged") ()
{
var objectUnderTest = CreateObject();
var events = new List<PropertyChangedEventArgs>();
((INotifyPropertyChanged)objectUnderTest).PropertyChanged += (s, e) => events.Add(e);
//perform a self-assignment to avoid duplicating the above test
var originalValue = [email protected];
[email protected] = originalValue;
</text>
foreach (var testValue in property.Type.CommonValues)
{
<text>
events.Clear();
try
{
@property.Type.FullName expectedValue = @testValue;
var valueChanged = !Object.Equals(expectedValue, [email protected]);
[email protected] = expectedValue;
if (valueChanged)
@Assert.IsTrue("events.Any(e => e.PropertyName == \"" + property.Name + "\")", "\"No property changed event was raised for \\\"" + property.Name + "\\\".\"")
else
@Assert.IsTrue("events.Count() == 0", "\"No change events should have been raised, the property's value didn't change.\"")
}
catch (ArgumentException)
{
//OK
return;
}
</text>
}
<text>
}
</text>
}
}