コード例 #1
0
        public void PriceTest()
        {
            StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value

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

            double expected = 150.00F; // TODO: Initialize to an appropriate value
            double actual;

            actual = target.Price();
            Assert.AreEqual(expected, actual);
        }
コード例 #2
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);
        }
コード例 #3
0
        public void FindSKUTest_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(wheel)); //because, we don't just use the same instance
            target.Add(new StockKeepingUnit("Tyre", 50.00));
            target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance
            target.Add(new StockKeepingUnit("Tyrehorn", 11.50));
            target.Add(wheel);

            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.FindSKU(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));
        }
コード例 #4
0
        public void FindSKUTest_VerifyByName()
        {
            StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value

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

            target.Add(wheel);
            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(wheel)); //because, we don't just use the same instance
            target.Add(new StockKeepingUnit("Tyrehorn", 11.50));
            target.Add(wheel);


            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.FindSKU(skuname);

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

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

            target.Add(wheel);
            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(wheel)); //because, we don't just use the same instance
            target.Add(new StockKeepingUnit("Tyrehorn", 11.50));
            target.Add(wheel);

            string            skuname  = wheel.Name;                                                                                                               // TODO: Initialize to an appropriate value
            StockKeepingUnits expected = new StockKeepingUnits(new StockKeepingUnit[] { new StockKeepingUnit(wheel), wheel, wheel, new StockKeepingUnit(wheel) }); // TODO: Initialize to an appropriate value

            StockKeepingUnits actual;

            actual = target.FindSKUs(skuname);
            Assert.AreEqual(expected.Count, actual.Count);
        }
コード例 #6
0
 /// <summary>
 /// Adds a new SKU item
 /// </summary>
 public void AddSKU(StockKeepingUnit item)
 {
     fSKUs.Add(item);
 }