Inheritance: System.MarshalByRefObject
コード例 #1
0
 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;
 }
コード例 #3
0
 public static bool remove_Session(this TMUser tmUser, UserSession userSession)
 {
     if (userSession.isNull())
         return false;
     return tmUser.remove_Session(userSession.SessionID);
 }
コード例 #4
0
ファイル: Test_Users_Sessions.cs プロジェクト: roman87/Dev
        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
        }