chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
It would be usefull for us on learning curves to have some examples supplied with the download or as a separate download. I have been trying to get it to work with vb.net , altho I am a c# developer and the syntax has been driving me crazy. Some example code always makes life easier.
asked by owain.perry (1.1k points)

2 Answers

0 votes
It would be usefull for us on learning curves to have some examples supplied with the download or as a separate download. I have been trying to get it to work with vb.net , altho I am a c# developer and the syntax has been driving me crazy. Some example code always makes life easier.

Hi Owain,
It is true that we don't have VB.NET code example in the distribution, we will try to add example source code in c# and VB.NET.

Here is a small VB.NET example:

   <TestFixture()> _
    Public Class Test
        ' Initialize before each test
        <SetUp()> _
        Public Sub SetUp()
            MockManager.Init()
        End Sub

        ' Verfiy after each test
        <TearDown()> _
        Public Sub TearDown()
            MockManager.Verify()
        End Sub

        ' Test some expectations, 
        <Test()> _
         Public Sub ReturnValue()

            Dim t As TestedClass
 
            Dim mock As Mock
            ' Mock the type and set expectations
            mock = MockManager.Mock(GetType(TestedClass))
            mock.ExpectAndReturn("getVar", 5)
            mock.ExpectAndReturn("getVar", 6)
            mock.ExpectGet("Str", "Hi")

            ' Perform the code
            t = New TestedClass
            Assert.AreEqual("Hi", t.Str())
            Assert.AreEqual(5, t.getVar())
            Assert.AreEqual(6, t.getVar())
        End Sub


        ' Test the passed arguments expectations, 
       <Test()> _
        Public Sub TestParameters()
            Dim t As TestedClass
            Dim mock As Mock

            ' Mock the type and set expectations with argument checks
            mock = MockManager.Mock(GetType(TestedClass))
            mock.ExpectAndReturn("DoSomething", 1).Args("s", 9.3F, MockManager.Any, True)

            ' Perform the code
            t = New TestedClass
            Assert.AreEqual(1, t.DoSomething("s",  9.3F, "a", True))

        End Sub
answered by scott (32k points)
0 votes
Hi,
We have included C# and VB.NET examples in the distribution in version 2.1
answered by richard (3.9k points)
...