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
I am trying to create a Unit Test


<TestMethod> Public Sub TestGetDefaultTypeTransport()

Dim Expected As Integer = 1

With TheseCalls.WillReturn(3)
Dim dummy = Utilities.TypeTransportDefault
End With


Dim Actual As Integer = t.GetTypeDefault

Assert.AreEqual(Expected, Actual)

End Sub




Utilities.TypeTransportDefault is a property that calls my DataAccessLayer. I know this works well so i want to mock it.

when t.GetTypeDefault is invoked, it calls the Utilities.TypeTransportDefault.. in which case I want the value returned to be 3.

but it returns 0.. What is wrong with my code ?

thanks
asked by RedSoxFred (1.8k points)

4 Answers

0 votes
Found the Problem.. i was using WITH instead of USING

doh!!!
answered by RedSoxFred (1.8k points)
0 votes
Hi,

Glad you found the solution :)
Please let us know if you'll need more help!
answered by ohad (35.5k points)
0 votes
The following code works beautifully... Is this proper practice

Dim Expected = False

Dim TestCommande As New Commandes

Dim FakeUC As ucCommande = FakeInstance(Of ucCommande)(Members.CallOriginal)


Using TheseCalls.WillReturn(TestCommande)
Console.WriteLine(FakeUC.BindingSource.Current)
End Using

Dim Actual = FakeUC.GarderInfoFacture


Assert.AreEqual(Expected, Actual)



The one thing i didn't know how to do what to put the property call in the Using EndUsing Area.. so I used console.writeline as a way to call it.. Is there a better way to do so ?
answered by RedSoxFred (1.8k points)
0 votes
Hi,

The solution is simply use a dummy variable to get the value.
Example:
Dim Expected = False 

Dim TestCommande As New Commandes 

Dim FakeUC As ucCommande = FakeInstance(Of ucCommande)(Members.CallOriginal) 


Using TheseCalls.WillReturn(TestCommande) 
 Dim dummy As  BindingSource = FakeUC.BindingSource.Current 
End Using 

Dim Actual = FakeUC.GarderInfoFacture 
Assert.AreEqual(Expected, Actual) 


Note I'm just guessing the type of FakeUC.BindingSource.Current here :)
You should put the correct type in case I'm wrong.

Hope it helps.
answered by ohad (35.5k points)
...