Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Example code.

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 Feb 1, 2005 by owain.perry (140 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 Feb 1, 2005 by scott (29,080 points)
0 votes
Hi,
We have included C# and VB.NET examples in the distribution in version 2.1
answered Feb 4, 2005 by richard (3,900 points)
...