Search code examples
vb.netinterfacemockingtelerikjustmock

How to mock an interface property with JustMock in VB.NET


I am using JustMock to mock interfaces for unit testing, but perhaps I'm not doing it right.

I have an interface:

Public Interface IFoo
    Property Bar as int
End Interface

I want to mock this interface and set that property so that it can be read by consumers of the interface.
Beginning with:

Dim mockFoo as IFoo = Mock.Create(Of IFoo)()

The I've tried to set the property like this:

mockFoo.Bar = 1

And also like this:

Mock.Arrange(Sub() mockFoo.Bar = 1).DoNothing()

and also like this:

Mock.Arrange(Function() mockFoo.Bar).Returns(1)

I followed the question and answer from this post on the Telerik forum (not my question):
http://www.telerik.com/community/forums/justmock/general-discussions/mock-property-set-in-vb-net-module.aspx

But the example posted by Telerik doesn't solve my issue. It also looks like a concretion, not an interface. Am I approaching this completely the wrong way?

EDIT, UPDATE:
The issue was my project not building. I am able to get interface properties using the following syntax:

Mock.Arrange(Function() mockFoo.Bar).Returns(1)

Solution

  • Mock.Arrange( () => mockFoo.Bar ).Returns(1);
    

    See Telerik's documentation: http://www.telerik.com/help/justmock/basic-usage-mock-returns.html