Наследование: System.MarshalByRefObject
 public static UserSession add_NewSession(this TMUser tmUser, string loginMethod = "Direct")
 {
     var userSession = new UserSession
     {
         SessionID    = Guid.NewGuid(),
         IpAddress    = HttpContextFactory.Request.ipAddress(),
         CreationDate = DateTime.Now,
         LoginMethod  = loginMethod
     };
     tmUser.Sessions.add(userSession);
     return userSession;
 }
Пример #2
0
 public static UserSession add_NewSession(this TMUser tmUser)
 {
     var ipAddress = HttpContextFactory.Context.ipAddress();
     var userSession = new UserSession
     {
         SessionID = Guid.NewGuid(),
         IpAddress = ipAddress,
         CreationDate = DateTime.Now
     };
     tmUser.Sessions.add(userSession);
     return userSession;
 }
 public static bool remove_Session(this TMUser tmUser, UserSession userSession)
 {
     if (userSession.isNull())
         return false;
     return tmUser.remove_Session(userSession.SessionID);
 }
Пример #4
0
        public void UserSession_Object()
        {
            userData.resetAllSessions();
            //test empty UserSession Object
            var userSession0 = new UserSession();
            Assert.AreEqual(userSession0.SessionID, Guid.Empty);
            Assert.AreEqual(userSession0.CreationDate, default(DateTime));
            Assert.IsNull  (userSession0.IpAddress);

            // temp user object
            var tmUser = new TMUser();

            //test expected values for 1st session
            var userSession1 = tmUser.add_NewSession();

            Assert.IsNotNull(userSession1, "New UserSession was null");
            Assert.AreNotEqual(userSession1.SessionID, Guid.Empty);
            Assert.AreNotEqual(userSession1.CreationDate, default(DateTime));
            Assert.IsNotNull  (userSession1.IpAddress);
            Assert.AreEqual   (tmUser.Sessions.size(), 1, "There should only be one sessions here");
            Assert.AreEqual   (tmUser.Sessions.first(), userSession1);

            //test expected values for 2nd session
            var userSession2 = tmUser.add_NewSession();

            Assert.IsNotNull  (userSession2, "New UserSession was null");
            Assert.AreNotEqual(userSession2.SessionID, Guid.Empty);
            Assert.AreNotEqual(userSession2.CreationDate, default(DateTime));
            Assert.IsNotNull  (userSession2.IpAddress);
            Assert.AreEqual   (tmUser.Sessions.size(), 2, "There should only be two sessions here");
            Assert.AreEqual   (tmUser.Sessions.second(), userSession2);
            Assert.AreNotEqual(userSession1, userSession2);

            Assert.AreEqual   (userData.validSessions().size(),0); // there should be no sessions here in global sessions handler since the user was created manually
        }