Пример #1
0
        public void LogicTest()
        {
            //arrange

            //instantiate new class to call our method to test
            ShipmentLogicLayer logic = new ShipmentLogicLayer();

            //method takes in list, need mock list
            List <IShipmentInfoBO> testList = new List <IShipmentInfoBO>();

            //mock list objects to fill mock list
            IShipmentInfoBO mock1 = new ShipmentBO();

            mock1.ProducerID   = 1;
            mock1.QuantityInBu = 100;

            IShipmentInfoBO mock2 = new ShipmentBO();

            mock2.ProducerID   = 2;
            mock2.QuantityInBu = 200;

            IShipmentInfoBO mock3 = new ShipmentBO();

            mock3.ProducerID   = 3;
            mock3.QuantityInBu = 300;

            IShipmentInfoBO mock4 = new ShipmentBO();

            mock4.ProducerID   = 4;
            mock4.QuantityInBu = 400;

            //add mock objects to mock list
            testList.Add(mock1);
            testList.Add(mock2);
            testList.Add(mock3);
            testList.Add(mock4);

            //act

            //set variable to get result of method we are testing
            var result = logic.GetTopProducer(testList);

            //assert

            //4 should be top producer from list, does this equal what the method tells us??  Yes :-)
            Assert.AreEqual(4, result);
        }
        public ActionResult ViewProducers()
        {
            //instantiate new viewmodel obj.
            ProducerVM newVM = new ProducerVM();

            //make sure user is authorized to add producer
            if (Session["UserName"] == null || (int)Session["UserLevel"] == 3)
            {
                RedirectToAction("Login", "User");
            }
            else
            {
                //instantiated new viewmodel, fill below
                try
                {
                    //call to DAL for method, reader fills list in method
                    List <IProducerInfoDO> ProducerData = _ProducerAccess.ViewAllProducers();
                    //call to method from mapping class
                    newVM.ProducerList = ProducerMap.MapDOtoPO(ProducerData);


                    //get a fresh list of shipments
                    List <IShipmentInfoDO> mylist = _ShipmentAccess.ViewAllShipments();
                    //Map each from DO to a BO
                    List <IShipmentInfoBO> viewTop = ShipmentMap.MapDOtoBO(mylist);
                    //call to the business logic, pass the information.
                    long topProducerID = _ShipmentLogic.GetTopProducer(viewTop);
                    //turn id into an object by calling down to the database, map in line.
                    newVM.Producer = ProducerMap.MapDOtoPO(_ProducerAccess.ViewProducerByID(topProducerID));
                    //now top producer is in PO form, can display using producerVM
                }
                catch (Exception)
                {
                    newVM.ErrorMessage = "There was an issue obtaining the list";
                }
                finally
                {
                    ///nothing else needs to happen
                }
            }


            return(View(newVM));
        }