You have to create a mock collection (you don't want to use the COM classes themselves, but the interfaces) ... so say for Rhino Mocks (I dont really like NMock, bit clunky, but the ideas are the same) you could implement a test fixture which creates the scenario of:
[*] Having the repository return a models collection.
[*] Invoking the AddNew method on the models collection.
[*] Having a new package returned.
[*] Verifying that the name for this package is the one we expected.
[/list]
Here's the code for this example test fixture:
[Test]
public void MockRepositoryModelsCollectionAndPackage()
{
MockRepository mockRepository = new MockRepository();
string expectedName = "My Package";
string expectedType = "Package";
EA.Package package = mockRepository.CreateMock<EA.Package>();
Expect.Call(package.Name).Return(expectedName);
EA.Collection collection = mockRepository.CreateMock<EA.Collection>();
Expect.Call(collection.AddNew(expectedName, expectedType)).Constraints(Is.Equal(expectedName),
Is.Equal(expectedType)).Return(
package);
EA.Repository repository = mockRepository.CreateMock<EA.Repository>();
Expect.Call(repository.Models).Return(collection);
mockRepository.ReplayAll();
EA.Package newPackage = repository.Models.AddNew(expectedName, expectedType) as EA.Package;
Assert.AreEqual(expectedName, newPackage.Name);
mockRepository.VerifyAll();
}
And anywhere that you need a really "smart" mock object (probably a bad smell in your test case if it's complex - but it does happen on occasion) then just implement your own class using the EA.XXXXX interface you need - of course then you have to implement the whole thing, which could be trouble then it's worth :)
Let me know if you need any more pointers on Mocking this stuff.
Cheers,
- Alex