Пример #1
0
        public void Should_correctly_CallBack_after_Consecutive_Buys()
        {
            //Given
            var fruits = new Stock(new List <Product> {
                new Product("apples", 10)
            });
            //When
            int     testQuantity = 0;
            Product testProduct  = null;

            void TestMethod(Product product, int quantity)
            {
                testProduct  = product;
                testQuantity = quantity;
            }

            fruits.AddCallback(TestMethod);
            fruits.Buy(1, "apples");
            fruits.Buy(1, "apples");
            fruits.Buy(4, "apples");
            //Then
            Assert.Equal(4, testQuantity);
        }
Пример #2
0
        public void Test_CallBack_Final_Check()
        {
            //Given
            var fruits = new Stock(new List <Product> {
                new Product("apples", 10)
            });
            //When
            int     testQuantity = 0;
            Product testProduct  = null;

            void TestMethod(Product product, int quantity)
            {
                testProduct  = product;
                testQuantity = quantity;
            }

            fruits.AddCallback(TestMethod);
            fruits.Buy(1, "apples");
            fruits.Buy(1, "apples");
            fruits.Buy(4, "apples");
            fruits.Buy(1, "apples");
            //Then
            Assert.Equal(4, testQuantity);
        }
Пример #3
0
        public void Should_CallBack_after_Removing_1_element_From_10_Products()
        {
            //Given
            var apples = new Product("apples", 10);
            var fruits = new Stock(new List <Product> {
                apples
            });
            //When
            int     testQuantity = 0;
            Product testProduct  = null;

            void TestMethod(Product product, int quantity)
            {
                testProduct  = product;
                testQuantity = quantity;
            }

            fruits.AddCallback(TestMethod);
            fruits.Buy(1, "apples");
            //Then
            Assert.NotNull(testProduct);
            Assert.Equal(apples.Name, testProduct.Name);
            Assert.Equal(9, testQuantity);
        }