chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Test
[Isolated]
[TestMethod]
public void OnTearingDownUnSignedToPropertyChange()
{
    AddressCreationViewController controller = new AddressCreationViewController();
    AddressCreationViewControlsState controlsState = Isolate.Fake.Instance<AddressCreationViewControlsState>();

    //Inject dependencies
    controller.ControlsState = controlsState;

    //Action!!!
    controller.OnTearingDown();

    //Asserts
    Isolate.Verify.WasCalledWithAnyArguments(() => controlsState.PropertyChanged -= null);
}

Failes with ".remove_PropertyChanged(PropertyChangedEventHandler) was expected but was not called."
Code under test is
public void OnTearingDown()
{
    this.ControlsState.PropertyChanged -= new PropertyChangedEventHandler(ControlsState_PropertyChanged);
}

This test was created for Typemock 5.3.5 and executed fine , but broke after upgrading to 6.0.2.
Thank you
asked by dimonytch (1.2k points)

2 Answers

0 votes
Hi,

This seems like a bug :(. Can you post the code of AddressCreationViewControlsState?

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
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.
answered by dimonytch (1.2k points)
...