开发者

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)


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