/// <summary>
 /// Asynchronously retrieves the named <see cref="SavedSearch"/>.
 /// </summary>
 /// <param name="name">
 /// Name of the <see cref="SavedSearch"/> to be retrieved.
 /// </param>
 /// <param name="args">
 /// Constrains the information returned about the <see cref=
 /// "SavedSearch"/>.
 /// </param>
 /// <remarks>
 /// This method uses the <a href="http://goo.gl/L4JLwn">GET 
 /// saved/searches/{name}</a> endpoint to get the <see cref=
 /// "SavedSearch"/> identified by <see cref="name"/>.
 /// </remarks>
 public async Task<SavedSearch> GetSavedSearchAsync(string name, SavedSearchFilterArgs args = null)
 {
     var resource = new SavedSearch(this.Context, this.Namespace, name);
     await resource.GetAsync(args);
     return resource;
 }
        public async Task SavedSearchesUpdateProperties()
        {
            using (var service = await SdkHelper.CreateService())
            {
                SavedSearchCollection savedSearches = service.SavedSearches;
                const string          name          = "sdk-test_UpdateProperties";
                const string          search        = "search index=sdk-tests * earliest=-1m";

                //// Ensure test starts in a known good state

                SavedSearch testSearch = await savedSearches.GetOrNullAsync(name);

                if (testSearch != null)
                {
                    await testSearch.RemoveAsync();
                }

                //// Create a saved search

                testSearch = await savedSearches.CreateAsync(name, search);

                testSearch = await savedSearches.GetOrNullAsync(name);

                Assert.NotNull(testSearch);

                //// Read the saved search

                await savedSearches.GetAllAsync();

                testSearch = savedSearches.SingleOrDefault(a => a.Name == name);
                Assert.True(testSearch.IsVisible);

                // CONSIDER: Test some additinal default property values.

                // Update search properties, but don't specify required args to test
                // pulling them from the existing object
                bool updatedSnapshot = await testSearch.UpdateAsync(new SavedSearchAttributes()
                {
                    IsVisible = false
                });

                Assert.True(updatedSnapshot);
                Assert.False(testSearch.IsVisible);

                // Delete the saved search
                await testSearch.RemoveAsync();

                testSearch = await savedSearches.GetOrNullAsync(testSearch.Name);

                Assert.Null(testSearch);

                // Create a saved search with some additional arguments
                testSearch = await savedSearches.CreateAsync(name, search, new SavedSearchAttributes()
                {
                    IsVisible = false
                });

                Assert.False(testSearch.IsVisible);

                // Set email param attributes

                var attributes = new SavedSearchAttributes()
                {
                    ActionEmailAuthPassword = "******",
                    ActionEmailAuthUsername = "******",
                    ActionEmailBcc          = "*****@*****.**",
                    ActionEmailCC           = "*****@*****.**",
                    ActionEmailCommand      = "$name1$",
                    ActionEmailFormat       = EmailFormat.Plain,
                    ActionEmailFrom         = "*****@*****.**",
                    //attrs.ActionEmailHostname = "dummy1.host.com",
                    ActionEmailInline                 = "true",
                    ActionEmailMailServer             = "splunk.com",
                    ActionEmailMaxResults             = 101,
                    ActionEmailMaxTime                = "10s",
                    ActionEmailSendPdf                = true, //??ActionEmailPdfView = "dummy",
                    ActionEmailSendResults            = true, //??ActionEmailPreProcessResults = "*",
                    ActionEmailReportPaperOrientation = PaperOrientation.Landscape,
                    ActionEmailReportPaperSize        = PaperSize.Letter,
                    ActionEmailReportServerEnabled    = false,
                    //attrs.ActionEmailReportServerUrl = "splunk.com",
                    ActionEmailSubject              = "sdk-subject",
                    ActionEmailTo                   = "*****@*****.**",
                    ActionEmailTrackAlert           = false,
                    ActionEmailTtl                  = "61",
                    ActionEmailUseSsl               = false,
                    ActionEmailUseTls               = false,
                    ActionEmailWidthSortColumns     = false,
                    ActionPopulateLookupCommand     = "$name2$",
                    ActionPopulateLookupDestination = "dummypath",
                    ActionPopulateLookupHostName    = "dummy2.host.com",
                    ActionPopulateLookupMaxResults  = 102,
                    ActionPopulateLookupMaxTime     = "20s",
                    ActionPopulateLookupTrackAlert  = false,
                    ActionPopulateLookupTtl         = "62",
                    ActionRssCommand                = "$name3$",
                    //attrs.ActionRssHostname = "dummy3.host.com",
                    ActionRssMaxResults       = 103,
                    ActionRssMaxTime          = "30s",
                    ActionRssTrackAlert       = "false",
                    ActionRssTtl              = "63",
                    ActionScriptCommand       = "$name4$",
                    ActionScriptFileName      = "action_script_filename",
                    ActionScriptHostName      = "dummy4.host.com",
                    ActionScriptMaxResults    = 104,
                    ActionScriptMaxTime       = "40s",
                    ActionScriptTrackAlert    = false,
                    ActionScriptTtl           = "64",
                    ActionSummaryIndexName    = "default",
                    ActionSummaryIndexCommand = "$name5$",
                    //attrs.ActionSummaryIndexHostname = "dummy5.host.com",
                    ActionSummaryIndexInline     = false,
                    ActionSummaryIndexMaxResults = 105,
                    ActionSummaryIndexMaxTime    = "50s",
                    ActionSummaryIndexTrackAlert = false,
                    ActionSummaryIndexTtl        = "65",
                    Actions = "rss,email,populate_lookup,script,summary_index"
                };

                await testSearch.UpdateAsync(attributes);

                // check

                Assert.True(testSearch.Actions.Email != null); //IsActionEmail));
                Assert.True(testSearch.Actions.PopulateLookup != null);
                Assert.True(testSearch.Actions.Rss != null);
                Assert.True(testSearch.Actions.Script != null);
                Assert.True(testSearch.Actions.SummaryIndex != null);

                Assert.Equal("sdk-password", testSearch.Actions.Email.AuthPassword);
                Assert.Equal("sdk-username", testSearch.Actions.Email.AuthUsername);
                Assert.Equal("*****@*****.**", testSearch.Actions.Email.Bcc);
                Assert.Equal("*****@*****.**", testSearch.Actions.Email.CC);
                Assert.Equal("$name1$", testSearch.Actions.Email.Command);
                Assert.Equal(EmailFormat.Plain, testSearch.Actions.Email.Format);
                Assert.Equal("*****@*****.**", testSearch.Actions.Email.From);
                //Assert.Equal("dummy1.host.com", savedSearch.Actions.Email.Hostname);
                Assert.True(testSearch.Actions.Email.Inline);
                //Assert.Equal("splunk.com", savedSearch.Actions.Email.MailServer);
                Assert.Equal(101, testSearch.Actions.Email.MaxResults);
                Assert.Equal("10s", testSearch.Actions.Email.MaxTime);
                //Assert.Equal("dummy", savedSearch.Actions.Email.PdfView);
                //Assert.Equal("*", savedSearch.Actions.Email.PreProcessResults);
                Assert.Equal(PaperOrientation.Landscape, testSearch.Actions.Email.ReportPaperOrientation);
                Assert.Equal(PaperSize.Letter, testSearch.Actions.Email.ReportPaperSize);
                Assert.False(testSearch.Actions.Email.ReportServerEnabled);
                //Assert.Equal("splunk.com", savedSearch.Actions.Email.ReportServerUrl);
                Assert.True(testSearch.Actions.Email.SendPdf);
                Assert.True(testSearch.Actions.Email.SendResults);
                Assert.Equal("sdk-subject", testSearch.Actions.Email.Subject);
                Assert.Equal("*****@*****.**", testSearch.Actions.Email.To);
                Assert.False(testSearch.Actions.Email.TrackAlert);
                Assert.Equal("61", testSearch.Actions.Email.Ttl);
                Assert.False(testSearch.Actions.Email.UseSsl);
                Assert.False(testSearch.Actions.Email.UseTls);
                Assert.False(testSearch.Actions.Email.WidthSortColumns);
                Assert.Equal("$name2$", testSearch.Actions.PopulateLookup.Command);
                Assert.Equal("dummypath", testSearch.Actions.PopulateLookup.Destination);
                Assert.Equal("dummy2.host.com", testSearch.Actions.PopulateLookup.Hostname);
                Assert.Equal(102, testSearch.Actions.PopulateLookup.MaxResults);
                Assert.Equal("20s", testSearch.Actions.PopulateLookup.MaxTime);
                Assert.False(testSearch.Actions.PopulateLookup.TrackAlert);
                Assert.Equal("62", testSearch.Actions.PopulateLookup.Ttl);
                Assert.Equal("$name3$", testSearch.Actions.Rss.Command);
                //Assert.Equal("dummy3.host.com", savedSearch.Actions.Rss.Hostname);
                Assert.Equal(103, testSearch.Actions.Rss.MaxResults);
                Assert.Equal("30s", testSearch.Actions.Rss.MaxTime);
                Assert.False(testSearch.Actions.Rss.TrackAlert);
                Assert.Equal("63", testSearch.Actions.Rss.Ttl);

                Assert.Equal("$name4$", testSearch.Actions.Script.Command);
                Assert.Equal("action_script_filename", testSearch.Actions.Script.FileName);
                Assert.Equal("dummy4.host.com", testSearch.Actions.Script.Hostname);
                Assert.Equal(104, testSearch.Actions.Script.MaxResults);
                Assert.Equal("40s", testSearch.Actions.Script.MaxTime);
                Assert.False(testSearch.Actions.Script.TrackAlert);
                Assert.Equal("64", testSearch.Actions.Script.Ttl);

                Assert.Equal("default", testSearch.Actions.SummaryIndex.Name);
                Assert.Equal("$name5$", testSearch.Actions.SummaryIndex.Command);
                //Assert.Equal("dummy5.host.com", savedSearch.Actions.SummaryIndex.Hostname);
                Assert.False(testSearch.Actions.SummaryIndex.Inline);
                Assert.Equal(105, testSearch.Actions.SummaryIndex.MaxResults);
                Assert.Equal("50s", testSearch.Actions.SummaryIndex.MaxTime);
                Assert.False(testSearch.Actions.SummaryIndex.TrackAlert);
                Assert.Equal("65", testSearch.Actions.SummaryIndex.Ttl);

                // Delete the saved search

                await testSearch.RemoveAsync();

                try
                {
                    await testSearch.GetAsync();

                    Assert.True(false);
                }
                catch (ResourceNotFoundException)
                { }

                testSearch = await savedSearches.GetOrNullAsync(testSearch.Name);

                Assert.Null(testSearch);
            }
        }