public void TestDeleteItemByQueryWithSpacesOnlyInDatabaseReturnsException()
        {
            var exception = Assert.Throws <ArgumentException>(() => ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery("/sample query")
                                                              .Database("  "));

            Assert.AreEqual("DeleteItemItemByQueryRequestBuilder.Database : The input cannot be empty.", exception.Message);
        }
        private async void SendDeleteByQueryRequest()
        {
            try
            {
                using (var session = this.instanceSettings.GetSession())
                {
                    var request = ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery(this.itemQueryField.Text)
                                  .Build();

                    this.ShowLoader();

                    ScDeleteItemsResponse response = await session.DeleteItemAsync(request);

                    this.ProceedResponce(response);
                }
            }
            catch (Exception e)
            {
                AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
            }
            finally
            {
                BeginInvokeOnMainThread(delegate
                {
                    this.HideLoader();
                });
            }
        }
        private async void DeleteItemByQuery()
        {
            var itemQueryField = this.FindViewById <EditText>(Resource.Id.field_item_query);
            var itemQuery      = itemQueryField.Text;

            if (string.IsNullOrWhiteSpace(itemQuery))
            {
                Toast.MakeText(this, "Please enter query", ToastLength.Long).Show();
                return;
            }

            try
            {
                var request = ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery(itemQuery).Build();

                this.SetProgressBarIndeterminateVisibility(true);

                using (var session = this.prefs.Session)
                {
                    var response = await session.DeleteItemAsync(request);

                    this.SetProgressBarIndeterminateVisibility(false);

                    this.ShowResult(response);
                }
            }
            catch (System.Exception exception)
            {
                this.SetProgressBarIndeterminateVisibility(false);

                var title = this.GetString(Resource.String.text_error);
                DialogHelper.ShowSimpleDialog(this, title, exception.Message);
            }
        }
        public void TestDeleteItemByQueryWithNullScopeReturnsException()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery("sample query")
                                                                  .AddScope(null));

            Assert.IsTrue(exception.Message.Contains("DeleteItemItemByQueryRequestBuilder.Scope"));
        }
        public void TestDeleteItemByQueryWithTwoDatabasesReturnsException()
        {
            var exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery("sample query")
                                                                      .Database("1")
                                                                      .Database("2"));

            Assert.AreEqual("DeleteItemItemByQueryRequestBuilder.Database : Property cannot be assigned twice.", exception.Message);
        }
        private async Task <ScDeleteItemsResponse> DeleteAllItems(string database)
        {
            var deleteFromMaster = ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery(this.testData.Items.CreateItemsHere.Path)
                                   .AddScope(ScopeType.Children)
                                   .Database(database)
                                   .Build();

            return(await this.noThrowCleanupSession.DeleteItemAsync(deleteFromMaster));
        }
        public async void TestDeleteInternationalItemWithSpacesInNameByQuery()
        {
            await this.RemoveAll();

            ISitecoreItem item1 = await this.CreateItem("International בינלאומי");

            ISitecoreItem item2 = await this.CreateItem("インターナショナル عالمي");

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery(testData.Items.CreateItemsHere.Path + "/*")
                          .Build();

            var result = await this.session.DeleteItemAsync(request);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(item1.Id, result[0]);
            Assert.AreEqual(item2.Id, result[1]);
        }
        public async void TestDeleteItemByQueryWithChildrenAndSelfScope()
        {
            await this.RemoveAll();

            ISitecoreItem parentItem = await this.CreateItem("Parent item");

            ISitecoreItem selfItem = await this.CreateItem("Self item", parentItem);

            await this.CreateItem("Child item", selfItem);

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery(testData.Items.CreateItemsHere.Path + "/descendant::*[@@templatename='Sample Item']")
                          .AddScope(ScopeType.Children)
                          .AddScope(ScopeType.Self)
                          .Build();

            var result = await this.session.DeleteItemAsync(request);

            Assert.AreEqual(5, result.Count); //but 3 items was deleted in fact (Item Web API issue)
        }
        public async void TestCreateGetAndDelete100ItemsByQuery()
        {
            await this.RemoveAll();

            for (int i = 0; i < 100; i++)
            {
                await this.CreateItem("Test item " + (i + 1));
            }

            var query = testData.Items.CreateItemsHere.Path + "/descendant::*[@@templatename='Sample Item']";

            var readRequest = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(query).PageNumber(0).ItemsPerPage(100).Build();
            var readResult  = await this.session.ReadItemAsync(readRequest);

            testData.AssertItemsCount(100, readResult);

            var deleteRequest = ItemWebApiRequestBuilder.DeleteItemRequestWithSitecoreQuery(query).Build();
            var deleteResult  = await this.session.DeleteItemAsync(deleteRequest);

            Assert.AreEqual(100, deleteResult.Count);
        }