public void TestMethod1() { //Make the virtual context that has User database set and Course database set var context = new TestNLDS_V_Context(); //make test user with empry courses list ICollection<Course> course_collection = new Collection<Course>(); User test = new User { ID = 1, username = "******", password = "******", email = "*****@*****.**", phone = 1231231234, selfDescription = "why", courses = course_collection }; //add user and course to virtual database set context.Users.Add(test); context.Courses.Add(new Course { ID = 2, name = "test101", school = "uiuc", classInfo = "info", year = 2016, season = Season.Fall }); //Gain the controller var controller = new UsersController(context, test); controller.set_currentUser(test); //current user = test string[] test_array = { "2" }; //add course to the user var result = controller.AddCourses(test_array); Assert.IsNotNull(result); //check it is not null Assert.IsNotNull(test.courses); }
public void TestCreateUser() { var testdb = new TestNLDS_V_Context(); User testuser = new User { ID = 3, username = "******", password = "******", books = new List<Book>(), courses = new List<Course>() }; var controller = new UsersController(testdb, testuser); ActionResult result = controller.Create(testuser); // System.Diagnostics.Debug.WriteLine(testdb.Users.Find(3).username); Assert.AreEqual(testdb.Users.Find(3).username, "kevinly"); }
private static User currentUser = null;//Current user //set the current user if there are data in Cookie, else set currentuser to null private void initializeFunc() { //get user basic info if (Request.Cookies["NLDS_V_username"] == null || Request.Cookies["NLDS_V_password"] == null)//if there is no current user { currentUser = null; return; } else { string username = Request.Cookies["NLDS_V_username"].Value; string password = Request.Cookies["NLDS_V_password"].Value; try { //???????????????????? Hope default value of a I-created class is null ?????????????????????? currentUser = db.Users.SingleOrDefault(u => u.username == username && u.password == password); } catch { currentUser = null; return; } } }
public void MarkAsModified(User id) { }
public void set_currentUser(User name) { currentUser = name; }
public ActionResult LogIn([Bind(Include = "username,password")] User user, string navigationUrl) { try { currentUser = db.Users.SingleOrDefault(u => u.username == user.username && u.password == user.password); } catch { currentUser = null; } if(currentUser != null) { Response.Cookies["NLDS_V_username"].Value = user.username; Response.Cookies["NLDS_V_username"].Expires = DateTime.Now.AddDays(1); Response.Cookies["NLDS_V_password"].Value = user.password; Response.Cookies["NLDS_V_password"].Expires = DateTime.Now.AddDays(1); if (!String.IsNullOrEmpty(navigationUrl)) { Response.Redirect(navigationUrl); } return RedirectToAction("Index"); } return View(); }
private NLDS_VContext db = new NLDS_VContext(); //database to query and save data #endregion Fields #region Constructors public UsersController(NLDS_VContext context, User user) { this.db = context; currentUser = user; }