views:

613

answers:

3

Is it even possible?

So far, I found that we can buy TypeMock to mock the SharePoint objects and then use any free Mocking framework (Moq?) to do the rest of the job.

What do you think?

It seams that without TypeMock, it's impossible to do unit test within SharePoint.

To properly test our events, we need to give the event a SPItemEventProperties. The class is sealed and have an internal constructor that require a SPSite.

If I use the SPSite I can instantiate the class and give the proper values to test for my event. However, I want to remove that dependency and TypeMock seams to be the only one able to do that.

Any way around it?

+1  A: 

There's no really nice way of doing it. You might try splitting apart the parts of the SPItemEventProperties that you actually use into separate parameters, so your event handler takes the SPItemEventProperties, and just calls the actual event handler, passing it the item and web. At that point, just unit test the actual event handler (passing it appropriate mock objects for the particular parameters).

Yuliy
+3  A: 

I haven't used it yet, but I am anxious to try this product: TypeMock for SharePoint

Video introduction here on the multimedia page (#5)

Here's a nice little overview of the trickiness with unit testing SharePoint

jt

Jason
As a comment, I've tried TypeMock and it work wonderfully well. But I only use the Isolator for Sharepoint and use Moq for the actual mocking. Great product overall.
Maxim
A: 

Currenlty typemock Isolator is the only framework that can fake or mock SharePoint. That's because it can create mock objects that have private constructors or are sealed, like most SharePoint objects are.