示例#1
0
文件: Main.cs 项目: licnep/smuxi
        private static void ManageUser(bool addUser, bool delUser, bool modUser,
                                       bool listUsers,
                                       string username, string password)
        {
            Config             config     = new Config();
            UserListController controller = new UserListController(config);

            if (addUser)
            {
                config.Load();
                controller.AddUser(username, password);
                config.Save();
                Console.WriteLine(
                    _("User \"{0}\" successfully added to server."),
                    username
                    );
                Environment.Exit(0);
            }
            else if (modUser)
            {
                config.Load();
                controller.ModifyUser(username, password);
                config.Save();
                Console.WriteLine(
                    _("User \"{0}\" successfully modified."),
                    username
                    );
                Environment.Exit(0);
            }
            else if (delUser)
            {
                config.Load();
                controller.DeleteUser(username);
                config.Save();
                Console.WriteLine(
                    _("User \"{0}\" successfully deleted from server."),
                    username
                    );
                Environment.Exit(0);
            }
            else if (listUsers)
            {
                config.Load();
                var users = controller.GetUsers();
                Console.WriteLine(_("Users:"));
                foreach (var user in users)
                {
                    if (user == "local")
                    {
                        // is not a real user and could cause confusion
                        continue;
                    }
                    Console.WriteLine("\t{0}", user);
                }
                Environment.Exit(0);
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                /* Put all PageLoad code here. */
            }


            // The 'GetUsers' function returns List<UserModel>

            UserListController con = new UserListController(ConfigurationManager.ConnectionStrings["DBInformation"].ToString());

            rUsers.DataSource = con.GetUsers();
            rUsers.DataBind();
        }
示例#3
0
        public void UserListController_GetUsers_ShouldGetAllUsersFromTheDatabase()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseMySql(ConnectionString)
                          .Options;
            var context    = new ApplicationDbContext(options);
            var controller = new UserListController(context);
            var scans      = context.Users.ToListAsync().Result;

            //Act
            var result = controller.GetUsers().Result.Value;

            //Assert
            Assert.Equal(scans, result);
        }