public void Setup()
 {
     ctx = new ViewstateContext();
     ctx.SetValue("test", "abc");
 }
        public void SaveState(ViewstateContext ctx, bool useGuid = true)
        {
            if ( !useGuid && string.IsNullOrWhiteSpace( ctx.Reference ) )
                useGuid = true;

            string query = useGuid ? SaveStateByGuidQuery : SaveStateByReferenceQuery;
            var args = ctx.GetDatebaseRow();

            SqlConnection conn = new SqlConnection(connectionstringProvider.Connectionstring);
            try
            {
                conn.Open();
                conn.ExecuteMapperCommand(query, args);
            }
            catch(Exception ex)
            {
                AnnotatedException e = new AnnotatedException("Error saving viewstate", ex);
                e.AddAnnotation("UseGuid", useGuid);
                e.AddAnnotation("Query", query);
                e.AddAnnotations(args);

                throw e;
            }
            finally
            {
                conn.Close();
            }
        }