Hi,
How can I Mock ConfigurationCollection with Rhino Mocks.
I need to create an Expected ConfigurationCollection which contains 1 element in order to test if me Configuration contains that element.
Thanks.
Note : My ConfigurationCollection inherits from IEnumerable.
public interface ICapalConfiguration
{
ICapalRepositoryConfigurationCollection Repositories { get; }
ICapalServiceConfigurationCollection Services { get; }
}
public interface ICapalRepositoryConfigurationCollection : IEnumerable
{
string DefaultConnectionString { get; set; }
ICapalRepositoryConfiguration GetElement(string name);
}
public interface ICapalRepositoryConfiguration
{
string Name { get; set; }
string ConnectionStringName { get; set; }
}
[TestMethod]
public void Can_Get_One_Repository()
{
var config = MockRepository.GenerateMock<ICapalConfiguration>();
var expected_repositories = MockRepository.GenerateMock<ICapalRepositoryConfigurationCollection>();
var expected_repository = MockRepository.GenerateMock<ICapalRepositoryConfiguration>();
config.Expect(p => p.Repositories).Return(expected_repositories).Repeat.Any();
config.Expect(p => p.Repositories.GetElement("ArticleRepository")).Return(expected_repository);
var config_repositories = config.Repositories;
var config_repository = config.Repositories.GetElement("ArticleRepository");
config.VerifyAllExpectations();
Assert.IsNotNull(config);
Assert.IsNotNull(config_repositories);
}