Пример #1
0
        public static void SignUp(string userName, string email)
        {
            UserManager  mgr;
            IHttpContext context;
            string       passHash;

            UserTestTools.SignUp(userName, email, out mgr, out context, out passHash);
        }
Пример #2
0
        public void UserManagerShouldGetCorrectSession()
        {
            string        userName = MethodBase.GetCurrentMethod().Name;
            IHttpContext  context;
            LoginResponse result;
            UserManager   userMgr;

            UserTestTools.SignUpAndLogin(userName, out context, out result, out userMgr);

            Session session = Session.Get(context);

            Expect.AreEqual(session.Id.Value, userMgr.Session.Id.Value, "Session ids didn't match");
        }
Пример #3
0
        public void SessionShouldBeActiveAfterLogin()
        {
            string        userName = MethodBase.GetCurrentMethod().Name;
            IHttpContext  context;
            LoginResponse result;
            UserManager   userMgr;

            UserTestTools.SignUpAndLogin(userName, out context, out result, out userMgr);

            Session session = Session.Get(context);

            Expect.IsTrue(session.IsActive.Value, "session wasn't active");
        }
Пример #4
0
        private static void GetProviderAndPendingConfirmation(out DaoMembershipProvider provider, out User user, out Account account)
        {
            SQLiteRegistrar.Register("Users");
            Db.TryEnsureSchema("Users");

            user = UserTestTools.GetTestUser();

            provider = new DaoMembershipProvider();
            account  = Account.Create(user, "test", "test");
            Expect.IsNotNull(account.Id);
            Expect.IsTrue(account.Id > 0);
            Expect.IsFalse(account.IsConfirmed.Value);
        }
Пример #5
0
        public void LoginShouldFailIfBadPassword()
        {
            string       userName = MethodBase.GetCurrentMethod().Name;
            UserManager  userProxy;
            IHttpContext context;
            string       passHash;

            UserTestTools.SignUp(userName, out userProxy, out context, out passHash);

            LoginResponse result = userProxy.Login(userName, "badPassword");

            Expect.IsFalse(result.Success, "login should have failed");
        }
Пример #6
0
        public void SignOutShouldSucceed()
        {
            string        userName = MethodBase.GetCurrentMethod().Name;
            IHttpContext  context;
            LoginResponse result;
            UserManager   userMgr;

            UserTestTools.SignUpAndLogin(userName, out context, out result, out userMgr);

            SignOutResponse response = userMgr.SignOut();

            Expect.AreEqual(true, response.Success);
        }
Пример #7
0
        public void LoginShouldCreateLoginEntry()
        {
            string userName = MethodBase.GetCurrentMethod().Name;

            Login.LoadAll().Delete();
            Expect.AreEqual(0, Login.LoadAll().Count);

            UserTestTools.SignUpAndLogin(userName, out IHttpContext context, out LoginResponse result);

            User  user  = User.OneWhere(c => c.UserName == userName);
            Login login = Login.OneWhere(c => c.UserId == user.Id);

            Expect.IsNotNull(login);
        }
Пример #8
0
        public void UserShouldBeAuthenticatedAfterLogin()
        {
            string userName = MethodBase.GetCurrentMethod().Name;

            UserTestTools.SignUpAndLogin(userName, out IHttpContext context, out LoginResponse result);

            IHttpContext context2 = A.Fake <IHttpContext>();

            context2.Request = new TestRequest();

            Session session = Session.Init(context2);

            Expect.IsTrue(session.UserOfUserId.IsAuthenticated);
            Expect.IsTrue(context2.User.Identity.IsAuthenticated);
        }
Пример #9
0
        public void SessionInitShouldSetHttpContextUser()
        {
            string userName = MethodBase.GetCurrentMethod().Name;

            UserTestTools.SignUpAndLogin(userName, out IHttpContext context, out LoginResponse result);

            IHttpContext context2 = A.Fake <IHttpContext>();

            context2.Request = new TestRequest();

            Session session = Session.Init(context2);

            Expect.IsNotNull(context2.User, "context2.User was null");
            Expect.IsNotNull(context2.User.Identity, $"context2.User.Identity was null:\r\n   {session.Database.ConnectionString}");
            Expect.AreEqual(userName, context2.User.Identity.Name);
        }
Пример #10
0
        public void LoginShouldSetUserInUserResolvers()
        {
            string        userName = MethodBase.GetCurrentMethod().Name;
            IHttpContext  context;
            LoginResponse result;

            UserTestTools.SignUpAndLogin(userName, out context, out result);

            Expect.IsTrue(result.Success);

            string check  = UserResolvers.Default.GetUser(context);
            string check2 = context.User.Identity.Name;

            Expect.AreEqual(userName, check);
            Expect.AreEqual(userName, check2);
        }
