public void CreateTest() { RoleDAL dal = new RoleDAL(ConfigurationManager.ConnectionStrings["IMDB"].ConnectionString); var result = dal.CreateRole(new RoleDTO { RoleName = "Адмін", Description = "Може взаэмодіяти з юзерами", }); Assert.IsTrue(result.RoleId != 0, "returned ID should be more than zero"); }
public void GetAllTest() { RoleDAL dal = new RoleDAL(ConfigurationManager.ConnectionStrings["IMDB"].ConnectionString); var result = dal.CreateRole(new RoleDTO { RoleName = "User", Description = "може зайти на сайт", }); var movies = dal.GetAllRole(); Assert.AreEqual(0, movies.Count(x => x.RoleName == "User")); }
/// <summary> /// Create a new role. /// </summary> /// <param name="role">Role that you want to create.</param> public void CreateRole(String roleName) { Role newRole = new Role(); newRole.Role_Name = roleName; newRole.Role_IsDelete = false; //Check role name is exists. if (RD.GetRole(newRole.Role_Name) != null) { throw new Exception("This role is existed."); } int result = RD.CreateRole(newRole); if (result == -1) { throw new Exception("An error occurred while executing this operation."); } }
public void RoleDALMenu() { while (true) { System.Console.WriteLine("Welcome in Role"); System.Console.WriteLine("c - Create"); System.Console.WriteLine("r - read one"); System.Console.WriteLine("rall - read all"); System.Console.WriteLine("u - update"); System.Console.WriteLine("d - delete"); System.Console.WriteLine("else - exit"); string a = System.Console.ReadLine(); switch (a) { case "c": System.Console.WriteLine("Input RoleName:"); role = dal.CreateRole(new RoleDTO { RoleName = System.Console.ReadLine() }); System.Console.WriteLine("You add the: Id - " + role.RoleId + " Name - " + role.RoleName); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "r": System.Console.Write("Choose Id: "); role = dal.GetRoleById(System.Convert.ToInt32(System.Console.ReadLine())); System.Console.WriteLine("You read the: Id - " + role.RoleId + " Name - " + role.RoleName); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "rall": List <RoleDTO> categories = dal.GetAllRole(); for (int i = 0; i < role.Count; i++) { System.Console.WriteLine("Id - " + role[i].RoleId + " Name - " + role[i].RoleName); } System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "u": System.Console.WriteLine("Update Name:"); role = dal.UpdateRole(new RoleDTO { RoleName = System.Console.ReadLine() }); System.Console.WriteLine("You add the: Id - " + role.RoleId + " Name - " + role.RoleName); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "d": System.Console.WriteLine("Choose Id:"); dal.DeleteRole(System.Convert.ToInt32(System.Console.ReadLine())); System.Console.WriteLine("Delete successful"); System.Console.WriteLine("Press any key"); System.Console.WriteLine(""); System.Console.WriteLine(""); System.Console.ReadKey(); break; case "else": break; } } }