summaryrefslogtreecommitdiff
path: root/Calculator/src/test/Calculator.Test/presentation/commands/SubtractionCommandTest.cs
blob: 40cd47b24c731480f51830edc4a1e37a1e4a9512 (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
54
55
56
57
58
59
60
61
62
63
64
using Calculator.Domain;
using Calculator.Presentation.Commands;
using MbUnit.Framework;
using Rhino.Mocks;

namespace Calculator.Test.presentation.commands {
	[TestFixture]
	public class SubtractionCommandTest {
		[SetUp]
		public void SetUp() {
			_mockery = new MockRepository( );
			_builder = _mockery.DynamicMock< INumberBuilder >( );
			_calculation = _mockery.DynamicMock< ICurrentCalculation >( );
		}

		public ISubtractionCommand CreateSUT() {
			return new SubtractionCommand( _builder, _calculation );
		}

		[Test]
		public void should_leverage_builder_to_retrieve_the_current_number() {
			using ( _mockery.Record( ) ) {
				Expect.Call( _builder.Build( ) ).Return( new Number( ) );
			}

			using ( _mockery.Playback( ) ) {
				CreateSUT( ).Execute( );
			}
		}

		[Test]
		public void should_include_number_from_builder_to_current_calculation() {
			var number = _mockery.DynamicMock< INumber >( );
			using ( _mockery.Record( ) ) {
				SetupResult.For( _builder.Build( ) ).Return( number );
				_calculation.Enter( number );
			}

			using ( _mockery.Playback( ) ) {
				CreateSUT( ).Execute( );
			}
		}

		[Test]
		public void should_include_subtraction_operation_to_current_calculation() {
			using ( _mockery.Record( ) ) {
				using ( _mockery.Ordered( ) ) {
					_calculation.Enter( null );
					LastCall.IgnoreArguments( );

					_calculation.Include( Operators.Subtraction );
				}
			}

			using ( _mockery.Playback( ) ) {
				CreateSUT( ).Execute( );
			}
		}

		private INumberBuilder _builder;
		private ICurrentCalculation _calculation;
		private MockRepository _mockery;
	}
}