I have this Bank
class:
public class Bank : INotifyPropertyChanged
{
public Bank(Account account1, Account account2)
{
Account1 = account1;
Account2 = account2;
}
public Account Account1 { get; }
public Account Account2 { get; }
public int Total => Account1.Balance + Account2.Balance;
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
Bank
depends on other classes and has a property Total
that is calculated from properties of these other classes. Whenever any of these Account.Balance
properties is changed, PropertyChanged
is raised for Account.Balance
:
public class Account : INotifyPropertyChanged
{
private int _balance;
public int Balance
{
get { return _balance; }
set
{
_balance = value;
RaisePropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
I would like to raise PropertyChanged
for Total
, whenever any of the prerequisite properties is changed. How can I do this in a way that is easily testable?
TL;DR How do I raise PropertyChanged
for a dependent property, when a prerequisite property is changed in another class?