Mock Property Set in VB.Net Module

2 posts, 0 answers
  1. Keith Knight
    Keith Knight avatar
    7 posts
    Member since:
    Feb 2010

    Posted 15 Sep 2010 Link to this post

    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.

  2. Ricky
    Ricky avatar
    467 posts

    Posted 17 Sep 2010 Link to this post

    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:

      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.

    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
Back to Top