예제 #1
0
        public void TestFindAll()
        {
            IDatabase    db       = DALFactory.CreateDatabase();
            IUserDao     dao      = DALFactory.CreateUserDao(db);
            IList <User> entities = dao.findAll();

            Assert.AreEqual(entities.Count, 2);
        }
예제 #2
0
        public void TestFindById()
        {
            IDatabase db  = DALFactory.CreateDatabase();
            IUserDao  dao = DALFactory.CreateUserDao(db);
            User      u   = dao.findById(1);

            Assert.AreEqual(u.Id, 1);
            Assert.AreEqual(u.Email, "*****@*****.**");
        }
예제 #3
0
        public void TestFindByUniqueProperty()
        {
            IDatabase    db   = DALFactory.CreateDatabase();
            IUserDao     dao  = DALFactory.CreateUserDao(db);
            PropertyInfo info = typeof(User).GetProperty("Email");
            User         u    = dao.findByUniqueProperty(info, "*****@*****.**");

            Assert.AreEqual(u.Email, "*****@*****.**");
            Assert.AreEqual(u.Id, 1);
        }
예제 #4
0
        public void TestUpdate()
        {
            IDatabase db  = DALFactory.CreateDatabase();
            IUserDao  dao = DALFactory.CreateUserDao(db);
            User      u   = dao.findById(1);

            u.FirstName = "Larry";
            dao.Update(u);
            User result = dao.findById(1);

            Assert.AreEqual(result.FirstName, "Larry");
        }
예제 #5
0
        public User AuthenticateAndReturnValidUser(string userName, string password)
        {
            IUserDao      dao  = DALFactory.CreateUserDao(database);
            HashAlgorithm algo = new SHA256Managed();

            byte[] pw   = algo.ComputeHash(Encoding.Default.GetBytes(userName + "|" + password));
            string pass = System.BitConverter.ToString(pw);
            User   u    = dao.findByUniqueProperty(typeof(User).GetProperty("Email"), userName);

            if (u != null && u.Password.Equals(pass))
            {
                return(u);
            }
            return(null);
        }
예제 #6
0
        public void TestInsert()
        {
            IDatabase db  = DALFactory.CreateDatabase();
            IUserDao  dao = DALFactory.CreateUserDao(db);
            User      u   = new User();

            u.Email     = "*****@*****.**";
            u.FirstName = "Unit Test";
            u.LastName  = "Unit Test";
            u.Password  = "******";
            dao.Insert(u);
            PropertyInfo info   = typeof(User).GetProperty("Email");
            User         result = dao.findByUniqueProperty(info, "*****@*****.**");

            Assert.AreEqual(result.Email, "*****@*****.**");
        }