private async void DeleteItemByPath()
        {
            var itemPathField = this.FindViewById <EditText>(Resource.Id.field_item_path);
            var itempath      = itemPathField.Text;

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

            try
            {
                var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(itempath).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);
            }
        }
        private async void SendDeleteByPathRequest()
        {
            try
            {
                using (var session = this.instanceSettings.GetSession())
                {
                    var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(this.itemPathField.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();
                });
            }
        }
        public async void TestDeleteItemByPathWithoutDeleteAccessReturnsException()
        {
            await this.RemoveAll();

            var noAccessSession = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
                                  .Credentials(testData.Users.NoCreateAccess)
                                  .DefaultDatabase("master")
                                  .Site(testData.ShellSite)
                                  .BuildSession();

            ISitecoreItem item = await this.CreateItem("Item to delete without delete access");

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(item.Path)
                          .Build();

            TestDelegate testCode = async() =>
            {
                var   task = noAccessSession.DeleteItemAsync(request);
                await task;
            };
            Exception exception = Assert.Throws <ParserException>(testCode);

            Assert.AreEqual("[Sitecore Mobile SDK] Data from the internet has unexpected format", exception.Message);
            Assert.AreEqual("Sitecore.MobileSDK.API.Exceptions.WebApiJsonErrorException", exception.InnerException.GetType().ToString());
            Assert.True(exception.InnerException.Message.Contains("DeleteItem - Delete right required"));

            await session.DeleteItemAsync(request);
        }
        public async void TestDeleteItemByIdAsAnonymousFromShellSiteReturnsException()
        {
            await this.RemoveAll();

            var anonymousSession = SitecoreWebApiSessionBuilder.AnonymousSessionWithHost(testData.InstanceUrl)
                                   .DefaultDatabase("master")
                                   .Site(testData.ShellSite)
                                   .BuildSession();

            ISitecoreItem item = await this.CreateItem("Item to delete as anonymous");

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(item.Path)
                          .Build();

            TestDelegate testCode = async() =>
            {
                var   task = anonymousSession.DeleteItemAsync(request);
                await task;
            };
            Exception exception = Assert.Throws <ParserException>(testCode);

            Assert.AreEqual("[Sitecore Mobile SDK] Data from the internet has unexpected format", exception.Message);
            Assert.AreEqual("Sitecore.MobileSDK.API.Exceptions.WebApiJsonErrorException", exception.InnerException.GetType().ToString());
            Assert.AreEqual("Access to site is not granted.", exception.InnerException.Message);

            await session.DeleteItemAsync(request);
        }
        public void TestDeleteItemByPathWithNullDatabaseDoNotReturnsException()
        {
            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath("/sample path")
                          .Database(null)
                          .Build();

            Assert.IsNotNull(request);
        }
        public async void TestDeleteItemByNotExistentPath()
        {
            await this.RemoveAll();

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(testData.Items.CreateItemsHere.Path + "/not existent item")
                          .Build();

            var response = await session.DeleteItemAsync(request);

            Assert.AreEqual(0, response.Count);
        }
        public async void TestDeleteInternationalItemByPathbWithChildrenScope()
        {
            await this.RemoveAll();

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

            ISitecoreItem childItem = await this.CreateItem("インターナショナル", selfItem);

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(selfItem.Path)
                          .AddScope(ScopeType.Children)
                          .Build();

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

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(childItem.Id, result[0]);
        }
        public async void TestDeleteItemByIdWithParentScope()
        {
            await this.RemoveAll();

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

            ISitecoreItem childItem = await this.CreateItem("Child item", parentItem);

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(childItem.Path)
                          .AddScope(ScopeType.Parent)
                          .Build();

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

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(parentItem.Id, result[0]);
        }
        public async void TestDeleteItemByPathWithDb()
        {
            await this.RemoveAll();

            const string Db          = "web";
            var          itemSession = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
                                       .Credentials(testData.Users.Admin)
                                       .Site(testData.ShellSite)
                                       .DefaultDatabase(Db)
                                       .BuildSession();
            ISitecoreItem item = await this.CreateItem("Item in web", null, itemSession);

            var request = ItemWebApiRequestBuilder.DeleteItemRequestWithPath(item.Path)
                          .Database(Db)
                          .Build();

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

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(item.Id, result[0]);
        }
        public void TestDeleteItemByPathWithSpacesOnlyReturnsException()
        {
            var exception = Assert.Throws <ArgumentException>(() => ItemWebApiRequestBuilder.DeleteItemRequestWithPath(" "));

            Assert.AreEqual("DeleteItemItemByPathRequestBuilder.ItemPath : The input cannot be empty.", exception.Message);
        }
        public void TestDeleteItemWithInvalidPathReturnsException()
        {
            var exception = Assert.Throws <ArgumentException>(() => ItemWebApiRequestBuilder.DeleteItemRequestWithPath("invalid path )"));

            Assert.AreEqual("DeleteItemItemByPathRequestBuilder.ItemPath : should begin with '/'", exception.Message);
        }