Esempio n. 1
0
        public void SavedSearchHistory()
        {
            Service service = this.Connect();

            SavedSearchCollection savedSearches = service.GetSavedSearches();

            // Ensure test starts in a known good state
            if (savedSearches.ContainsKey("sdk-test1"))
            {
                savedSearches.Remove("sdk-test1");
            }

            Assert.IsFalse(savedSearches.ContainsKey("sdk-test1"), this.assertRoot + "#69");

            string search = "search index=sdk-tests * earliest=-1m";

            // Create a saved search
            SavedSearch savedSearch = savedSearches.Create("sdk test1", search);

            // Clear the history - even though we have a newly create saved search
            // its possible there was a previous saved search with the same name
            // that had a matching history.
            Job[] history = savedSearch.History();
            foreach (Job job in history)
            {
                job.Cancel();
            }

            history = savedSearch.History();
            Assert.AreEqual(0, history.Length, this.assertRoot + "#70");

            Job job1 = savedSearch.Dispatch();

            this.Ready(job1);
            history = savedSearch.History();
            Assert.AreEqual(1, history.Length, this.assertRoot + "#71");
            Assert.IsTrue(this.Contains(history, job1.Sid));

            Job job2 = savedSearch.Dispatch();

            this.Ready(job2);
            history = savedSearch.History();
            Assert.AreEqual(2, history.Length, this.assertRoot + "#72");
            Assert.IsTrue(this.Contains(history, job1.Sid), this.assertRoot + "#73");
            Assert.IsTrue(this.Contains(history, job2.Sid), this.assertRoot + "#74");

            job1.Cancel();
            history = savedSearch.History();
            Assert.AreEqual(1, history.Length, this.assertRoot + "#75");
            Assert.IsTrue(this.Contains(history, job2.Sid), this.assertRoot + "#76");

            job2.Cancel();
            history = savedSearch.History();
            Assert.AreEqual(0, history.Length, this.assertRoot + "#77");

            // Delete the saved search
            savedSearches.Remove("sdk test1");
            Assert.IsFalse(savedSearches.ContainsKey("sdk test1"), this.assertRoot + "#78");
        }