Пример #1
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");
        }
Пример #2
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);
        }
Пример #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
        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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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");
        }
Пример #9
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);
        }
Пример #10
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");
        }
Пример #11
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);
        }