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

Best use of fake method in Visual Basic

3 Answers 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michel Corbin
Top achievements
Rank 1
Michel Corbin asked on 23 Jul 2010, 03:08 AM
Hi,

I try to use the mocking framework with visual basic and I try to figure it out what is the best manner to fake a method.

When I try to fake a function, the syntaxe is very nice like this:

      <Test()> _
      Public Sub TestDelete()
         Dim fileManager As JustMockFile.IFileManager

         fileManager = Mock.Create(Of JustMockFile.IFileManager)()

         Mock.Arrange(Function() fileManager.Delete(Arg.AnyString)).Returns(False)

         Assert.IsTrue(fileManager.Delete(""))
      End Sub

As you can see, the keyword "Function()" is use and when I call the "Delete" function of the FileManager, I have a full support with intellisense to define possibles values of each arguments.

The problem is when I try to fake a method because I don't know how to call Arrange correctly except with the keyword "AddressOf". The problem with "AddressOf" is that I don't have a full support with intellisense and i'm limited with 9 parameters.

      <Test()> _
      Public Sub TestCreate()
         Dim fileManager As JustMockFile.IFileManager

         fileManager = Mock.Create(Of JustMockFile.IFileManager)()

         Mock.Arrange(AddressOf fileManager.Create, Arg.AnyString)

         Mock.Assert(AddressOf fileManager.Create, Arg.AnyString, Occurs.Once)
      End Sub

I have full of legacy applications where many methods have more then 9 parameters. Any ways, I don't have full support with Intellisense.

I want to be able to fake a method like this:

      <Test()> _
      Public Sub TestCreate()
         Dim fileManager As JustMockFile.IFileManager

         fileManager = Mock.Create(Of JustMockFile.IFileManager)()

         Mock.Arrange(function() fileManager.Create(Arg.AnyString))

         Mock.Assert(function() fileManager.Create(Arg.AnyString) Occurs.Once)
      End Sub

Is there any way to fake method like a function with Visual Basic... with the "Function()" keyword?

Thank you very much

3 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 23 Jul 2010, 12:39 PM

Hi Samuel,

Thanks a lot for posting such topic. The action overload with max 9 parameters is for VB 3.5 only where the support for lambda using sub is not available. In that case, we provide a separate visual basic assembly. But for VB 4 you don’t need it anymore and you can directly use Telerik.JustMock.dll as VB 4 subs fully support lambda. Just to note that you will only get these legacy options, if you are referencing Telerik.JustMock.VisualBasic.dll.
 
In short, for functions you can  use the Function() keyword but for subs (void methods) you need to call it with address of.

But we will ponder over it whether  to support legacy syntax like record-reply to tackle VB sub issue.

Hope that helps,
Mehfuz


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
0
Michel Corbin
Top achievements
Rank 1
answered on 23 Jul 2010, 01:34 PM
Thank you,

I think it time for me to upgrade to Visual Studio 2010 with Visual Basic or simply use C#. :)
0
Ricky
Telerik team
answered on 23 Jul 2010, 02:08 PM
Hello Samuel,

Yeah upgrading to visual studio 2010 and VB 4 is the best solution,  no more tricky workaround for VB 3.5 Sub issues :-). The best part is that you can use C# API as it is in visual basic.

Hope that helps,
Mehfuz


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
Michel Corbin
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Michel Corbin
Top achievements
Rank 1
Share this question
or