コード例 #1
0
        public void ShouldProvideCorrectCalculationResults()
        {
            // Arrange
            IOutputWriter writerMock = new TestOutputWriter();
            IInputReader  readerMock = new TestInputReader();
            var           cut        = new CustomLogicComponent(readerMock, writerMock);

            // Act
            cut.DivideExample();

            // Assert
            Assert.IsTrue(((TestOutputWriter)writerMock)
                          .DoesItReceive("The result is: 2"), "Calculation is incorrect." + ((TestOutputWriter)writerMock).ReceivedCalls());
        }
コード例 #2
0
        public void ShouldReadSecondArgument()
        {
            // Arrange
            IOutputWriter writerMock = new TestOutputWriter();
            IInputReader  readerMock = new TestInputReader();
            var           sut        = new CustomLogicComponent(readerMock, writerMock);

            // Act
            sut.DivideExample();

            // Assert
            Assert.IsTrue(((TestOutputWriter)writerMock)
                          .DoesItReceive("Enter another number to be divided"), "Second phrase is incorrrect");
            Assert.AreEqual(2,
                            ((TestInputReader)readerMock).GetReadLineCallsCount());
        }
        public void ShouldReadSecondArgument()
        {
            // Arrange
            IOutputWriter writerMock = Substitute.For <IOutputWriter>();
            IInputReader  readerMock = Substitute.For <IInputReader>();

            readerMock.ReadLine().Returns("10");

            var sut = new CustomLogicComponent(readerMock, writerMock);

            // Act
            sut.DivideExample();

            // Assert
            writerMock.Received(1).Write(Arg.Is <string>(w => w == "Enter another number to be divided"));
            readerMock.Received(2).ReadLine();
        }
        public void ShouldProvideCorrectCalculationResults()
        {
            // Arrange
            IOutputWriter writerMock = Substitute.For <IOutputWriter>();
            IInputReader  readerStub = Substitute.For <IInputReader>();

            Stack <int> readLineRetVals = new Stack <int>();

            readLineRetVals.Push(2);
            readLineRetVals.Push(10);

            readerStub.ReadLine().Returns((info) =>
            {
                return(readLineRetVals.Pop().ToString());
            });

            var cut = new CustomLogicComponent(readerStub, writerMock);

            // Act
            cut.DivideExample();

            // Assert
            writerMock.Received(1).Write(Arg.Is <string>(w => w == "The result is: 5"));
        }