public void Get_Parent_List_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); ActionResult expected = null; ActionResult actual; actual = target.GetParentList(); JsonResult result = actual as JsonResult; Assert.AreEqual(result.Data.GetType(), typeof(SelectList)); var count = result.Data as SelectList; Assert.AreEqual(2, count.Count()); }
public void Commodity_Edit_Post_Valid_Model_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); Commodity commodity = new Commodity { CommodityID = 1, Name = "Wheat", LongName = "", CommodityTypeID = 1, ParentID = null }; //SetModelError(target); JsonResult expected = new JsonResult(); ActionResult actual; //Act actual = target.Edit(commodity); JsonResult result = actual as JsonResult; expected.Data = new { success = true }; Assert.AreEqual(expected.Data.ToString(), result.Data.ToString()); }
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()); }
public void Commodity_Edit_Get_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); int id = 1; ActionResult actual; actual = target.Edit(id); PartialViewResult result = actual as PartialViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.Model.GetType(), typeof(Commodity)); Assert.IsNotNull(result.ViewBag.CommodityTypeID); //major diff between parent and child //Assert.IsNull(result.ViewBag.ParentID); Assert.AreEqual(result.ViewBag.isParent, false); Assert.IsNull(result.ViewBag.CommodityType); Assert.IsNull(result.ViewBag.ParentCommodity); }
public void Commodity_Edit_Post_InValid_Model_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); Commodity commodity = new Commodity { CommodityID = 1, Name = "aja", LongName = "", CommodityTypeID = 1, ParentID = 1 }; //SetModelError(target); PartialViewResult expected = new PartialViewResult(); ActionResult actual; //Act actual = target.Edit(commodity); PartialViewResult result = actual as PartialViewResult; Assert.IsNotNull(result); }
public void CommodityControllerConstructorTest2() { CommodityController target = new CommodityController(); }
public void Commodity_Details_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); int id = 1; //details of wheat ViewResult expected = new ViewResult(); expected.ViewData.Model = new Commodity { CommodityID = 1, Name = "Wheat", LongName = "", CommodityTypeID = 1, ParentID = null }; ViewResult actual; actual = target.Details(id); ViewResult result = actual as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(actual.ViewData.Model.GetType(), typeof (Commodity)); Commodity CommodityX = result.ViewData.Model as Commodity; Commodity CommodityY = expected.ViewData.Model as Commodity; Assert.AreEqual(CommodityY.CommodityID, CommodityX.CommodityID); Assert.AreEqual(CommodityY.Name, CommodityX.Name); Assert.AreEqual(CommodityY.LongName, CommodityX.LongName); Assert.AreEqual(CommodityY.CommodityTypeID, CommodityX.CommodityTypeID); Assert.AreEqual(CommodityY.ParentID, CommodityX.ParentID); Assert.AreEqual("Details", result.ViewName); Assert.AreEqual(result.ViewData.ModelState.IsValid,true); }
public void Commodity_Create_Sub_Commodity_Get_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); int type = 0; Nullable<int> Parent = 1; //who is the parent commodity ActionResult expected = null; ActionResult actual; actual = target.Create(type, Parent); PartialViewResult result = actual as PartialViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.Model.GetType(), typeof(Commodity)); Assert.IsNotNull(result.ViewBag.CommodityTypeID); //major diff between parent and child Assert.IsNotNull(result.ViewBag.ParentID); Assert.AreEqual(result.ViewBag.isParent, true); Assert.IsNotNull(result.ViewBag.CommodityType); Assert.IsNotNull(result.ViewBag.ParentCommodity); }
public void Commodity_Delete_Confirmed_Faliure_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); Commodity commodity = new Commodity { Name = "Gebse", LongName = "", CommodityTypeID = 1, ParentID = null }; int id = 1; //delete the wheat commodity int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(5, commodityPreCount); JsonResult expected = new JsonResult(); ActionResult actual; //Act actual = target.DeleteConfirmed(id); ViewResult result = actual as ViewResult; //the number of commodities should decrease by 1 int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(commodityPreCount, commodityPostCount); Assert.AreEqual(result.ViewBag.ERROR,true); Assert.IsNotNull(result.ViewBag.ERROR_MSG); }
public void Commodity_Create_Post_For_InValid_Model_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); Commodity commodity = new Commodity { LongName = "", CommodityTypeID = 1, ParentID = 1 }; //SetModelError(target); int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(5, commodityPreCount); // Verify the expected Number pre-insert PartialViewResult expected = new PartialViewResult(); ActionResult actual; //Act actual = target.Create(commodity); PartialViewResult result = actual as PartialViewResult; Assert.IsNotNull(result); //no increase in the number of commodities int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(commodityPreCount, commodityPostCount); }
public void Commodity_Create_Post_For_Valid_Model_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); Commodity commodity = new Commodity { Name = "Gebse", LongName = "", CommodityTypeID = 1, ParentID = 1 }; int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(5, commodityPreCount); JsonResult expected = new JsonResult(); ActionResult actual; //Act actual = target.Create(commodity); JsonResult result = actual as JsonResult; expected.Data = new { success = true }; //the number of commodities should increase by 1 int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(commodityPreCount + 1, commodityPostCount); Assert.AreEqual(expected.Data.ToString() , result.Data.ToString()); }
public void Commodity_Controller_Index_Test() { //this three lines are good for testing null pointer exception validations //Mock<IUnitOfWork> mockCommodityRepository = new Mock<IUnitOfWork>(); //CommodityController target = new CommodityController(mockCommodityRepository.Object); // TODO: Initialize to an appropriate value // mockCommodityRepository.Object.GetAll();//SetupGet(d => d.GetAllParents()).SetupGet(d => d.GetAll()).Returns(mockCommodityRepository.Object.GetAll()); IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); ActionResult expected = new ViewResult(); //act call the index will call getall() from the repo and returns a list of comods ActionResult actual = target.Index(); ViewResult result = actual as ViewResult; 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 Commodity_Controller_Constructor_With_Two_Repos_Test() { IUnitOfWork commodityRepository = this.MockCommodityRepository; // TODO: Initialize to an appropriate value ICommodityTypeRepository commodityTypeRepository = null; // TODO: Initialize to an appropriate value CommodityController target = new CommodityController(commodityRepository); }
public void Commodity_Controller_Constructor_With_One_RepoTest() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); }
public void Sub_Commodity_List_Partial_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); ActionResult expected = new ViewResult(); //get all childrens of id (i.e. wheat for this case) int id = 1; ActionResult actual; actual = target.SubCommodityListPartial(id); PartialViewResult result = actual as PartialViewResult; Assert.IsNotNull(result); Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable<Commodity>)); Assert.AreEqual(result.ViewBag.SelectedCommodityID,id); Assert.AreEqual(result.ViewBag.ShowParentCommodity,true); }
public void Commodity_Delete_Confirmed_Success_Test() { IUnitOfWork repository = this.MockCommodityRepository; CommodityController target = new CommodityController(repository); //Commodity commodity = new Commodity //{ // Name = "Gebse", // LongName = "", // CommodityTypeID = 1, // ParentID = 1 //}; int id = 6; //delete the child yellow wheat commodity int commodityPreCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(5, commodityPreCount); JsonResult expected = new JsonResult(); ActionResult actual; const string testUrl = "/Commodity"; //Act actual = target.DeleteConfirmed(id); RedirectToRouteResult result = actual as RedirectToRouteResult; //the number of commodities should decrease by 1 int commodityPostCount = this.MockCommodityRepository.Commodity.GetAll().Count; Assert.AreEqual(commodityPreCount - 1, commodityPostCount); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); }
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 Init() { var commodities = new List<Commodity> { new Commodity {CommodityID = 1, Name = "Cereal", CommodityCode = "CER", CommodityTypeID = 1, ParentID = null}, new Commodity {CommodityID = 5, Name = "Wheat", CommodityCode = null, CommodityTypeID = 1, ParentID = 1}, }; var commodityService = new Mock<ICommodityService>(); commodityService.Setup(t => t.GetAllCommodity()).Returns(commodities); var commodityTypes = new List<CommodityType> { new CommodityType {CommodityTypeID = 1, Name = "Food"}, new CommodityType {CommodityTypeID = 2, Name = "Non Food"} }; var commodityTypeService = new Mock<ICommodityTypeService>(); commodityTypeService.Setup(t => t.GetAllCommodityType()).Returns(commodityTypes); _commodityController = new CommodityController(commodityTypeService.Object, commodityService.Object); }