using System; using System.Collections.Generic; using System.Linq; using Calculator.Domain; using Calculator.Infrastructure; using Calculator.Test.Extensions; using MbUnit.Framework; using Rhino.Mocks; namespace Calculator.Test { [TestFixture] public class ComponentRegistryTest { [SetUp] public void Setup() { _mockery = new MockRepository( ); _repository = _mockery.DynamicMock< IAssemblyRepository >( ); } public IComponentRegistry CreateSUT() { return new ComponentRegistry( _repository ); } [Test] public void should_leverage_repository_to_retrieve_all_interfaces_in_current_assembly() { IEnumerable< Type > interfacesFoundInAssembly = new List< Type > {typeof( ICalculator )}; using ( _mockery.Record( ) ) { Expect.Call( _repository.AllInterfaces( ) ).Return( interfacesFoundInAssembly ); } using ( _mockery.Playback( ) ) { CreateSUT( ).AllComponents( ).Count( ); } } [Test] public void should_return_a_component_for_each_interface_returned_from_the_repository() { IEnumerable< Type > interfacesFoundInAssembly = new List< Type > {typeof( ICalculator )}; using ( _mockery.Record( ) ) { SetupResult.For( _repository.AllInterfaces( ) ).Return( interfacesFoundInAssembly ); } using ( _mockery.Playback( ) ) { CreateSUT( ) .AllComponents( ) .ShouldContainItemWhere( component => component.Interface( ).Equals( typeof( ICalculator ) ) ); } } private MockRepository _mockery; private IAssemblyRepository _repository; } }