Exemple #1
0
        public ActionResult Index(HomeViewModel model)
        {
            ExerciseClass exerciseClass = new ExerciseClass();
            DataStructure dataStructure = new DataStructure();

            if (model.itemsList == null)
            {
                model.itemsList           = new DataStructureObject();
                model.itemsList.inputList = new List <DataStructureItem>();
            }

            model.itemsList.inputList.Add(new DataStructureItem()
            {
                productPrice          = Convert.ToDouble(model.productPrice, CultureInfo.InvariantCulture),
                productName           = model.productName,
                productQuantity       = model.productQuantity,
                productEvaluatedPrice = 0,
                tax               = 0,
                isImported        = model.isImported,
                input             = 0,
                DataStructureType = model.DataStructureType
            });

            foreach (var m in model.itemsList.inputList)
            {
                var mReturn = exerciseClass.DoWorkSingleItem(m, dataStructure.GetExceptedList());
                m.productEvaluatedPrice = mReturn.productEvaluatedPrice;
                m.productglobalPrice    = mReturn.productEvaluatedPrice;
                m.tax = mReturn.tax;
            }
            model.totalTax    = model.itemsList.inputList.Sum(x => x.tax);
            model.totalAmount = model.itemsList.inputList.Sum(x => x.productEvaluatedPrice);

            return(View(model));;
        }
Exemple #2
0
        public void TestMethod()
        {
            ExerciseClass  exerciseClass = new ExerciseClass();
            DataStructure  dataStructure = new DataStructure();
            TestDataSource dataSource    = new TestDataSource();
            var            allData       = dataSource.LoadTestData();

            foreach (var ds in allData.GetItems())
            {
                var           items             = exerciseClass.DoWork(ds, dataStructure.GetExceptedList());
                List <Double> globalPriceList   = items.inputList.Select(x => x.productglobalPrice).ToList();
                List <Double> evaluatePriceList = items.inputList.Select(x => x.productEvaluatedPrice).ToList();
                CollectionAssert.AreEqual(globalPriceList, evaluatePriceList);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            ExerciseClass  exerciseClass = new ExerciseClass();
            DataStructure  dataStructure = new DataStructure();
            TestDataSource dataSource    = new TestDataSource();
            var            allData       = dataSource.LoadTestData();

            foreach (var ds in allData.GetItems())
            {
                var items = exerciseClass.DoWork(ds, dataStructure.GetExceptedList());
                foreach (var item in items.inputList)
                {
                    Console.WriteLine(item.input.ToString() + " , " + item.productName + " , " + item.productPrice + " , " + item.productglobalPrice + " , " + item.productEvaluatedPrice + " , " + item.tax);
                }
                Console.WriteLine("TOTAL: " + ds.totalAmount);
                Console.WriteLine("TAX: " + ds.taxTotalAmount);
            }

            Console.ReadLine();
        }