jeudi 29 janvier 2015

Is it possible to write an interop assembly for MS Access

I'd like to unit test my MS Access application using MS Test in visual studio. This answer: Unit testing vba from .net - strongly typed COM objects along with this MS article: http://ift.tt/1twjqhH has enabled me to get to the point where I can test my own custom functions in an MS Access database:



Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Microsoft.Office.Interop

<TestClass()>
Public Class TestDb_Tests

Private oAccess As Access.ApplicationClass

<TestInitialize()>
Public Sub Setup()
oAccess = New Access.ApplicationClass
oAccess.Visible = False
oAccess.OpenCurrentDatabase("C:\Users\anon\Desktop\TestDb.accdb", False)
End Sub
<TestMethod()>
Public Sub CheckSEDOL_ValidSEDOL_ExpectTrue()
Assert.AreEqual(True, oAccess.Run("CheckSEDOL", "xxxxxxx"))
End Sub
<TestCleanup()>
Public Sub Cleanup()
oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
oAccess = Nothing
End Sub
End Class


However I cannot access my own class definitions, to instantiate and then test my own classes (I'd rather not instantiate them in the Access db). The first link above indicates that an interop assembly might help with this, but I cannot use tlbimp.exe to generate one from my MS Access database. I was wondering if this is actually possible and if so would I need to roll my own interop assembly? If so I'd very much appreciate pointers to any resources on how to do this.


Aucun commentaire:

Enregistrer un commentaire