I am new to unit testing and rhino mock. I want to create a stub for a
system.drawing.image in VB. Can anyone help me on that?
This is the function that needs to be unit tested:
Public Function getSystemDrawingImage(ByVal filePath As String) As
System.Drawing.Image Implements IMyImage.getSystemDrawingImage
If isFileExist(filePath) Or isImageFile(filePath) Then
Dim image As System.Drawing.Image =
System.Drawing.Image.FromFile(filePath)
Return image
Else
Return Nothing
End If
End Function
Here is the unit testing I want to write:
Public Sub
getSystemDrawingImageTest_Using_Mock_If_File_Path_Is_Valid_Return_Image()
Dim target As MyImage = New MyImage()
Dim filePath As String = "Fake_file_Path.jpg"
Dim expectedWidth As Integer = 1024
Dim expectedHeight As Integer = 768
Dim actual As Image
Dim mocks = New MockRepository
Dim stub = mocks.Stub(Of IMyImage)()
Dim img As System.Drawing.Image
Using mocks.Record
stub.isFileExist(filePath)
LastCall.Return(True)
stub.isImageFile()
LastCall.Return(True)
' how to set return image.Width and image.Height value as
expectedWidth and expectedHeight?
End Using
actual = target.getSystemDrawingImage(filePath)
Assert.AreEqual(expectedWidth, actual.Width)
Assert.AreEqual(expectedHeight, actual.Height)
End Sub
Thank you for your help
Best Regards
Li Aishen
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.