summaryrefslogtreecommitdiff
path: root/Calculator/src/test/Calculator.Test/ComponentRegistryTest.cs
blob: bd95bea2e7291d65583a653099345c6add63a327 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
	}
}