Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTO - Can't get reference to Word.ApplicationFactory from external assembly

The Issue

We’ve got a VSTO Word Add-in that we’re trying to do integration tests with.

We’ve organised into 3 projects as follows:

  • VSTO Project
  • Business Logic Project
  • Test Project

The issue is that in the test integration project we can create an instance of word using new Microsoft.Office.Interop.Word.Application() however we are unable to get an instance of Microsoft.Office.Tools.Word.ApplicationFactory (VSTO interface).

Does anyone know how I can get an instance of the VSTO ApplicationFactory in a test assembly?

For reference

The VSTO project makes calls to the business logic project passing

  • Microsoft.Office.Interop.Word.Application
  • Microsoft.Office.Tools.Word.ApplicationFactory

In the business logic project we can get the active Microsoft.Office.Interop.Word.Document and call the interop document method GetVstoObject method passing in the factory

public Microsoft.Office.Tools.Word.Document VstoDocument
{
    get { return _document.GetVstoObject(_factory); }
}
like image 575
Simon Avatar asked Mar 05 '13 15:03

Simon


1 Answers

It might be possible to mock the interface for test purposes (using moq or some other framework). I know when accessing the Excel interfaces needed to set up an RTD server, you have to create your own version of the interfaces, and mark them with the correct microsoft GUID. Perhaps the same approach will work with the application factory interface? I see that microsoft have published the GUID here

like image 135
Franchesca Avatar answered Oct 14 '22 18:10

Franchesca