示例#1
0
        static void Main(string[] args)
        {
            DatabaseReader databaseReader = new DatabaseReader();
            StockChecker   stockChecker   = new StockChecker(databaseReader);

            int stock = stockChecker.NumberInStock("ABC123");

            Console.WriteLine("Number in stock: " + stock);
            Console.ReadLine();
        }
示例#2
0
        public void TestNumberInStock_CallsTheReadQuantityMethodOfOurDatabaseReader_WhenCalled()
        {
            //Arrange
            Mock <IDatabaseReader> mockDatabaseReader = new Mock <IDatabaseReader>();
            string       isbn         = "ABC123";                                    //string isbn for act
            StockChecker stockChecker = new StockChecker(mockDatabaseReader.Object); //Object

            //Act
            stockChecker.NumberInStock(isbn); //Method

            //Assert
            //Not interested in what this test returns, just that it behaves in the way we want. Want to verify the database reader had its read method quanitity called
            mockDatabaseReader.Verify(r => r.ReadQuantity(It.IsAny <string>()), Times.Once);
        }
示例#3
0
        public void Test_NumberInStock_returns3WhenThereAre3MatchingBooksInTheDatabase()
        {
            //Arrange
            string isbn     = "ABC123";
            int    expected = 3;
            Mock <IDatabaseReader> mockDatabaseReader = new Mock <IDatabaseReader>();

            mockDatabaseReader.Setup(r => r.ReadQuantity(isbn)).Returns(3); //this is called stubbing

            StockChecker stockChecker = new StockChecker(mockDatabaseReader.Object);

            //Act
            int actual = stockChecker.NumberInStock(isbn);

            //Assert
            Assert.AreEqual(expected, actual);
        }