public void TestSitecoreQueryRequestBuilderWithAllFields()
        {
            IReadItemsByQueryRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("fast:/sitecore/content/HOME/*")
                                              .Database("core")
                                              .Language("de")

                                              // @adk : does not compile by design
                                              //        .Version("341")
                                              .Build();


            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ItemSource);
            Assert.IsNotNull(result.SitecoreQuery);
            Assert.IsNotNull(result.QueryParameters);
            Assert.IsNull(result.SessionSettings);

            Assert.AreEqual("fast:/sitecore/content/HOME/*", result.SitecoreQuery);
            Assert.AreEqual("de", result.ItemSource.Language);
            Assert.AreEqual("core", result.ItemSource.Database);

//      Assert.AreEqual("341", result.ItemSource.VersionNumber);
            Assert.IsNull(result.ItemSource.VersionNumber);

            Assert.IsNull(result.QueryParameters.Payload);
        }
Esempio n. 2
0
        private async Task <ScItemsResponse> GetItemByQuery(string query)
        {
            var request  = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(query).Build();
            var response = await this.sessionAuthenticatedUser.ReadItemAsync(request);

            return(response);
        }
        private async void SendRequest()
        {
            try
            {
                using (ISitecoreWebApiSession session = this.instanceSettings.GetSession())
                {
                    var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(queryTextField.Text)
                                  .Build();

                    this.ShowLoader();

                    ScItemsResponse response = await session.ReadItemAsync(request);

                    this.HideLoader();
                    if (response.ResultCount > 0)
                    {
                        this.ShowItemsList(response);
                    }
                    else
                    {
                        AlertHelper.ShowLocalizedAlertWithOkOption("Message", "Item is not exist");
                    }
                }
            }
            catch (Exception e)
            {
                this.HideLoader();
                AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
            }
        }
