locked
VSTS Unit Test: How to verify that method under test called Refresh() on ObjectDataProvider member? RRS feed

  • Question

  • I'm writing a unit test for a method, and one of the effects of calling the method is that it calls Refresh() on an ObjectDataProvider member of the class (accessible through a property).
    Is there a simple (or at least, not horribly complex) way to verify that the Refresh() was actually called?
    • Moved by Jay_WangMicrosoft employee Friday, October 23, 2009 1:57 AM Unit testing question. (From:Windows Presentation Foundation (WPF))
    Thursday, October 22, 2009 10:02 PM

Answers

  • lets call the unit under test is your controller.
    if you want to verify that your controller logic actually calls an object's refresh button you need to mock that.

    http://code.google.com/p/moq/wiki/QuickStart



    // i haven't tested this
    
    var mock = new Mock<IViewWithRefreshMethod>();
    var calls = 0;
    mock.Setup(foo => foo.Refresh())
        .Callback(() => calls++);
    
    var c = new Controller(mock);
    c.Invalidate(); // calls refresh internally.
    
    Assert.IsTrue(calls == 1);


    leblanc
    Thursday, October 22, 2009 11:11 PM