tags:

views:

18

answers:

0

I have a Microsoft Project Client AddIn. In it I have a POCO Calculation class that contains a method called CalculatePrice() of which function is to iterate through the current active project and calculate a price figure for each of the task assignments.

Now, this CalculatePrice() method is not only complex, but is also a critical function in the application that we are building.

We want to unit test this method but found it hard to do so. The CalculatePrice() gets the MSProject object from "Globals.ThisAddn.Application.ActiveProject". From this object, we then can get the rest of the information regarding this project like its Resource, Tasks, Assignments, etc. And I need these information to do the calculation.

I just want to test out the algorithm for calculation, but all these dependencies on the MS Project API classes makes it very difficult to unit test the algor in isolation.

I thought of creating a simple POCO Project class to wrap around the MSProject class and pass it as a parameter to my CalculatePrice() method, in my unit test, I simply instantiate the POCO class and "hand-code" the values into it, then I can unit test the CalculatePrice()'s algor.

But MSProject is a big class, it seems tedious to re-create another class just for the purpose of unit testing.

Can Mocks help me or what other strategy should I use to do the unit test?

Thanks.