Esempio n. 1
0
        /// <summary>
        /// Gets the user information from the database.
        /// </summary>
        /// <param name="userName">UserName of the user.</param>
        /// <returns>User object with properties filled up.</returns>
        public static User GetUser(string userName) {

            User user = null;
            SqlDataReader reader = UsersDAO.GetUserInformation(userName);

            try
            {
                while (reader.Read())
                {
                    user = new User
                    {
                        UserName = reader["UserName"].ToString(),
                        FirstName = reader["FirstName"].ToString(),
                        LastName = reader["LastName"].ToString(),
                        Gender = reader["Gender"].ToString(),
                        Email = reader["Email"].ToString(),
                        PhoneNumber = reader["PhoneNumber"].ToString(),
                        Address = reader["Address"].ToString(),
                        ZipCode = reader["ZipCode"].ToString()
                    };
                }
            }
            catch (Exception)
            {

            }
            finally 
            {
                reader.Close();
            }
            return user;
        }
        /// <summary>
        /// Process Request that updates user info given the HttpContext, and returns confirmation message upon successful completion
        /// </summary>
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            String jsonString;
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            try
            {
                User user = new User
                {
                    FirstName = request.Form["firstName"],
                    LastName = request.Form["lastName"],
                    Gender = request.Form["gender"],
                    PhoneNumber = request.Form["phoneNumber"],
                    Address = request.Form["address"],
                    ZipCode = request.Form["zipCode"],
                    UserName = request.Form["userName"]
                };
                user.UpdateProfile();

                jsonString = serializer.Serialize(new { result = "success" });
            }
            catch (Exception ex)
            {
                jsonString = serializer.Serialize(new { result = ex.Message });
            }
           
            response.Write(jsonString);
            response.ContentType = "application/json";
        }
 public void Initialize()
 {
     if (_testUser == null)
     {
         _testUser = User.GetUser("test.user");
     }
 }
        public void TestValidateUser()
        {
            String userName = Convert.ToString(TestContext.DataRow["UserName"]);
            String password = Convert.ToString(TestContext.DataRow["Password"]);
            String expectedResult = Convert.ToString(TestContext.DataRow["Result"]);

            IUser user = new User
            {
                UserName = userName,
                Password = password
            };
            LoginModel.Login login = new LoginModel.Login(user);
            String actualResult = login.ValidateUser();

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void TestCreateReport()
        {
            ReportTypeEnum reportTypeId = (ReportTypeEnum)Enum.Parse(
                typeof(ReportTypeEnum),
                TestContext.DataRow["ReportTypeId"].ToString());
            String message = TestContext.DataRow["Message"].ToString();
            String latitude = TestContext.DataRow["Latitude"].ToString();
            String longitude = TestContext.DataRow["Longitude"].ToString();
            String location = TestContext.DataRow["Location"].ToString();
            DateTime dateReported = Convert.ToDateTime(TestContext.DataRow["DateReported"]);
            User user = new User
            {
                UserName = TestContext.DataRow["UserName"].ToString()
            };
            String expectedResult = TestContext.DataRow["Result"].ToString();

            Report report = new Report(reportTypeId, message, latitude,
                longitude, location, dateReported, user);
            string actualResult = report.CreateReport(new TestContentLocator());
            Assert.IsTrue(actualResult.Contains(expectedResult), actualResult);
        }
        public void TestCreateUser()
        {
            String userName = Convert.ToString(TestContext.DataRow["UserName"]);
            String password = Convert.ToString(TestContext.DataRow["Password"]);
            String firstName = Convert.ToString(TestContext.DataRow["FirstName"]);
            String lastName = Convert.ToString(TestContext.DataRow["LastName"]);
            String email = Convert.ToString(TestContext.DataRow["Email"]);
            String expectedResult = Convert.ToString(TestContext.DataRow["Result"]);

            IUser newUser = new User
            {
                UserName = userName,
                Password = password,
                FirstName = firstName,
                LastName = lastName,
                Email = email
            };
            LoginModel.Login login = new LoginModel.Login(newUser);
            String actualResult = login.CreateUser(new TestContentLocator()).ToString();

            Assert.AreEqual(expectedResult, actualResult);
        }