/// <summary>
 /// Appends UserProfile-specific parameters to the specificied SqlCommand. 
 /// </summary>
 /// <param name="command">SqlCommand to be executed.</param>
 /// <param name="alert">Instance of UserProfile class</param>
 /// <param name="action">Database action type (select, insert, update, delete).</param>
 public static void AddEntityParameters(this SqlCommand command, UserProfile userProfile, DbActionType action)
 {
     command.AddCommonParameters(userProfile.Id, action);
     command.Parameters.Add("@email", SqlDbType.NVarChar).Value = userProfile.Name.ToDbValue();
     command.Parameters.Add("@password", SqlDbType.NVarChar).Value = userProfile.Password.ToDbValue();
     command.Parameters.Add("@password_question", SqlDbType.NVarChar).Value = userProfile.PasswordQuestion.ToDbValue();
     command.Parameters.Add("@password_answer", SqlDbType.NVarChar).Value = userProfile.PasswordAnswer.ToDbValue();
     command.Parameters.Add("@first_name", SqlDbType.NVarChar).Value = userProfile.FirstName.ToDbValue();
     command.Parameters.Add("@last_name", SqlDbType.NVarChar).Value = userProfile.LastName.ToDbValue();
     command.Parameters.Add("@comment", SqlDbType.NVarChar).Value = userProfile.Comment.ToDbValue();
     command.Parameters.Add("@is_approved", SqlDbType.Bit).Value = userProfile.IsApproved;
     command.Parameters.Add("@current_time_utc", SqlDbType.DateTime).Value = DateTime.UtcNow;
 }
 public static int CreateUser(UserProfile entity)
 {
     var res = -1;
     using (var holder = SqlConnectionHelper.GetConnection())
     {
         var cmd = holder.Connection.CreateSPCommand("user_create");
         try
         {
             cmd.AddEntityParameters(entity, DbActionType.Insert);
             cmd.ExecuteNonQuery();
             entity.Id = cmd.GetRowIdParameter();
             res = cmd.GetReturnParameter();
         }
         catch (SqlException e)
         {
             cmd.AddDetailsToException(e);
             throw;
         }
     }
     return res;
 }
        private static AccountController GetAccountController(UserProfile user = null)
        {
            var membershipRepository = new Mock<MembershipRepository>();

            var cookieContainer = new Mock<ICookieContainer>();
            cookieContainer.Setup(c => c.SetValue(It.IsAny<string>(), It.IsAny<object>(), It.IsAny<DateTime>()));
            cookieContainer.Setup(c => c.SetAuthCookie(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()));

            membershipRepository.Setup(m => m.GetUser(It.IsAny<string>(), It.IsAny<string>())).Returns(user);

            IFormsAuthentication formsAuth = new MockFormsAuthenticationService();
            var contextBase = MvcMockHelpers.FakeHttpContext(); // new MockHttpContext();

            var controller = new AccountController(
                cookieContainer.Object, formsAuth, membershipRepository.Object);
            controller.ControllerContext = new ControllerContext(contextBase, new RouteData(), controller);
            controller.Url = new UrlHelper(new RequestContext(contextBase, new RouteData()), new RouteCollection());
            return controller;
        }
 public static UserProfile CreateUser(string email, string password, string default_company_name, string default_account_name, string approveCode)
 {
     UserProfile res = new UserProfile(email, password, approveCode);
     using (var holder = SqlConnectionHelper.GetConnection())
     {
         var cmd = holder.Connection.CreateSPCommand("user_signin");
         try
         {
             cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
             cmd.Parameters.Add("@email", SqlDbType.NVarChar).Value = email;
             cmd.Parameters.Add("@password", SqlDbType.NVarChar).Value = password;
             cmd.Parameters.Add("@default_company_name", SqlDbType.NVarChar).Value = default_company_name;
             cmd.Parameters.Add("@default_account_name", SqlDbType.NVarChar).Value = default_account_name;
             cmd.Parameters.Add("@current_time_utc", SqlDbType.DateTime).Value = DateTime.UtcNow;
             cmd.Parameters.Add("@approve_code", SqlDbType.NVarChar).Value = approveCode;
             cmd.ExecuteNonQuery();
             res.Id = cmd.GetRowIdParameter();
         }
         catch (SqlException e)
         {
             cmd.AddDetailsToException(e);
             throw;
         }
     }
     return res;
 }
        private static TransactionsController GetController()
        {
            var reps = new Mock<TransactionsRepository>();
            reps.Setup(m => m.GetTransactions(It.IsAny<int?>())).Returns<int?>(p => GetTestTrans(p));
            var car_rep = new Mock<CategoriesRepository>();
            car_rep.Setup(m => m.GetAll(It.IsAny<int?>())).Returns<int?>(p => GetTestCats(p));
            var tag_rep = new Mock<TagsRepository>();
            tag_rep.Setup(m => m.GetAll(It.IsAny<int?>())).Returns<int?>(p => GetTestTags(p));

            var controller = new TransactionsController(reps.Object, car_rep.Object, tag_rep.Object);
            //set user and def company
            var user = new UserProfile();
            user.DefaultCompany = 1;
            var comps = new List<Company>();
            comps.Add(new Company() { Id = 1 });
            user.Companies = comps;
            controller.CurrentUser = user;

            return controller;
        }
 public virtual string SetSessionForUser(UserProfile profile)
 {
     // generate session key
     var cId = Guid.NewGuid().ToString();
     new CacheWrapper().Set(cId, profile, true, null);
     return cId;
 }