Inheritance: BaseController
 public void AdminUnitControllerConstructorTest()
 {
     try
     {
         AdminUnitController target = new AdminUnitController();
     }
     catch(Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
 public void AdminUnits_AdminUnits_WithAdminUnitType_Test()
 {
     mockRepository.Setup(m => m.AdminUnit.GetRegions()).Returns(new List<BLL.AdminUnit>());
     mockRepository.Setup(m => m.AdminUnit.GetAdminUnitType(1)).Returns(new BLL.AdminUnitType());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     Nullable<int> id = new Nullable<int>(); // TODO: Initialize to an appropriate value
     id = 1;
     var viewName = "Lists/AdminUnits." + id + "";
     PartialViewResult actual;
     actual = (PartialViewResult)target.AdminUnits(id);
     Assert.AreEqual(viewName, actual.ViewName);
 }
        public void Init()
        {
            var adminUnits = new List<AdminUnit>
                {
                    new AdminUnit {AdminUnitID = 1, Name = "Federal", ParentID = null, AdminUnitTypeID = 1},
                    new AdminUnit {AdminUnitID = 2, Name = "Afar", ParentID = 1, AdminUnitTypeID = 2},
                    new AdminUnit {AdminUnitID = 3, Name = "Zone1", ParentID = 2, AdminUnitTypeID = 3},
                    new AdminUnit {AdminUnitID = 4, Name = "Adhar", ParentID = 12, AdminUnitTypeID = 4},
                };
            var adminUnitTypes = new List<AdminUnitType>
                {
                    new AdminUnitType {AdminUnitTypeID = 1, Name = "Federal"},
                    new AdminUnitType {AdminUnitTypeID = 2, Name = "Region"},
                    new AdminUnitType {AdminUnitTypeID = 3, Name = "Zone"},
                    new AdminUnitType {AdminUnitTypeID = 4, Name = "Woreda"},
                };
            var adminUnitService = new Mock<IAdminUnitService>();
            adminUnitService.Setup(t => t.GetAllAdminUnit()).Returns(adminUnits);
            adminUnitService.Setup(t => t.GetAdminUnitType(1)).Returns(adminUnitTypes[1]);
            adminUnitService.Setup(t => t.GetAdminUnitType(2)).Returns(adminUnitTypes[2]);
            adminUnitService.Setup(t => t.GetRegions()).Returns(adminUnits);

            var userProfiles = new List<UserProfile>
                {
                    new UserProfile {UserProfileID = 1, UserName = "******", Password = "******", Email = "*****@*****.**"},
                    new UserProfile {UserProfileID = 2, UserName = "******", Password="******", Email = "*****@*****.**"},

                };
            var userProfileService = new Mock<IUserProfileService>();
            userProfileService.Setup(t => t.GetAllUserProfile()).Returns(userProfiles);

            var dispatchAllocation = new List<DispatchAllocation>
                {
                    new DispatchAllocation
                        {
                            DispatchAllocationID = new Guid("8296"),
                            PartitionID = 2,
                            HubID = 2,
                            CommodityID = 2,
                            RequisitionNo = "8296",
                            Amount = 500,
                            Unit = 2,
                            FDPID = 2,
                            IsClosed = false
                        },
                    new DispatchAllocation
                        {
                            DispatchAllocationID = new Guid("3096"),
                            PartitionID = 1,
                            HubID = 1,
                            CommodityID = 1,
                            RequisitionNo = "3096",
                            Amount = 1000,
                            Unit = 1,
                            FDPID = 1,
                            IsClosed = false
                        }
                };
            var dispatchAllocationService = new Mock<IDispatchAllocationService>();
            dispatchAllocationService.Setup(t => t.GetAllDispatchAllocation()).Returns(dispatchAllocation);

            _adminUnitController = new AdminUnitController(adminUnitService.Object, userProfileService.Object, dispatchAllocationService.Object);
        }
 public void AdminUnits_AdminUnits_WithOutAdminUnitType_Test()
 {
     AdminUnitController target = new AdminUnitController(); // TODO: Initialize to an appropriate value
     Nullable<int> id = new Nullable<int>(); // TODO: Initialize to an appropriate value
     //var viewName = "Lists/AdminUnits." + id + "";
     id = null;
     EmptyResult actual;
     try
     {
         actual = (EmptyResult)target.AdminUnits(id);
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
 public void Admin_Unit_Edit_POST_Positive_Test()
 {
     mockRepository.Setup(p => p.AdminUnit.SaveChanges(new BLL.AdminUnit())).Verifiable();
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     JsonResult expected = new JsonResult();
     expected.Data = new { success = true };
     int id = 1;
     //string expected = "{ success = true }";
     JsonResult actual;
     actual = (JsonResult)target.Edit(id,new AdminUnit());
     Assert.IsNotNull(actual.Data);
     Assert.AreEqual(expected.Data.ToString(), actual.Data.ToString());
 }
 public void Admin_Unit_Edit_GET_Test()
 {
     mockRepository.Setup(p => p.AdminUnit.FindById(0)).Returns(new AdminUnit());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     int id = 0; // TODO: Initialize to an appropriate value
     //ActionResult expected = null; // TODO: Initialize to an appropriate value
     string viewName = "Edit";
     PartialViewResult actual;
     actual = (PartialViewResult)target.Edit(id);
     Assert.AreEqual(viewName, actual.ViewName);
 }
        public void Admin_Unit_Edit_Negative_POST_Test()
        {
            mockRepository.Setup(p => p.AdminUnit.SaveChanges(new BLL.AdminUnit())).Verifiable();
            mockRepository.Setup(p => p.AdminUnit.FindById(0)).Verifiable();
            AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value

            base.SetModelError(target);

            PartialViewResult actual;
            int id = 1;
            var actualResult = (PartialViewResult)target.Edit(id, new AdminUnit());
            Assert.AreEqual("Edit", actualResult.ViewName);
        }
 public void Admin_Unit_Delete_Post_Negative_Test()
 {
     mockRepository.Setup(p => p.AdminUnit.DeleteByID(0)).Verifiable();
     mockRepository.Setup(p => p.AdminUnit.FindById(0)).Returns(new BLL.AdminUnit());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     base.SetModelError(target);
     int id = 0; // TODO: Initialize to an appropriate value
     ViewResult actual;
     actual = (ViewResult)target.Delete(id);
     Assert.AreEqual("Delete", actual.ViewName);
 }
 public void Admin_Unit_Delete_Post_Positive_Test()
 {
     mockRepository.Setup(p => p.AdminUnit.Delete(new BLL.AdminUnit())).Verifiable();
     mockRepository.Setup(p => p.AdminUnit.FindById(0)).Returns(new BLL.AdminUnit());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     int id = 0; // TODO: Initialize to an appropriate value
     RedirectToRouteResult actual;
     actual = (RedirectToRouteResult)target.Delete(id, new BLL.AdminUnit());
     Assert.IsTrue(actual.RouteValues.ContainsValue("Index"));
 }
 public void Admin_Unit_Create_Zone_GET_Test()
 {
     AdminUnitController target = new AdminUnitController(); // TODO: Initialize to an appropriate value
     int typeid = 3; // TODO: Initialize to an appropriate value
     string viewName = "CreateZone";
     PartialViewResult actual;
     actual = (PartialViewResult)target.Create(typeid);
     Assert.AreEqual(viewName, actual.ViewName);
 }
 public void Admin_Unit_Delete_GET_Test()
 {
     mockRepository.Setup(m => m.AdminUnit.DeleteByID(1)).Verifiable();
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     int id = 1; // TODO: Initialize to an appropriate value
     ViewResult actual;
     actual = (ViewResult)target.Delete(id);
     Assert.AreEqual("Delete", actual.ViewName);
 }
 public void AdminUnits_Index_GET_Test()
 {
     mockRepository.Setup(m => m.AdminUnit.GetAdminUnitTypes()).Returns(new List<BLL.AdminUnitType>());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     //ActionResult expected = null; // TODO: Initialize to an appropriate value
     string viewName = "Index";
     ViewResult actual;
     actual = (ViewResult)target.Index();
     Assert.AreEqual(viewName, actual.ViewName);
 }
 public void AdminUnits_GetRegions_JSON_Test()
 {
     mockRepository.Setup(m => m.AdminUnit.GetRegions()).Returns(new List<BLL.AdminUnit>());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     JsonResult actual;
     actual = (JsonResult)target.GetRegions();
     Assert.IsNotNull(actual.Data);
 }
 public void AdminUnits_GetChildren_JSON_Test()
 {
     mockRepository.Setup(m=>m.AdminUnit.GetChildren(0)).Returns(new List<BLL.AdminUnit>());
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     int unitId = 0; // TODO: Initialize to an appropriate value
     JsonResult actual;
     actual = (JsonResult)target.GetChildren(unitId);
     Assert.IsNotNull(actual.Data);
     //TypeDescriptor.AddProviderTransparent(new AssociatedMetaDataTypeTypeDescriptionProvider(),null)
 }
 public void AdminUnits_Create_Positive_Post_Test()
 {
     AdminUnitModel unit = new AdminUnitModel();
     mockRepository.Setup(p => p.AdminUnit.Add(new BLL.AdminUnit())).Verifiable();
     AdminUnitController target = new AdminUnitController(mockRepository.Object);
     JsonResult expected = new JsonResult();
     expected.Data = new { success = true };
     //string expected = "{ success = true }";
     JsonResult actual;
     actual = (JsonResult)target.Create(unit);
     Assert.IsNotNull(actual.Data);
     Assert.AreEqual(expected.Data.ToString(), actual.Data.ToString());
 }
 public void AdminUnits_Create_Negative_Post_Test()
 {
     mockRepository.Setup(p => p.AdminUnit.Add(new BLL.AdminUnit())).Verifiable();
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     AdminUnitModel unit = new AdminUnitModel(); // TODO: Initialize to an appropriate value
     base.SetModelError(target);
     string viewName = "Create";
     ViewResult actual;
     actual = (ViewResult)target.Create(unit);
     Assert.IsNotNull(actual);
     Assert.AreEqual(viewName, actual.ViewName);
 }