Пример #1
0
        public void OneActionTest()
        {
            var Calc = new Calculator(0);
            var Action = new Mock<ICalculatorAction>();

            Action.SetupGet(t => t.Unary).Returns(false);
            Action.Setup(t => t.Calculate(It.IsAny<double>(), It.IsAny<double?>())).Returns(200);

            Calc.InputAction(Action.Object);
            Calc.InputNumber(50);

            Assert.AreEqual(200, Calc.CurrentValue);
            Action.Verify(a => a.Unary, Times.AtLeastOnce());
            Action.Verify(a => a.Calculate(It.Is<double>(d => d == 0), It.Is<double?>(d => d.HasValue && d.Value == 50)), Times.Once());
        }
Пример #2
0
        public void UnaryActionTest()
        {
            var Calc = new Calculator(0);
            var Action = new Mock<ICalculatorAction>();

            Action.SetupGet(t => t.Unary).Returns(true);
            Action.Setup(t => t.Calculate(It.IsAny<double>(), It.IsAny<double?>())).Returns(200);

            Calc.InputAction(Action.Object);

            Assert.AreEqual(200, Calc.CurrentValue);
            Assert.AreEqual(WaitedInput.Action, Calc.InputWaited);

            Action.Verify(a => a.Unary, Times.AtLeastOnce());
            Action.Verify(a => a.Calculate(It.Is<double>(d => d == 0), It.Is<double?>(d => !d.HasValue)), Times.Once());
        }