public void Data_Read_Session()
        {
            var repository = new SessionRepository(_dataConnectionString, 1);

            var data = repository.Get(1);

            Assert.IsTrue(data.SessionID == 1);
            Assert.IsTrue(data.Key == "USER1SESSION");
        }
        public void Data_Read_Other_User_Session()
        {
            var repository = new SessionRepository(_dataConnectionString, 1);

            var data = repository.Get(4);

            Assert.IsTrue(data == null);
        }
        public void Data_Delete_Session_By_Key()
        {
            var repository = new SessionRepository(_dataConnectionString, 1);

            var result = repository.DeleteByKey("USER1SESSION");

            var session = repository.Get(1);

            Assert.IsTrue(session == null);
            Assert.IsTrue(result.Deleted == true);
            Assert.IsTrue(result.DeletedBy == 1);
            Assert.IsTrue(result.DeletedDate.Value.Date == DateTime.Now.Date);
        }
        public void Data_Delete_Session_Expired()
        {
            var repository = new SessionRepository(_dataConnectionString, 1);

            repository.DeleteExpired();

            var session = repository.Get(2);

            Assert.IsTrue(session == null);

            // Read the database directly and check the expired session is now marked as deleted
            using (var conn = new SqlConnection(_dataConnectionString))
            {
                conn.Open();

                var expiredSession = conn.Query<Session>("SELECT * FROM [dbo].[Sessions] WHERE [Key] = 'USER1SESSIONEXPIRED'").Single();

                Assert.IsTrue(expiredSession.Deleted == true);
                Assert.IsTrue(expiredSession.DeletedBy == 1);
                Assert.IsTrue(expiredSession.DeletedDate.Value.Date == DateTime.Now.Date);
            }
        }
        public void Data_Update_Session()
        {
            var repository = new SessionRepository(_dataConnectionString, 1);

            var session = repository.Get(1);

            session.Key = "UPDATED";
            session.Expiry = new DateTime(2020, 2, 2);

            var result = repository.Update(session);

            Assert.IsTrue(result.Key == "UPDATED");
            Assert.IsTrue(result.Expiry.Date == new DateTime(2020, 2, 2).Date);
            Assert.IsTrue(result.LastModifiedBy == 1);
            Assert.IsTrue(result.LastModifiedDate.Date == DateTime.Now.Date);
        }