1

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)
Matthew
  • 10,244
  • 5
  • 49
  • 104

1 Answers1

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

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

Joel C
  • 5,547
  • 1
  • 21
  • 31
  • Just realized that's C# syntax I used in the lambda, and VB.NET might be different (I haven't used VB.NET much). Is the VB.NET syntax `Sub()` instead of `()`? – Joel C Jun 06 '11 at 14:52
  • This isn't working for me. In VB.NET I can lambda returns using `Function()` rather than `()` but the property always returns null/nothing. – Matthew Jun 06 '11 at 16:12
  • @Matthew can you post your test that fails? The syntax looks correct. – Joel C Jun 06 '11 at 17:00
  • The problem was that my test project wasn't being rebuilt. Using the `Function()` expression I am able to make it work now. Thanks! – Matthew Jun 06 '11 at 18:29