Using events declared in Visual Basic 6.0 in a dotnet application

we are writing tests for a COM library written in VB 6.0. The problem we are facing is that we cannot access events declared in VB (withevents). We get an exception, "the object does not support many events." How can we solve this problem?

+3
source share
2 answers

Your mocking structure is the problem here. The layout object returned by this call:

repository.DynamicMock<PersonLib.DatabaseCommand>();

DatabaseCommand, . , VB6, DatabaseCommand, , .

PersonClass.Init, , :

  • PersonClass.Init:

    Set dbCommand = vDBCommand

  • VB6 Set, , DatabaseCommand (VB6 , dbCommand WithEvents , dbCommand).

  • , , , DatabaseCommand, , DatabaseCommand. VB6 , , .

, - , DatabaseCommand, (, , ), , .

+3

, VB 6.0 DatabaseCommand.

Option Explicit

Public Event SavedSuccessfully()

Public Sub Execute(ByVal vAge As Integer, ByVal vName As String, ByVal vAddress As String)

    RaiseEvent SavedSuccessfully

End Sub

, personclass

Private WithEvents dbCommand As DatabaseCommand

Public Sub Init(ByVal vDBCommand As DatabaseCommand)

    Set dbCommand = vDBCommand

End Sub

Private Sub dbCommand_SavedSuccessfully()
    'not implemented
End Sub

, ( vb)

MockRepository repository = new MockRepository();

PersonLib.DatabaseCommand db = repository.DynamicMock<PersonLib.DatabaseCommand>();

PersonLib.PersonClass person = new PersonLib.PersonClass();

person.Init(db);  --- this line throws error - Object or class does not support the set of events
+1

Source: https://habr.com/ru/post/1699445/


All Articles