Example #1
0
        public void UpdateTest()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = new ViewResult();
            Nullable <int>      param      = 1; // TODO: Initialize to an appropriate value
            ActionResult        actual;

            //act call the index will call getall() from the repo and returns a list of comods
            actual = target.Update(param);

            PartialViewResult result = actual as PartialViewResult;

            Assert.IsNotNull(result);

            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable <Commodity>));

            Assert.IsNull(result.ViewBag.Title);
            Assert.IsNotNull(result.ViewBag.ParentID);
            Assert.IsNotNull(result.ViewBag.SelectedCommodityID);
            Assert.IsNotNull(result.ViewBag.Parents);


            //just for testing that we are really using the test model objects
            var count = result.ViewData.Model as IEnumerable <Commodity>;

            Assert.AreEqual(count.Count(), 5);
        }
        public void CanDoUpdate()
        {
            //ACT
            var viewResult = _commodityController.Update(1) as ViewResult;

            Assert.IsNotNull(viewResult);
            var model = viewResult.Model;

            //ASSERT
            Assert.IsInstanceOf <SelectList>(viewResult.ViewBag.ParentID);
            Assert.IsInstanceOf <IEnumerable <Commodity> >(viewResult.ViewBag.Parents);
            Assert.IsInstanceOf <IEnumerable <Commodity> >(model);
        }