I created a sample project to illustrate the bug.
Controller:
public class Controller
{
public AddressCreationViewControlsState State { get; set; }
public void Unsubsribe()
{
this.State.PropertyChanged -= new PropertyChangedEventHandler(State_PropertyChanged);
}
void State_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
throw new NotImplementedException();
}
}
State:
public class AddressCreationViewControlsState : ViewControlsStateBase
{
}
State base class:
public abstract class ViewControlsStateBase : INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
Test code:
[TestMethod]
[Isolated]
public void CanUnsubsribe()
{
Controller controller = new Controller();
AddressCreationViewControlsState state = Isolate.Fake.Instance<AddressCreationViewControlsState>();
controller.State = state;
controller.Unsubsribe();
Isolate.Verify.WasCalledWithAnyArguments(() => state.PropertyChanged -= null);
}
I suppose the problem is with inheritance here.