public void InvalidUser1()
        {
            User u = new User { Password = Cryptography.PasswordHash("test"), Email = "*****@*****.**" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public void DefaultsForNewUser()
        {
            User u = new User();

            // Test if the constructor writes the correct default values
            Assert.IsNotNull(u.Created_At, "Created At should not be null");
            Assert.IsNotNull(u.LastOnline, "Last online should not be null");
            Assert.IsNotNull(u.Rank, "Rank should not be null");

            // Test if the expected default values are present.
            Assert.IsTrue(u.Created_At == StringToDateTime.ToUnixTimeStamp(DateTime.Now), "Created At should be initialized to DateTime.Now.ToString()");
            Assert.IsTrue(u.LastOnline == u.Created_At, "Last Online should be initialized to be the same as Created At");

            // Everything else should be null or 0
            Assert.IsNull(u.UserName, "UserName should be initialized to null");
            Assert.IsNull(u.Password, "Password should be initialized to null");
            Assert.IsNull(u.Email, "Email should be initialized to null");
            Assert.AreEqual<int>(0, u.Rank, "Rank should be defaulted to 0");
            Assert.IsNull(u.Name, "Name should be initialized to null");
            Assert.IsNull(u.Birthday, "Birthday should be initialized to null");
            Assert.IsNull(u.Location, "Location should be initialize to null");
            Assert.IsNull(u.Website, "Website should be initialize to null");
            Assert.IsNull(u.Languages, "Languages should be initialize to null");
        }
        public void InvalidUser2()
        {
            User u = new User { UserName = "******", Email = "*****@*****.**" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public void InvalidUserWebsite2()
        {
            User u = new User { Website = "ftp://google.com", UserName = "******", Password = Cryptography.PasswordHash("test"), Email = "*****@*****.**" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public void InvalidUserRealName()
        {
            User u = new User { Name = "sjaak", UserName = "******", Password = Cryptography.PasswordHash("test"), Email = "*****@*****.**" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public void InvalidUserName7()
        {
            User u = new User { UserName = "******", Password = Cryptography.PasswordHash("test"), Email = "*****@*****.**" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public void InvalidUserLocation()
        {
            User u = new User { Location = "leeuwarden", UserName = "******", Password = Cryptography.PasswordHash("test"), Email = "*****@*****.**" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public void InvalidUserEmail4()
        {
            User u = new User { UserName = "******", Password = Cryptography.PasswordHash("test"), Email = "test@testmail" };

            db.Users.Add(u);
            db.SaveChanges();
        }
        public ActionResult Index(User user)
        {
            // check if the conditions are checked
            if (Request.Form.Get("ConditionsAccepted") == "false" ) // check if the conditions has been checked
                ModelState.AddModelError("", "De gebruikersvoorwaarden dienen te worden geacepteerd");
            // check if the two passwords are equal
            if (Request.Form.Get("PassWord2") != user.Password) // check if password1 and password2 are the same, preventing password typos
                ModelState.AddModelError("", "De ingevulde wachtwoorden komen niet overeen");
            // check if the email is being used
            var Email = from emailAdress in db.Users
                        where user.Email == emailAdress.Email
                        select emailAdress.Email;
            if (Email.Count() != 0) // email is being used so show an error
                ModelState.AddModelError("", "Het e-mail adress is al gebruikt.");
            // check if the username is being used
            var userName = from NameUser in db.Users
                           where user.UserName.ToLower() == NameUser.UserName.ToLower()
                           select NameUser.UserName;
            if (userName.Count() != 0) // username is being used so show an error
                ModelState.AddModelError("", "Deze username is al gebruikt.");

            if (ModelState.IsValid) // if so add to database
            {
                // everything is right
                // hash the password
                // in a try catch incase we are unable to send an mail
                try
                {
                    user.Password = Cryptography.PasswordHash(user.Password);
                    user.ActivationLink = Cryptography.UrlHash(user.Email);
                    db.Users.Add(user);
                    // try catch is for this part. We need to check if we can send this email if not show an error
                    UserMailer.MailConfirm(user.ActivationLink, user.Email).Send();
                }
                catch
                {
                    ModelState.AddModelError("", "Er is iets mis gegaan. Onze excuses. Probeer het opnieuw aub.");
                }
                if (ModelState.IsValid)
                {
                    db.SaveChanges();
                    return RedirectToAction("gelukt");
                }
            }
            // if we got here the fields were incorrect. Reshow the form.
            return View();
        }