I've been trying out some test mockings with TypeMock and they seem to work well except for one test case that I encountered.
I have a class under test
Public Class ClassUnderTest
public function PostPurchaseOrder() As SalesOrderPostingOutput
Dim userid as string
Dim logon As New Encore.Utilities
userid = logon.Logon("username", "password", "T", "", encore.Language.ENGLISH, 0, 0, "")
return nothing ' just for testing
end Function
end Class
<NUnit.Framework.Test()> _
Public Sub TestPostPurchaseOrder()
MockManager.Init()
Dim EncoreUtilities As Mock = MockManager.Mock(GetType(Encore.Utilities))
EncoreUtilities.AlwaysReturn("Logon", "Test Data")
Dim syspro As New ClassUnderTest
syspro.PostPurchaseOrder()
MockManager.Verify()
end Sub
When I run the above test, error message "Cannot type mock Interfaces or Abstract classes use MockObject" appears. So I change the Mock to MockObject. The problem is now is that the logon.Logon is never mocked. Instead, the original logon.Logon is called. Could it be that Encore.Utilities is not native dotnet but a ComInterop? Or am i missing something?
The object browser shows Encore.Utilites is defined as follows
-- Interop.Encore
{} Encore
Instance (an enum)
IQuery (interface)
ISetup (interface)
ITransaction (interface)
IUtilities (interface)
Language (enum)
LogDetail (enum)
Query (class)
Setup (class)
Transaction (class)
Utilities (class)
Thanks for any help.