/// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="reason"></param>
        /// <param name="termsLists"></param>
        /// <returns></returns>
        private TermsLists ValidateHistory(DnaTestURLRequest request, string reason, TermsLists termsLists)
        {
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader(""))
            {
                foreach (var termsList in termsLists.Termslist)
                {
                    foreach(var term in termsList.Terms)
                    {
                        reader.ExecuteDEBUGONLY("select id from termslookup where term='" + term.Value + "'");
                        if (reader.Read())
                        {
                            term.Id = reader.GetInt32NullAsZero("id");
                        }
                        Assert.AreNotEqual(0, term.Id);
                    }
                }

                var historyId = 0;
                reader.ExecuteDEBUGONLY("select top 1 * from TermsUpdateHistory order by updatedate desc");
                if (reader.Read())
                {
                    historyId = reader.GetInt32NullAsZero("id");
                    Assert.AreNotEqual(0, historyId);
                    Assert.AreEqual(reason, reader.GetStringNullAsEmpty("notes"));
                    Assert.AreEqual(request.CurrentUserID, reader.GetInt32NullAsZero("userid"));
                }


                var termsListsClone = (TermsLists)termsLists.Clone();
                reader.ExecuteDEBUGONLY("select * from TermsByModClassHistory where updateid=" + historyId + " order by modclassid");
                while (reader.Read())
                {
                    //remove items from lists if in db
                    var termsListFound = 
                        termsListsClone.Termslist.FirstOrDefault(x => x.ModClassId == reader.GetInt32NullAsZero("modclassid"));

                    Assert.IsNotNull(termsListFound);
                    var termFound = termsListFound.Terms.FirstOrDefault(x => x.Id == reader.GetInt32NullAsZero("termid")
                        && (byte)x.Action == reader.GetTinyIntAsInt("actionid"));

                    Assert.IsTrue(termsListFound.Terms.Remove(termFound));

                    if(termsListFound.Terms.Count == 0)
                    {
                        Assert.IsTrue(termsListsClone.Termslist.Remove(termsListFound));
                    }

                }
                Assert.AreEqual(0, termsListsClone.Termslist.Count);

            }
            return termsLists;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="termsLists"></param>
        private void ValidateTermAssociations(DnaTestURLRequest request, TermsLists termsLists)
        {
            XmlDocument doc;
            var termIds = new List<int>();
            foreach (var tmpList in termsLists.Termslist)
            {
                termIds.AddRange(tmpList.Terms.Select(term => term.Id));
            }
            //strip duplicates
            termIds = termIds.Distinct().ToList();


            //check the term association
            foreach (var id in termIds)
            {
                var termsListsClone = (TermsLists)termsLists.Clone();
                termsListsClone.FilterListByTermId(id);
                request.RequestPage(String.Format("termsfilterimport?s_termid={0}&skin=purexml&ignorecache=1", id));
                doc = request.GetLastResponseAsXML();

                ValidateResponse(request);

                var termsListNodes = doc.SelectNodes("//H2G2/TERMSLISTS/TERMSLIST");
                Assert.IsNotNull(termsListNodes);
                foreach(XmlNode termsListNode in termsListNodes)
                {
                    var termsList =
                        termsListsClone.Termslist.FirstOrDefault(
                            x => x.ModClassId == Int32.Parse(termsListNode.Attributes["MODCLASSID"].Value));
                    Assert.IsNotNull(termsList);
                    Assert.AreEqual(id, termsList.Terms[0].Id);

                    termsListsClone.Termslist.Remove(termsList);
                }
                //check if all elements removed
                Assert.AreEqual(0, termsListsClone.Termslist.Count);
            }
        }