コード例 #1
0
        public void Commodity_List_Partial_Test()
        {
            IUnitOfWork         repository = this.MockCommodityRepository;
            CommodityController target     = new CommodityController(repository);
            ActionResult        expected   = new ViewResult();
            ActionResult        actual     = null;

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

            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.AreEqual("_CommodityPartial", result.ViewName);

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

            Assert.AreEqual(2, count.Count());
        }
コード例 #2
0
        public void CanViewCommodityListPartial()
        {
            //ACT
            var result = _commodityController.CommodityListPartial() as ViewResult;

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

            //Assert
            Assert.AreEqual(false, result.ViewBag.ShowParentCommodity);
            Assert.IsInstanceOf <SelectList>(result.ViewBag.ParentID);
            Assert.IsInstanceOf <Int32>(result.ViewBag.SelectedCommodityID);
            Assert.IsInstanceOf <IEnumerable <Commodity> >(model);
            Assert.AreEqual(2, ((IOrderedEnumerable <Commodity>)model).Count());
        }