コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public Receipt CalculateReceipt(string[] items)
        {
            Receipt result = new Receipt(); //zero the result

            StockKeepingUnits itemSKUs = new StockKeepingUnits();

            foreach (var s in items)
            {
                StockKeepingUnit tempRef = fSKUs.FindSingletonSKU(s);
                if (tempRef != null)
                {
                    itemSKUs.Add(new StockKeepingUnit(tempRef));
                }
                else
                {
                    result.AddRemark(String.Format("\"{0}\" was not recognised and skipped", s));
                }
            }

            result.AddRemark(itemSKUs.ToString());

            //now that we know what we are buting, we should apply the discounts
            result.Subtotal = itemSKUs.Price();

            DiscountResults discountResults = fDiscounts.ApplyDiscounts(itemSKUs);

            result.Total = result.Subtotal - discountResults.Sum();
            result.AddDiscount(discountResults.ToString());

            return(result);
        }
コード例 #2
0
        public void FindSingletonSKU_VerifyByName()
        {
            StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value

            StockKeepingUnit wheel = new StockKeepingUnit("Wheel", 88.50);

            target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance
            target.Add(new StockKeepingUnit("Tyre", 50.00));
            target.Add(new StockKeepingUnit("Tyrehorn", 11.50));


            string skuname = wheel.Name; // TODO: Initialize to an appropriate value

            //as we are not always returning the SAME instance, testing that would be pointless.
            StockKeepingUnit expected = new StockKeepingUnit(wheel); // TODO: Initialize to an appropriate value

            StockKeepingUnit actual;

            actual = target.FindSingletonSKU(skuname);

            Assert.AreEqual <string>(expected.Name, actual.Name);
        }
コード例 #3
0
        public void FindSingletonSKUTest_VerifyByPrice()
        {
            StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value

            StockKeepingUnit wheel = new StockKeepingUnit("Wheel", 88.50);

            target.Add(wheel);
            target.Add(new StockKeepingUnit("Tyre", 50.00));
            target.Add(new StockKeepingUnit("Tyrehorn", 11.50));

            string skuname = wheel.Name; // TODO: Initialize to an appropriate value

            //as we are not always returning the SAME instance, testing that would be pointless.
            StockKeepingUnit expected = new StockKeepingUnit(wheel); // TODO: Initialize to an appropriate value

            //we have enfourced a limit that the FindSKU will return null when there is 0 or > 1 SKU
            //in the list.
            StockKeepingUnit actual;

            actual = target.FindSingletonSKU(skuname);

            Assert.IsNotNull(actual, "There was no 'actual' item instance found");
            Assert.AreEqual <double>(expected.Price, actual.Price, string.Format("L: {0} - R: {1}", expected.Price, actual.Price));
        }