Exemple #1
0
        public void WidgetCacheIsUsed()
        {
            var mockData = GetStubData();

            var service = new WidgetService(mockData.Object);

            var widgets1 = service.GetAllWidgets();
            var widgets2 = service.GetAllWidgets();

            //check behavior: cache should be used in second call
            mockData.Verify(d => d.GetWidgets(), Times.Once);
            Assert.AreEqual(widgets1.Count(), widgets2.Count());
        }
Exemple #2
0
        public void BuyWidgetsAndDetermineTaxCalculation()
        {
            //arrange
            var mockData = GetStubData();
            var service  = new WidgetService(mockData.Object);

            var widgets = service.GetAllWidgets();

            var widgetsToBuy = widgets.Take(2).ToList();

            //act
            var receiptModel = service.PurchaseWidgets(widgetsToBuy, "cash", widgetsToBuy.Sum(w => w.Price));

            Assert.IsTrue(widgetsToBuy.Sum(w => w.Price) * 0.07m == receiptModel.Tax);
        }