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

Mock Property Set in VB.Net Module

1 Answer 205 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Keith Knight
Top achievements
Rank 1
Keith Knight asked on 15 Sep 2010, 06:44 PM
Does anyone any ideas on how to mock a static property in a Vb.Net module?

I have attempted various solutions, all of which lead to JustMock throwing exceptions.

I am looking for something like:
Mock.ArrangeSet(Sub() VbModule.MyProperty = Arg.AnyString).DoNothing()





Any help would be appreciated.






1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 17 Sep 2010, 09:20 AM
Hi Keith,

Thank you for bringing up the issue. ArrangeSet is meant to be used for setting up property assignments in C#  because Expression<TDelegate> does not support assignment inside lambda. If you notice closely, you will find that it is a simple action (only executes); thus should be used after Mock.Create / Mock.SetupStatic. But Visual Basic does not restrict this kind of operation. Therefore, you can directly do:

Mock.Arrange(Sub() VbModule.MyProperty = Arg.AnyString).DoNothing()

Since MyProperty is declared in a global scope, you can't set it up with SetupStatic. The only option is to partially mock it.

I wrote the test in the following the way and it is working fine:

<Test()>
  Public Sub ShouldAssertProperyFromModule()
      Mock.Arrange(Sub() VBModule.MyProperty = Arg.AnyString).Throws(New ArgumentException())
      Assert.Throws(Of ArgumentException)(Sub() VBModule.MyProperty = "test")
      Mock.Assert(Sub() VBModule.MyProperty = "test")
  End Sub

The test project is also attached to let you have a look. Please write back, if you are having  further issues.

Regards,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Keith Knight
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or