Пример #11
0
        public void SignUpShouldSetAccountToken()
        {
            string userName = MethodBase.GetCurrentMethod().Name;

            User.UserDatabase = new SQLiteDatabase(userName);
            User.UserDatabase.TryEnsureSchema <User>();
            UserTestTools.SignUp(userName, out UserManager userProxy, out IHttpContext context, out string passHash);

            User    user    = User.GetByUserNameOrDie(userName);
            Account account = user.AccountsByUserId.FirstOrDefault();

            Expect.IsNotNull(user.AccountsByUserId.FirstOrDefault());
            Expect.IsNotNullOrEmpty(account.Token);

            OutLineFormat("Token: {0}", account.Token);
        }
Пример #12
0
        public void UserShouldBeAuthenticatedAfterLogin()
        {
            string userName = MethodBase.GetCurrentMethod().Name;

            User.UserDatabase = new SQLiteDatabase(userName);
            User.UserDatabase.TryEnsureSchema <User>();
            UserTestTools.SignUpAndLogin(userName, out IHttpContext context, out LoginResponse result);

            IHttpContext context2 = Substitute.For <IHttpContext>();

            context2.Request = new TestRequest();

            Session session = Session.Init(context2);

            Expect.IsTrue(session.UserOfUserId.IsAuthenticated);
            Expect.IsTrue(context2.User.Identity.IsAuthenticated);
        }
Пример #13
0
        public void ConfirmShouldConfirmAccount()
        {
            string userName = MethodBase.GetCurrentMethod().Name;

            UserTestTools.SignUpAndLogin(userName, out IHttpContext context, out LoginResponse result);

            UserManager userMgr = new UserManager();
            User        user    = User.GetByUserNameOrDie(userName);
            Account     account = user.AccountsByUserId.FirstOrDefault();

            userMgr.ConfirmAccount(account.Token);

            user.AccountsByUserId.Reload();
            account = user.AccountsByUserId.FirstOrDefault();

            Expect.IsTrue(account.IsConfirmed.Value, "was not confirmed");
        }
Пример #14
0
        public void SessionEndShouldEndSession()
        {
            string        userName = MethodBase.GetCurrentMethod().Name;
            IHttpContext  context;
            LoginResponse result;
            UserManager   userMgr;

            UserTestTools.SignUpAndLogin(userName, out context, out result, out userMgr);

            Session session = Session.Get(context);

            session.End();

            Expect.IsFalse(session.IsActive.Value);

            Session doubleCheck = Session.OneWhere(c => c.Id == session.Id.Value);

            Expect.IsFalse(doubleCheck.IsActive.Value, "Doublecheck was still active");
        }
Пример #15
0
        public void LoginDateTimeShouldBeNowInstant()
        {
            string        userName = MethodBase.GetCurrentMethod().Name;
            IHttpContext  context;
            LoginResponse result;

            UserTestTools.SignUpAndLogin(userName, out context, out result);

            User    user       = User.GetByUserNameOrDie(userName);
            Instant nowInstant = new Instant();
            Login   login      = new Login();

            login.UserId   = user.Id;
            login.DateTime = nowInstant.ToDateTime();
            login.Save();

            Login check = Login.OneWhere(c => c.Id == login.Id);

            Instant loginAt = new Instant(check.DateTime.Value);

            Expect.AreEqual(nowInstant, loginAt);
        }
Пример #16
0
        public void LoginShouldSetUserInCurrentHttpSession()
        {
            string       userName  = MethodBase.GetCurrentMethod().Name;
            UserManager  userProxy = new UserManager();
            IHttpContext context   = A.Fake <IHttpContext>();

            context.Request       = new TestRequest();
            userProxy.HttpContext = context;

            Session session = Session.Get(context);

            string passHash = "password".Sha1();
            string email    = "*****@*****.**";

            UserTestTools.EnsureUserNameAndEmailAreAvailable(userName, email);
            userProxy.SignUp(email, userName, passHash, false);
            LoginResponse result = userProxy.Login(userName, passHash);

            Expect.IsTrue(result.Success);

            string check = context.User.Identity.Name;

            Expect.AreEqual(userName, check);
        }
Пример #17
0
 public static void SignUp(string userName, out UserManager userProxy, out IHttpContext context, out string passHash)
 {
     UserTestTools.SignUp(userName, "*****@*****.**", out userProxy, out context, out passHash);
 }
Пример #18
0
 public void Setup()
 {
     UserTestTools.ClearAllUserInfo();
 }
Пример #19
0
 public void Teardown()
 {
     UserTestTools.ClearAllUserInfo();
 }