Ejemplo n.º 1
0
 private void PushCommandsToActiveObject(IReadOnlyList <int> numbers, IReadOnlyList <Type> types,
                                         CalculatorActiveObject activeObject)
 {
     for (var i = 0; i < numbers.Count; i++)
     {
         var type    = types[i];
         var command = (ICommand)Activator.CreateInstance(type, numbers[i]);
         activeObject.Push(command);
     }
 }
Ejemplo n.º 2
0
        public void MixingAddAndSubtractCommandsResultingInDesignatedExpectedValue(int[] numbers, Type[] types, int expected)
        {
            // Arrange
            var calculatorActiveObject = new CalculatorActiveObject();

            PushCommandsToActiveObject(numbers, types, calculatorActiveObject);

            // Act
            var result = calculatorActiveObject.Calculate();

            // Assert
            That(result, Is.EqualTo(expected));
        }
Ejemplo n.º 3
0
        public void MixingAddAndSubtractCommandsAndUndoingOperationAfterFirstCommandResultingInDesignatedExpectedValue(
            int[] numbers, Type[] types, int expected)
        {
            // Arrange
            var calculatorActiveObject = new CalculatorActiveObject();

            PushCommandsToActiveObject(numbers.Take(1).ToArray(), types.Take(1).ToArray(), calculatorActiveObject);
            PopCommandFromActiveObject(calculatorActiveObject);
            PushCommandsToActiveObject(numbers.Skip(1).ToArray(), types.Skip(1).ToArray(), calculatorActiveObject);

            // Act
            var result = calculatorActiveObject.Calculate();

            // Assert
            That(result, Is.EqualTo(expected));
        }
Ejemplo n.º 4
0
 private void PopCommandFromActiveObject(CalculatorActiveObject calculatorActiveObject)
 {
     calculatorActiveObject.Pop();
 }