public void SaveUserTest()
        {
            var sut = new UserPersister();
            var user = new User { Email = "*****@*****.**", FirstName = "Louis",
                                  LastName = "Salin", Password = "******" };

            sut.Save(user);

            using (var connection = new SqliteConnection("URI=file:Users.db3"))
            {
                var query = "SELECT * FROM Users WHERE Email='*****@*****.**';";

                using (var cmd = connection.CreateCommand())
                {
                    connection.Open();
                    cmd.CommandText = query;

                    using (var reader = cmd.ExecuteReader())
                    {
                        reader.Read();

                        reader["FirstName"].ShouldEqual("Louis");
                        reader["LastName"].ShouldEqual("Salin");
                        reader["Email"].ShouldEqual("*****@*****.**");
                        reader["Password"].ShouldEqual("pass123");

                        reader.Close();
                    }

                    connection.Close();
                }
            }
        }
Exemplo n.º 2
0
        public void Run(AppArguments arguments)
        {
            var firstname = GetFirstName(arguments);
            var lastname = GetLastName(arguments);
            var email = GetEmail(arguments);
            var password = GetPassword(arguments);

            var user = new User {FirstName = firstname,
                                 LastName = lastname,
                                 Email = email,
                                 Password = password};

            persister.Save(user);
        }
Exemplo n.º 3
0
        public bool Save(User user)
        {
            try
            {
                using (var connection = new SqliteConnection("URI=file:Users.db3"))
                {
                    ExecuteQuery(GetQuery(user));
                }
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Exemplo n.º 4
0
        private string GetQuery(User user)
        {
            string query = "";
            bool userFound = false;
            ExecuteReaderQuery(string.Format("SELECT COUNT(*) AS Count FROM Users WHERE Email='{0}'", user.Email),
                               reader =>
                               {
                                   reader.Read();
                                   userFound = int.Parse(reader["Count"].ToString()) > 0;
                               });

            if (userFound)
                query = string.Format("UPDATE Users SET FirstName='{0}', LastName='{1}', Password='******' WHERE Email='{3}'",
                                      user.FirstName, user.LastName, user.Password, user.Email);
            else
                query = string.Format("INSERT INTO Users VALUES ('{0}', '{1}', '{2}', '{3}')",
                                      user.FirstName, user.LastName, user.Email, user.Password);

            return query;
        }