예제 #1
0
        /// <summary>
        /// Adds a 'User'-entry to database.
        /// </summary>
        /// <param name="fullname">String containing 2 or 3 names for user.</param>
        /// <param name="email">Email for user, only one user may exist per email.</param>
        /// <param name="password">Password for user.</param>
        /// <returns>Returns true is the user could be added to the database, false if the email is used.</returns>
        public bool AddUser(string fullname, string email, string password)
        {
            #region Checking 'email' and creating instance of 'User'

            if (IsEmailInUse(email))
            {
                return false;
            }

            User user;

            if (!ValidateName(fullname))
            {
                return false;
            }

            string[] names = fullname.Split(' ');

            if (names.Length <= 2)
            {
                user = new User() { Firstname = names[0], Lastname = names[1], Email = email, Password = password };
            }
            else
            {
                user = new User() { Firstname = names[0], Middelname = names[1], Lastname = names[2], Email = email, Password = password };
            }

            #endregion

            using (var db = new DatabaseContext())
            {
                db.UserSet.Add(user);
                db.SaveChanges();
            }

            return true;
        }
예제 #2
0
        public void FindUserByEmail_TwoUsersWithSameEmailExistInDB_ThrowsMultipleOccourencesOfEmailWasFoundException()
        {
            User user1 = new User() { Firstname = "John", Middelname = "Derp", Lastname = "Herpson", Email = "email", Password = "******" };
            User user2 = new User() { Firstname = "Simon", Middelname = "Siggy", Lastname = "Sergson", Email = "email", Password = "******" };

            using (var db = new DatabaseContext())
            {
                db.UserSet.Add(user1);
                db.UserSet.Add(user2);
                db.SaveChanges();
            }

            Assert.Throws<MultipleOccourencesOfEmailWasFoundException>(() => _uut.FindUserByEmail("email"));
        }
예제 #3
0
        public void Setup()
        {
            _userAccess = new UserAccess();
            _uut = new PoolAccess(_userAccess);

            _testUser1 = new User() { Firstname = "John", Middelname = "Derp", Lastname = "Andersen", Email = "*****@*****.**", Password = "******" };
            _testUser2 = new User() { Firstname = "Sire", Middelname = "Herp", Lastname = "Jensenei", Email = "*****@*****.**", Password = "******" };

            using (var db = new DatabaseContext())
            {
                db.UserSet.Add(_testUser1);
                db.UserSet.Add(_testUser2);
                db.SaveChanges();
            }
        }
예제 #4
0
        public void FindSpecificPool_EmptyDatabase_ThrowsPoolNotFoundException()
        {
            User derp = new User() { Firstname = "John", Middelname = "Derp", Lastname = "Andersen", Email = "*****@*****.**" };

            Assert.Throws<PoolNotFoundException>(() => _uut.FindSpecificPool(derp.Email, "thispooldoesnotexist"));
        }