public void CreateWithInvalidModel()
 {
     var controller = new RolesController(new UserRoleBLL(new RoleServiceStub()));
     var role = new Role();
     controller.ViewData.ModelState.AddModelError("RoleName", "");
     var actionResult = (ViewResult)controller.Create(role);
     Assert.AreEqual(actionResult.ViewName, "");
 }
        public void CreateWithValidId()
        {
            var controller = new RolesController(new UserRoleBLL(new RoleServiceStub()));
            var role = new Role { RoleId = 1, RoleStringId = "C", RoleName = "Customer" };

            var actionResult = (RedirectToRouteResult)controller.Create(role);

            Assert.AreEqual(actionResult.RouteName, "");
            Assert.IsTrue(actionResult.RouteValues.Values.Count == 1);
            Assert.AreEqual(actionResult.RouteValues.Values.First(), "Index");
        }
 public void Update(Role role)
 {
     db.Entry(role).State = EntityState.Modified;
     this.Save();
 }
        public void GetRoleList()
        {
            var controller = new RolesController(new UserRoleBLL(new RoleServiceStub()));

            var role = new Role { RoleId = 1, RoleStringId = "C", RoleName = "Customer" };
            List<Role> forventet = new List<Role>();
            forventet.Add(role);
            forventet.Add(role);
            forventet.Add(role);

            var actionResult = (ViewResult)controller.Index();
            var result = (List<Role>)actionResult.Model;

            Assert.AreEqual(actionResult.ViewName, "");
            for(var i = 0; i < forventet.Count; i++)
            {
                Assert.AreEqual(forventet[i].RoleId, result[i].RoleId);
                Assert.AreEqual(forventet[i].RoleStringId, result[i].RoleStringId);
                Assert.AreEqual(forventet[i].RoleName, result[i].RoleName);
            }
        }
 public void Insert(Role role)
 {
     db.Role.Add(role);
     this.Save();
 }