This is a migrated thread and some comments may be shown as answers.

Arrange Conflicting with Assert

1 Answer 70 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kaya
Top achievements
Rank 1
Kaya asked on 26 Jul 2011, 05:12 PM

If you are unit testing a method that gets an Arranged mocked property and, then, sets that property, how do you verify the results at then end?

For example, let's say we want to unit test a method that looks like:

public void MyMethod()
{
    if (_view.SelectedObject != null)
        _view.SelectedObject = null;
}

I would expect to be able to write a test similar to:

[TestMethod]
public void MyMethodTest()
{
    var view = Mock.Create<iView>();
    var testObject = new Thingy();
  
    Mock.Arrange(() => view.SelectedObject).Returns(testObject);
    Mock.ArrangeSet(() => view.SelectedObject = null);
      
    objectUnderTest.MyMethod();
  
    Assert.IsNull(view.SelectedObject); 
}

The assert fails because the mocked property return is still in effect and you get testObject.  What's the proper way to write this test?  Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 27 Jul 2011, 09:31 AM
Hi Kaya,
An answer is posted in Ticket ID: 447581. Please check it out.


Kind Regards,
Mehfuz
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
General Discussions
Asked by
Kaya
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or