/////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>creates a number or rows </summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void DefaultHostInsertAndStay()
        {
            Tracing.TraceMsg("Entering DefaultHostInsertAndStay");

            int       iCount = 0;
            FeedQuery query  = new FeedQuery();

            Service service = new Service();

            service.RequestFactory = this.factory;

            query.Uri = new Uri(this.defaultHost);
            AtomFeed  returnFeed = service.Query(query);
            AtomEntry entry;


            iCount = returnFeed.Entries.Count;

            // now we have all we need.

            for (int i = 0; i < this.iIterations; i++)
            {
                Tracing.TraceMsg("DefaultHostInsertAndStay: inserting entry #: " + i);
                entry = ObjectModelHelper.CreateAtomEntry(i);
                entry = returnFeed.Insert(entry);
            }

            Tracing.TraceMsg("DefaultHostInsertAndStay: inserted lot's of  entries");
            // done doing the inserts...

            // now query the guy again.

            returnFeed = service.Query(query);
            Assert.AreEqual(iCount + this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now");
        }
        /////////////////////////////////////////////////////////////////////////////



        ////////////////////////////////////////////////////////////////////
        /// <summary>[Test] creates a new entry, saves and loads it back</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void CreateEmptyEntrySaveAndLoad()
        {
            Tracing.TraceMsg("Entering Create/Save/Load test");

            AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1);

            entry.Content.Type    = "text";
            entry.Content.Content = "";

            ObjectModelHelper.DumpAtomObject(entry, CreateDumpFileName("CreateEmptyEntrySaveAndLoad"));


            // let's try loading this...
            Service service = new Service();

            service.RequestFactory = this.factory;

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(CreateUriLogFileName("CreateEmptyEntrySaveAndLoad"));
            AtomFeed feed = service.Query(query);

            Assert.IsTrue(feed.Entries != null, "Feed.Entries should not be null");
            Assert.AreEqual(1, feed.Entries.Count, "Feed.Entries should have ONE element");
            // that feed should have ONE entry
            if (feed.Entries != null)
            {
                AtomEntry theOtherEntry = feed.Entries[0];
                Assert.IsTrue(ObjectModelHelper.IsEntryIdentical(entry, theOtherEntry), "Entries should be identical");
            }
        }
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>[Test] creates a new entry, saves and loads it back
        ///   uses HTML content to test the persistence/encoding code
        /// </summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void CreateHTMLEntrySaveAndLoad()
        {
            Tracing.TraceMsg("Entering CreateHTMLEntrySaveAndLoad");

            AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1);

            entry.Content.Type    = "html";
            entry.Content.Content = HttpUtility.HtmlDecode("<b>this is a &lt;test&gt;</b>");

            Tracing.TraceMsg("Content: " + entry.Content.Content);

            ObjectModelHelper.DumpAtomObject(entry, CreateDumpFileName("CreateHTMLEntrySaveAndLoad"));


            // let's try loading this...
            Service service = new Service();

            service.RequestFactory = this.factory;

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(CreateUriLogFileName("CreateHTMLEntrySaveAndLoad"));
            AtomFeed feed = service.Query(query);

            Assert.IsTrue(feed.Entries != null, "Feed.Entries should not be null");
            Assert.AreEqual(1, feed.Entries.Count, "Feed.Entries should have ONE element");
            // that feed should have ONE entry
            if (feed.Entries != null)
            {
                AtomEntry theOtherEntry = feed.Entries[0];
                Tracing.TraceMsg("Loaded Content: " + theOtherEntry.Content.Content);
                Assert.IsTrue(ObjectModelHelper.IsEntryIdentical(entry, theOtherEntry));
            }
        }
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>[Test] creates a new entry, saves and loads it back</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void DefaultHostInsertOneAndDelete()
        {
            Tracing.TraceMsg("Entering DefaultHostInsertOneAndDelete");
            AtomEntry entry   = ObjectModelHelper.CreateAtomEntry(1);
            Service   service = new Service();
            FeedQuery query   = new FeedQuery();

            service.RequestFactory = this.factory;

            int iCount = 0;

            string strTitle = "DefaultHostInsertOneAndDelete" + Guid.NewGuid().ToString();

            entry.Title.Text = strTitle;

            query.Uri = new Uri(this.defaultHost);
            AtomFeed returnFeed = service.Query(query);

            iCount = returnFeed.Entries.Count;


            for (int i = 0; i < this.iIterations; i++)
            {
                Tracing.TraceMsg("DefaultHostInsertOneAndDelete, iteration : " + i);

                Stream s = service.EntrySend(new Uri(this.defaultHost), entry, GDataRequestType.Insert);
                s.Close();

                returnFeed = service.Query(query);
                Assert.AreEqual(iCount + 1, returnFeed.Entries.Count, "feed should have one more entry now");

                AtomEntry returnEntry = null;

                foreach (AtomEntry feedEntry in returnFeed.Entries)
                {
                    if (String.Compare(feedEntry.Title.Text, strTitle) == 0)
                    {
                        // got him
                        returnEntry = feedEntry;
                        break;
                    }
                }

                Assert.IsTrue(returnEntry != null, "did not find the just inserted entry");

                returnEntry.Delete();

                // query again and check count

                returnFeed = service.Query(query);

                Assert.AreEqual(iCount, returnFeed.Entries.Count, "feed has different number of entries as expected");
            }
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>[Test] creates a new entry, saves and loads it back
        ///   uses XHTML content to test the persistence/encoding code
        /// </summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void CreateXHTMLEntrySaveAndLoad()
        {
            Tracing.TraceMsg("Entering CreateXHTMLEntrySaveAndLoad");

            AtomEntry entry = ObjectModelHelper.CreateAtomEntry(1);

            entry.Content.Type    = "xhtml";
            entry.Content.Content = HttpUtility.HtmlDecode("<div xmlns=\"http://www.w3.org/2005/Atom\"><b>this is a test</b></div>");

            Tracing.TraceMsg("Content: " + entry.Content.Content);

            ObjectModelHelper.DumpAtomObject(entry, CreateDumpFileName("CreateXHTMLEntrySaveAndLoad"));

            Tracing.TraceMsg("saved in... CreateXHTMLEntrySaveAndLoad");


            // let's try loading this...
            Service service = new Service();

            service.RequestFactory = this.factory;

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(CreateUriLogFileName("CreateXHTMLEntrySaveAndLoad"));
            AtomFeed feed = service.Query(query);

            Tracing.TraceMsg("loaded in... CreateXHTMLEntrySaveAndLoad");

            Assert.IsTrue(feed.Entries != null, "Feed.Entries should not be null");
            Assert.AreEqual(1, feed.Entries.Count, "Feed.Entries should have ONE element");


            // that feed should have ONE entry
            if (feed.Entries != null)
            {
                Tracing.TraceMsg("checking entries... CreateXHTMLEntrySaveAndLoad");
                AtomEntry theOtherEntry = feed.Entries[0];

                Assert.IsTrue(theOtherEntry.Content != null, "the entry should have a content element");
                Assert.IsTrue(theOtherEntry.Content.Type.Equals("xhtml"), "the entry should have a content element of type xhtml");
                Assert.IsTrue(theOtherEntry.Content.Content != null, "the entry should have a content element that is not empty");

                Tracing.TraceMsg("Loaded Content: " + theOtherEntry.Content.Content);
                Assert.IsTrue(ObjectModelHelper.IsEntryIdentical(entry, theOtherEntry));
                Tracing.TraceMsg("done comparing entries... CreateXHTMLEntrySaveAndLoad");
            }
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>creates X rows and updates it</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void DefaultHostMassiveInsertAndUpdate()
        {
            Tracing.TraceMsg("Entering DefaultHostMassiveInsertAndUpdate");

            int       iCount = 0;
            FeedQuery query  = new FeedQuery();

            Service service = new Service();

            service.RequestFactory = this.factory;

            query.Uri = new Uri(this.defaultHost);
            AtomFeed  returnFeed = service.Query(query);
            AtomEntry entry;


            iCount = returnFeed.Entries.Count;


            // now we have all we need.
            int z = 0;

            for (int i = 0; i < this.iIterations; i++)
            {
                z++;
                if (z > 500)
                {
                    z = 0;
                    // do a requery every hundreth to see mem usage
                    Tracing.TraceMsg("Query at point: " + i);
                    returnFeed = service.Query(query);
                }
                Tracing.TraceMsg("Inserting entry: " + i);
                entry = ObjectModelHelper.CreateAtomEntry(i);
                entry = returnFeed.Insert(entry);
                entry.Content.Content = "Updated entry: " + Guid.NewGuid().ToString();
                entry.Update();
            }

            // now query the guy again.
            returnFeed = service.Query(query);
            Assert.AreEqual(iCount + this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now");

            Tracing.TraceMsg("Exiting DefaultHostMassiveInsertAndUpdate");
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>[Test] creates a feed object from scratch</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void CreateFeed()
        {
            Tracing.TraceInfo("Entering Create Feed Test");
            AtomFeed feed = new AtomFeed(new Uri("http://dummy"), null);

            AtomEntry entry;

            for (int i = 1; i <= this.iIterations; i++)
            {
                entry = ObjectModelHelper.CreateAtomEntry(i);
                feed.Entries.Add(entry);
            }

            Tracing.TraceInfo("now persisting feed");

            ObjectModelHelper.DumpAtomObject(feed, CreateDumpFileName("CreateFeed"));

            Tracing.TraceInfo("now loadiing feed from disk");

            Service service = new Service();

            service.RequestFactory = this.factory;

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(CreateUriLogFileName("CreateFeed"));

            feed = service.Query(query);

            Assert.IsTrue(feed.Entries != null, "Feed.Entries should not be null");
            Assert.AreEqual(this.iIterations, feed.Entries.Count, "Feed.Entries should have 50 elements");
            if (feed.Entries != null)
            {
                for (int i = 1; i <= this.iIterations; i++)
                {
                    entry = ObjectModelHelper.CreateAtomEntry(i);
                    AtomEntry theOtherEntry = feed.Entries[i - 1];
                    Assert.IsTrue(ObjectModelHelper.IsEntryIdentical(entry, theOtherEntry));
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>creates a number or rows and delets them again</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void DefaultHostMassiveInsertAndDelete()
        {
            Tracing.TraceMsg("Entering DefaultHostMassiveInsertAndDelete");

            int       iCount = 0;
            FeedQuery query  = new FeedQuery();

            Service service = new Service();

            service.RequestFactory = this.factory;

            query.Uri = new Uri(this.defaultHost);
            AtomFeed  returnFeed = service.Query(query);
            AtomEntry entry;


            iCount = returnFeed.Entries.Count;

            AtomEntryCollection newEntries = new AtomEntryCollection(null);


            // now we have all we need.

            for (int i = 0; i < this.iIterations; i++)
            {
                entry = ObjectModelHelper.CreateAtomEntry(i);
                entry = returnFeed.Insert(entry);
                newEntries.Add(entry);
            }

            Tracing.TraceMsg("DefaultHostMassiveInsert: inserted lot's of  entries");
            // done doing the inserts...

            // now query the guy again.

            returnFeed = service.Query(query);
            Assert.AreEqual(iCount + this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now");

            // now udpate the 100 entries we have added

            for (int i = 0; i < this.iIterations; i++)
            {
                entry            = newEntries[i];
                entry.Title.Text = Guid.NewGuid().ToString();
                entry.Update();
            }
            Tracing.TraceMsg("DefaultHostMassiveInsert: updated lot's of entries");

            returnFeed = service.Query(query);
            Assert.AreEqual(iCount + this.iIterations, returnFeed.Entries.Count, "feed should have " + this.iIterations + " more entries now");

            // let's find them and delete them...
            for (int i = 0; i < this.iIterations; i++)
            {
                entry = newEntries[i];
                foreach (AtomEntry feedEntry in returnFeed.Entries)
                {
                    if (String.Compare(feedEntry.Title.Text, entry.Title.Text) == 0)
                    {
                        // got him
                        Tracing.TraceMsg("trying to delete entry: " + feedEntry.Title.Text + " = " + entry.Title.Text);
                        feedEntry.Delete();
                        break;
                    }
                }
            }


            // and a last time
            returnFeed = service.Query(query);
            Assert.AreEqual(iCount, returnFeed.Entries.Count, "feed should have the same number again");

            Tracing.TraceMsg("DefaultHostMassiveInsertAndDelete: deleted lot's of entries");
        }