Hi
The problem is that MockManager.Mock will mock the next instance of the type.
See the explanation
here
All you have to do is move the the line
ConfigurationTypeRepository target = new ConfigurationTypeRepository(databaseName, type);
after the the line that mocks ConfigurationTypeRepository
So your test should looks like this:
public void FindConfigurationTypesTest()
{
string databaseName = "Test";
MockObject dbMock = MockManager.MockObject(typeof(SqlDatabase), Constructor.NotMocked, databaseName);
Database db = (Database)dbMock.Object;
Mock factoryMockCreateDatabase = MockManager.Mock(typeof(DatabaseFactory));
factoryMockCreateDatabase.ExpectAndReturn("CreateDatabase", db, 1);
RepositoryType type = RepositoryType.DBInstance;
//wrong unless you use MockManager.MockAll()
//ConfigurationTypeRepository target = new ConfigurationTypeRepository(databaseName, type);
int ownerId = 0;
List<ConfigurationType> mockList = BuildConfigurationTypeList();
List<ConfigurationType> expected = mockList;
List<ConfigurationType> actual;
MockObject mockSelectionFactory = MockManager.MockObject(typeof(ConfigurationTypeSelectionFactory));
ConfigurationTypeSelectionFactory csf = (ConfigurationTypeSelectionFactory)mockSelectionFactory.Object;
MockObject mockComponentFactory = MockManager.MockObject(typeof(ConfigurationTypeFactory));
ConfigurationTypeFactory cf = (ConfigurationTypeFactory)mockComponentFactory.Object;
Mock mock = MockManager.Mock(typeof(ConfigurationTypeRepository), true);
mock.CallBase.ExpectAndReturn("FindAll", mockList).Args(csf, cf);
//This should work
ConfigurationTypeRepository target = new ConfigurationTypeRepository(databaseName, type);
actual = target.FindConfigurationTypes();
Assert.IsNotNull(actual, "Null was returned");
Assert.AreEqual(expected, actual, "TriadFinancial.ApplicationAdmin.Resource.DataAccess.Repositories.Core.Configurati" +
"onTypeRepository.FindConfigurationTypes did not return the expected value.");
}
Another option is to use MockManager.MockAll method. This will mock all instances of mocked type.
Hope it helps.