public Session UpdateExistingSession(Session session)
        {
            session.CreateDate = DateTime.Now;
            session.Name = Guid.NewGuid().ToString();

               return _db.UpdateSession(session);
        }
        public void GetUserSessionGetsANewSessionIfOneExistsButIsExpired()
        {
            var oldSession = new Session(1, "4D07565F-9B7E-444D-8E05-A056962D5C0C", 1, DateTime.Now.AddDays(-1));
            var goodSession = new Session(1, "F5AE412E-8FE0-46A5-8C31-9F4B1F45862A", 1, DateTime.Now);
            _db.Setup(x => x.GetExistingUserSession(It.IsAny<long>())).Returns(oldSession);
            _db.Setup(x => x.UpdateSession(It.IsAny<Session>())).Returns(goodSession);

            var session = _auth.GetUserSession(1);

            session.Should().Not.Be.Null();
            _db.Verify(x => x.UpdateSession(It.IsAny<Session>()), Times.Once());
        }
        public void GetUserSessionGetsANewSessionIfOneDoesntExist()
        {
            Session nullSession = null;
            var goodSession = new Session(1,"4D07565F-9B7E-444D-8E05-A056962D5C0C", 1, DateTime.Now);
            _db.Setup(x => x.GetExistingUserSession(It.IsAny<long>())).Returns(nullSession);
            _db.Setup(x => x.AddSession(It.IsAny<Session>())).Returns(goodSession);

            var session = _auth.GetUserSession(1);

            session.Should().Not.Be.Null();
            _db.Verify(x => x.AddSession(It.IsAny<Session>()), Times.Once());
        }
 public bool SessionExpired(Session session)
 {
     return (session.CreateDate < DateTime.Now.AddHours(-1));
 }
 public Session GetNewSession(long userID)
 {
     var session = new Session(-1, Guid.NewGuid().ToString(), userID, DateTime.Now);
     return _db.AddSession(session);
 }
        public void TestAuthenticateUser()
        {
            const string salt = "w2bWxJv9wmjyNp+NGUqtC6H/Ew2vscSNPuYNxxFP692oaYInrfEm1s4N0xXhYWvNukNTOo2iFHPxpp7a3uo+OLbaeDWPgYcfqaErkXK8tm6O4ocyJQ1qkEeX/9grw8e2xSiN+Mne+ispyU3P3o1yQneoXdyrVJ/G/DTb4xffMuI=";
               const  string encryptedPassword ="******";
            var mockedUser = new User(1, "testUser", encryptedPassword, "*****@*****.**", "test", "user", salt);

            var mockedSession = new Session(1, "4BB75EF2-1306-4C50-886A-AF79C9CEE2F4", 1, DateTime.Now);

            _db.Setup(x => x.GetUser(It.IsAny<string>())).Returns(mockedUser);
            _db.Setup(x => x.GetExistingUserSession(1)).Returns(mockedSession);

            var actualSessionToken = _auth.AuthenticateUser("testUser", "P@55w0rd");

            actualSessionToken.Should().Not.Be.NullOrEmpty();
        }