Esempio n. 4
0
        private async void PerformGetItemRequest(string query)
        {
            try
            {
                var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(query).Build();
                this.SetProgressBarIndeterminateVisibility(true);

                using (var session = this.Prefs.Session)
                {
                    var response = await session.ReadItemAsync(request);

                    if (response.ResultCount == 0)
                    {
                        DialogHelper.ShowSimpleDialog(this, Resource.String.text_item_received, Resource.String.text_no_item);
                    }
                    else
                    {
                        this.PopulateItemsList(response);
                    }
                }

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

                var title = this.GetString(Resource.String.text_error);
                DialogHelper.ShowSimpleDialog(this, title, exception.Message);
            }
        }
 public void TestDatabaseCannotBeAssignedTwice()
 {
     Assert.Throws <InvalidOperationException>(() =>
                                               ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/pppp/sss/*")
                                               .Database("master")
                                               .Database("web")
                                               );
 }
Esempio n. 6
0
        public async void TestGetItemInRequestByQueryAsConcatenationString()
        {
            var requestBuilder = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.Home.Path + "/*");
            var request        = requestBuilder.Database("master").Build();
            var response       = await this.sessionAuthenticatedUser.ReadItemAsync(request);

            this.testData.AssertItemsCount(4, response);
        }
        public void TestNullLanguageCanBeAssignedExplicitly()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/pppp/sss/*")
                          .Language(null)
                          .Build();

            Assert.IsNotNull(request);
        }
        public void TestGetItemWithSpacesInDatabaseInRequestByQueryReturnsException()
        {
            Exception exception = Assert.Throws <ArgumentException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.Home.Id)
                                                                    .Database(" 	")
                                                                    .Build());

            Assert.AreEqual("ReadItemByQueryRequestBuilder.Database : The input cannot be empty.", exception.Message);
        }
        public void TestGetItemWithEmpryLanguageInRequestByQueryDoNotReturnsException()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.Home.Id)
                          .Language("")
                          .Build();

            Assert.IsNotNull(request);
        }
        public void TestGetItemByQueryDuplicateScopeParamsReturnsException()
        {
            Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.Home.Path)
                                                                            .AddScope(ScopeType.Children, ScopeType.Self, ScopeType.Children)
                                                                            .Build());

            Assert.AreEqual("ReadItemByQueryRequestBuilder.Scope : Adding scope parameter duplicates is forbidden", exception.Message);
        }
Esempio n. 11
0
        public async void TestGetItemByQueryWithNotCorrectField()
        {
            var requestBuilder = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content//*[@Title='DANISH version 2 web']");
            var request        = requestBuilder.Language("da").Database("master").Build();
            var response       = await sessionAuthenticatedUser.ReadItemAsync(request);

            testData.AssertItemsCount(0, response);
        }
Esempio n. 12
0
        public void TestGetItemByQueryWithOverridenPayloadReturnsException()
        {
            Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.Home.Path)
                                                                            .Payload(PayloadType.Content)
                                                                            .Payload(PayloadType.Content)
                                                                            .Build());

            Assert.AreEqual("ReadItemByQueryRequestBuilder.Payload : Property cannot be assigned twice.", exception.Message);
        }
Esempio n. 13
0
        public void TestPagingSettingsUsedForOmittedScopeAndSingleItemResponse()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/x/y/z/*")
                          .PageNumber(44)
                          .ItemsPerPage(5)
                          .Build();

            Assert.AreEqual(44, request.PagingSettings.PageNumber);
            Assert.AreEqual(5, request.PagingSettings.ItemsPerPageCount);
        }
        public async void TestGetItemWithChildrenScopeByQuery()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(this.testData.Items.AllowedItem.Path)
                          .AddScope(ScopeType.Children)
                          .Build();
            var response = await this.session.ReadItemAsync(request);

            testData.AssertItemsCount(2, response);
            Assert.AreEqual("Allowed_Child", response[0].DisplayName);
            Assert.AreEqual("Not_Allowed_Child", response[1].DisplayName);
        }
Esempio n. 15
0
        public async void TestGetItemByQueryWithContentFields()
        {
            var request  = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/Home/ancestor-or-self::*").Payload(PayloadType.Content).Build();
            var response = await this.sessionAuthenticatedUser.ReadItemAsync(request);

            testData.AssertItemsCount(3, response);
            testData.AssertItemsAreEqual(testData.Items.Home, response[0]);
            ISitecoreItem item = response[0];

            Assert.AreEqual(2, item.FieldsCount);
            Assert.AreEqual("Sitecore", item["Title"].RawValue);
        }
Esempio n. 16
0
        public async void TestGetItemByQueryWithCorrectField()
        {
            var requestBuilder = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore//*[@Title='English version 2 web']");
            var request        = requestBuilder.Payload(PayloadType.Content).Build();
            var response       = await sessionAuthenticatedUser.ReadItemAsync(request);

            testData.AssertItemsCount(1, response);
            var resultItem     = response[0];
            var expectedSource = new ItemSource(LegacyConstants.DefaultSource().Database, LegacyConstants.DefaultSource().Language, 2);

            testData.AssertItemsAreEqual(testData.Items.ItemWithVersions, resultItem);
            testData.AssertItemSourcesAreEqual(expectedSource, resultItem.Source);
        }
        public async void TestGetItemWithChildrenScopeByQueryWithSpecifiedFields()    //children in name
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/Home/descendant::*[@title='Allowed_Item']")
                          .AddScope(ScopeType.Children)
                          .Language("en")
                          .AddScope(ScopeType.Self)
                          .Build();
            var response = await this.session.ReadItemAsync(request);

            testData.AssertItemsCount(6, response);
            Assert.AreEqual("Allowed_Child", response[0].DisplayName);
            Assert.AreEqual("Not_Allowed_Child", response[1].DisplayName);
            Assert.AreEqual("Allowed_Item", response[2].DisplayName);
        }
        public async void TestGetPage0WithSize3ByQuery()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/Home/*")
                          .AddScope(ScopeType.Self)
                          .PageNumber(0)
                          .ItemsPerPage(3)
                          .Build();

            ScItemsResponse response = await this.session.ReadItemAsync(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(3, response.ResultCount);
            Assert.AreEqual(4, response.TotalCount);
        }
        public async void TestGetItemWithSelfScopeByQuery()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(this.testData.Items.Home.Path)
                          .AddScope(ScopeType.Self)
                          .Build();
            var response = await this.session.ReadItemAsync(request);

            testData.AssertItemsCount(1, response);
            var resultItem = response[0];

            testData.AssertItemsAreEqual(testData.Items.Home, resultItem);
            Assert.AreEqual(2, resultItem.FieldsCount);
            Assert.AreEqual("Sitecore", resultItem["Title"].RawValue);
        }
        public async void TestGetItemWithChildrenAndSelfAndParentScopeByQuery()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/Home/Allowed_Parent/Allowed_Item/ancestor-or-self::*")
                          .AddScope(ScopeType.Children, ScopeType.Self, ScopeType.Parent)
                          .Language("en")
                          .Payload(PayloadType.Content)
                          .Build();
            var response = await this.session.ReadItemAsync(request);

            testData.AssertItemsCount(28, response);
            Assert.AreEqual("Allowed_Child", response[0].DisplayName);
            Assert.AreEqual("Not_Allowed_Child", response[1].DisplayName);
            Assert.AreEqual("Allowed_Item", response[2].DisplayName);
            Assert.AreEqual("Allowed_Parent", response[3].DisplayName);
        }
Esempio n. 21
0
        public void TestCancelExceptionIsNotWrappedForItemByQueryRequest()
        {
            TestDelegate testAction = async() =>
            {
                var cancel  = new CancellationTokenSource();
                var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/home/*").Build();

                Task <ScItemsResponse> action = this.session.ReadItemAsync(request, cancel.Token);
                cancel.Cancel();

                await action;
            };

            Assert.Catch <OperationCanceledException>(testAction);
        }
        public void TestOptionalSourceInSessionAndUserRequest()
        {
            var connection = new SessionConfig("localhost");

            var request       = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/home/*").Build();
            var requestMerger = new UserRequestMerger(connection, null);
            var mergedRequest = requestMerger.FillReadItemByQueryGaps(request);

            var urlBuilder = new ItemByQueryUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

            string result   = urlBuilder.GetUrlForRequest(mergedRequest);
            string expected = "http://localhost/-/item/v1?query=%2fsitecore%2fcontent%2fhome%2f%2a";

            Assert.AreEqual(expected, result);
        }
Esempio n. 23
0
        public async void TestOverrideLanguageInRequestByQuery()
        {
            const string Language = "da";

            var requestBuilder = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/Home/*");
            var request        = requestBuilder
                                 .Language(Language)
                                 .Build();
            var response = await sessionAuthenticatedUser.ReadItemAsync(request);

            testData.AssertItemsCount(4, response);
            var resultItem     = response[3];
            var expectedSource = new ItemSource(LegacyConstants.DefaultSource().Database, Language, 1);

            testData.AssertItemSourcesAreEqual(expectedSource, resultItem.Source);
        }
        public void TestQueryRequestBuilderWithQueryOnly()
        {
            IReadItemsByQueryRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("sitecore/content/HOME/*").Build();

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ItemSource);
            Assert.IsNotNull(result.SitecoreQuery);
            Assert.IsNotNull(result.QueryParameters);
            Assert.IsNull(result.SessionSettings);

            Assert.AreEqual("sitecore/content/HOME/*", result.SitecoreQuery);
            Assert.IsNull(result.QueryParameters.Payload);

            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
        }
        public void TestDatabaseAndExplicitLanguageAndPayload()
        {
            var connection = new SessionConfig("localhost");

            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/home/*")
                          .Language("da")
                          .Payload(PayloadType.Content)
                          .Build();
            var requestMerger = new UserRequestMerger(connection, null);
            var mergedRequest = requestMerger.FillReadItemByQueryGaps(request);

            var urlBuilder = new ItemByQueryUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

            string result   = urlBuilder.GetUrlForRequest(mergedRequest);
            string expected = "http://localhost/-/item/v1?language=da&payload=content&query=%2fsitecore%2fcontent%2fhome%2f%2a";

            Assert.AreEqual(expected, result);
        }
Esempio n. 26
0
        public async void TestGetEmptyField()
        {
            var fields = new Collection <string>
            {
                "",
            };

            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.TestFieldsItem.Path)
                          .AddFieldsToRead(fields)
                          .Payload(PayloadType.Default)
                          .Build();

            var response = await this.sessionAuthenticatedUser.ReadItemAsync(request);

            testData.AssertItemsCount(1, response);
            testData.AssertItemsAreEqual(testData.Items.TestFieldsItem, response[0]);
            Assert.AreEqual(0, response[0].FieldsCount);
        }
Esempio n. 27
0
        public async void TestWithHttpInUrlAndWithOneSlashInTheEndByQuery()
        {
            var urlWithOneSlash = testData.InstanceUrl + "/";
            var url             = urlWithOneSlash;

            using
            (
                var session =
                    SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(url)
                    .Credentials(this.testData.Users.Admin)
                    .BuildReadonlySession()
            )
            {
                var requestWithItemQuery = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(this.testData.Items.Home.Path).Payload(PayloadType.Content).Build();
                var response             = await session.ReadItemAsync(requestWithItemQuery);

                testData.AssertItemsCount(1, response);
                testData.AssertItemsAreEqual(testData.Items.Home, response[0]);
            }
        }
        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);
        }
Esempio n. 29
0
        public static async Task <ObservableCollection <WorkflowContentItem> > GetContentItemsInWorkflowState(WorkflowState workflowState)
        {
            var contentItems = new ObservableCollection <WorkflowContentItem> ();

            using (var session = CreateBaseSession().BuildSession()) {
                var request = ItemWebApiRequestBuilder
                              .ReadItemsRequestWithSitecoreQuery("/sitecore//*[@#__Workflow state# = '" + workflowState.Id + "']")
                              .Build();

                var results = await session.ReadItemAsync(request);

                foreach (var result in results)
                {
                    contentItems.Add(new WorkflowContentItem(result)
                    {
                        CurrentWorkflowState = workflowState
                    });
                }
            }

            return(contentItems);
        }
Esempio n. 30
0
        public void TestCancelGetItemByQuery()
        {
            var             request     = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(testData.Items.Home.Path).Build();
            var             cancelToken = CreateCancelTokenWithDelay(10);
            ScItemsResponse response    = null;

            TestDelegate testCode = async() =>
            {
                var task = session.ReadItemAsync(request, cancelToken);
                response = await task;
            };
            var exception = Assert.Catch <OperationCanceledException>(testCode);

            Assert.IsNull(response);

            //      Desktop (Windows) : "A task was canceled."
            //      iOS               : "The Task was canceled"
            Assert.IsTrue(exception.Message.ToLowerInvariant().Contains("task was canceled"));

            // @adk : CancellationToken class comparison or scheduling works differently on iOS
            // Assert.AreEqual(cancelToken, exception.CancellationToken);
        }