Ejemplo n.º 1
0
        public void CalculatorViewModel_DigitButtonPress_WhenLeftOperandIsEnteredAndOperationIsEnteredAndRightOperandIsEntered_ThenDigitButtonUpdatesRightOperandAndDisplay()
        {
            var leftOperand          = "12";
            var rightOperand         = "6";
            var operation            = "+";
            var button               = "8";
            var expectedRightOperand = "68";
            var expectedDisplay      = leftOperand + operation + expectedRightOperand;
            // Arrange
            var mockCalcModel = new Mock <ICalculatorModel>();

            mockCalcModel.SetupAllProperties();
            mockCalcModel.Object.LeftOperand  = leftOperand;
            mockCalcModel.Object.RightOperand = rightOperand;
            mockCalcModel.Object.Operation    = operation;
            var calculatorViewModel = new CalculatorViewModel(mockCalcModel.Object);

            // Act
            calculatorViewModel.DigitButtonPress(button);
            //Assert
            Assert.AreEqual(leftOperand, calculatorViewModel.LeftOperand);
            Assert.AreEqual(expectedDisplay, calculatorViewModel.Display);
            Assert.AreEqual(expectedRightOperand, calculatorViewModel.RightOperand);
            Assert.AreEqual(operation, calculatorViewModel.Operation);
        }
Ejemplo n.º 2
0
        public void CalculatorViewModel_DigitButtonPress_WhenOperationIsEnteredAndRightOperandIsEnteredAndBackspaceIsPressed_ThenRightOperandIsUpdated()
        {
            var leftOperand            = "23";
            var operation              = "*";
            var rightOperand           = "456";
            var leftOperandAfterPress  = "23";
            var rightOperandAfterPress = "45";
            var expectedDisplay        = "23*45";
            var button = "BACKSPACE";
            // Arrange
            var mockCalcModel = new Mock <ICalculatorModel>();

            mockCalcModel.SetupAllProperties();
            mockCalcModel.Object.LeftOperand  = leftOperand;
            mockCalcModel.Object.RightOperand = rightOperand;
            mockCalcModel.Object.Operation    = operation;
            var calculatorViewModel = new CalculatorViewModel(mockCalcModel.Object);

            // Act
            calculatorViewModel.DigitButtonPress(button);
            //Assert
            Assert.AreEqual(leftOperandAfterPress, calculatorViewModel.LeftOperand);
            Assert.AreEqual(expectedDisplay, calculatorViewModel.Display);
            Assert.AreEqual(rightOperandAfterPress, calculatorViewModel.RightOperand);
            Assert.AreEqual(operation, calculatorViewModel.Operation);
        }
Ejemplo n.º 3
0
        public void CalculatorViewModel_DigitButtonPress_WhenNothingIsEntered_ThenDigitButtonUpdatesLeftOperandAndDisplay()
        {
            var button = "2";
            // Arrange
            var mockCalcModel = new Mock <ICalculatorModel>();

            mockCalcModel.SetupAllProperties();
            mockCalcModel.Object.LeftOperand  = string.Empty;
            mockCalcModel.Object.RightOperand = string.Empty;
            mockCalcModel.Object.Operation    = string.Empty;
            var calculatorViewModel = new CalculatorViewModel(mockCalcModel.Object);

            // Act
            calculatorViewModel.DigitButtonPress(button);
            //Assert
            Assert.AreEqual(button, calculatorViewModel.LeftOperand);
            Assert.AreEqual(button, calculatorViewModel.Display);
            Assert.AreEqual(string.Empty, calculatorViewModel.RightOperand);
            Assert.AreEqual(string.Empty, calculatorViewModel.Operation);
        }
Ejemplo n.º 4
0
        public void CalculatorViewModel_DigitButtonPress_WhenClearIsPressed_ThenOperandsAndOperationAreResetAndZeroIsDisplay()
        {
            var leftOperand     = "13";
            var operation       = "+";
            var rightOperand    = "7";
            var expectedDisplay = "0";
            var button          = "CLEAR";
            // Arrange
            var mockCalcModel = new Mock <ICalculatorModel>();

            mockCalcModel.SetupAllProperties();
            mockCalcModel.Object.LeftOperand  = leftOperand;
            mockCalcModel.Object.RightOperand = rightOperand;
            mockCalcModel.Object.Operation    = operation;
            var calculatorViewModel = new CalculatorViewModel(mockCalcModel.Object);

            // Act
            calculatorViewModel.DigitButtonPress(button);
            //Assert
            Assert.AreEqual(string.Empty, calculatorViewModel.LeftOperand);
            Assert.AreEqual(expectedDisplay, calculatorViewModel.Display);
            Assert.AreEqual(string.Empty, calculatorViewModel.RightOperand);
            Assert.AreEqual(string.Empty, calculatorViewModel.Operation);
        }