I am trying to install fixtures using the InMemory Persistor for testing and am not having any success.
My setup is as follows:
- I have 2 factory/repository types: ClientFactory and UserFactory. These implement a singleton pattern.
- ClientFactory is responsible for creating new Clients.
- UserFactory is responsible for creating new Users.
- Both ClientFactory and UserFactory singleton instances are added to SystemServices in NakedObjects for IOC DI.
- User instances require a Client instance, so UserFactory has a reference to ClientFactory so it can get at Client instances. The reference is injected by the NakedObjects IOC Dependency Injection.
- Both ClientFactory and UserFactory derive from DomainObjectFactory.
- DomainObjectFactory derives from NakedObjects.Services.AbstractService.
- DomainObjectFactory has a virtual method called InstallDefaults() which allows each factory to be called to install any default data (fixtures) required.
- I also have a TestFixture type that derives from AbstractFixture.
- TestFixture is added to Fixtures.
- TestFixture has a reference to both ClientFactory and UserFactory. These references are injected by the IOC DI.
- TestFixture overrides the AbstractFixture.Install() method. In the overridden method it calls the ClientFactory.InstallDefaults() and the UserFactory.InstallDefaults() methods.
My problem is as follows:
I can happily create and persist instances of User and Client as part of the fixture install process, without any errors, but when I try and get the instances from the container again, it always returns zero items.
public void InstallDefaults()
// NakedObjectsContext.ObjectPersistor.StartTransaction(); // Seems to make no difference if I enable/disable transactions.
var client = this.Container.NewTransientInstance<Client>();
client.Name = "Test";
// At this point
// returns zero items!
NOTE: When my test methods get instances from their container they are present!
Please can you let me know what I am doing wrong?