public void TestMultipleItemFieldsCanBeAddedByAnyCollection()
        {
            string[]      fields         = { "Мама", "Мыла", "Раму" };
            string[]      moarFields     = { "1", "2", "4" };
            List <string> moarFieldsList = new List <string>(moarFields);

            string[] expectedFields = { "Мама", "Мыла", "Раму", "1", "2", "4" };

            IReadItemsByIdRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}")
                                           .AddFieldsToRead(fields)
                                           .AddFieldsToRead(moarFieldsList)
                                           .Build();

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



            Assert.AreEqual("{dead-c0de}", result.ItemId);
            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
            Assert.IsNull(result.QueryParameters.Payload);
            Assert.AreEqual(expectedFields, result.QueryParameters.Fields);
        }
Esempio n. 2
0
        private async Task <ScItemsResponse> GetItemByIdWithItemSource(ItemSource itemSource)
        {
            var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
                          .Credentials(testData.Users.Admin)
                          .DefaultLanguage(itemSource.Language)
                          .DefaultDatabase(itemSource.Database)
                          .BuildReadonlySession();

            IReadItemsByIdRequest request = null;

            if (null == itemSource.VersionNumber)
            {
                request = this.requestWithItemId;
            }
            else
            {
                request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
                          .Payload(PayloadType.Content)
                          .Version(itemSource.VersionNumber.Value)
                          .Build();
            }

            var response = await session.ReadItemAsync(request);

            return(response);
        }
Esempio n. 3
0
        public async void TestWithHttpsInUrlById()
        {
            var url = "https://scmobileteam.sitecoretest.net";

            // @adk : inlined due to
            //
            // Failed UrlAutocompleteTest.TestWithHttpsInUrlById
            //
            // MESSAGE:
            // System.Threading.Tasks.TaskCanceledException : A task was canceled.
            // +++++++++++++++++++
            // STACK TRACE:
            //    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            //    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
            //    at Sitecore.MobileSDK.ScApiSession.<ReadItemAsync>d__a.MoveNext() in c:\dev\Jenkins\jobs\XamarinSDK-FullBuild\workspace\lib\SitecoreMobileSDK-PCL\ScApiSession.cs:line 215
            using
            (
                var session =
                    SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(url)
                    .Credentials(this.testData.Users.Admin)
                    .BuildReadonlySession()
            )
            {
                var requestWithItemId = ItemWebApiRequestBuilder.ReadItemsRequestWithId(this.testData.Items.Home.Id).Payload(PayloadType.Content).Build();
                var response          = await session.ReadItemAsync(requestWithItemId);

                testData.AssertItemsCount(1, response);
                testData.AssertItemsAreEqual(testData.Items.Home, response[0]);
            }
        }
Esempio n. 4
0
        private async Task <ScItemsResponse> GetItemById(string id)
        {
            var request  = ItemWebApiRequestBuilder.ReadItemsRequestWithId(id).Build();
            var response = await this.sessionAuthenticatedUser.ReadItemAsync(request);

            return(response);
        }
Esempio n. 5
0
        public void TestCancelGetItemById()
        {
            using (new FunctionTracer("CancelOperationsTest->TestCancelGetItemById()", DebugWriteLineBlock))
            {
                var             request     = ItemWebApiRequestBuilder.ReadItemsRequestWithId(this.testData.Items.Home.Id).Build();
                var             cancelToken = CreateCancelTokenWithDelay(20);
                ScItemsResponse response    = null;

                // @adk : do not use Task.WaitAll() since it may cause deadlocks
                TestDelegate testCode = async() =>
                {
                    using (new FunctionTracer("session.ReadItemAsync()", DebugWriteLineBlock))
                    {
                        var task = this.session.ReadItemAsync(request, cancelToken);
                        response = await task;
                    }
                };
                var exception = Assert.Catch <OperationCanceledException>(testCode);
                Debug.WriteLine("Expected token : " + cancelToken);
                Debug.WriteLine("Received token : " + exception.CancellationToken);


                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);
            }
        }
        public async void TestCreateItemByPathFromBranch()
        {
            await this.RemoveTestItemsFromMasterAndWebAsync();

            const string ItemFromBranchName = "Multiple item branch";

            TestEnvironment.Item expectedItem = this.CreateTestItem(ItemFromBranchName);

            var request = ItemWebApiRequestBuilder.CreateItemRequestWithParentPath(this.testData.Items.CreateItemsHere.Path)
                          .BranchId("{14416817-CDED-45AF-99BF-2DE9883B7AC3}")
                          .ItemName(ItemFromBranchName)
                          .Database("master")
                          .Language("en")
                          .Payload(PayloadType.Content)
                          .Build();

            var createResponse = await session.CreateItemAsync(request);

            this.testData.AssertItemsCount(1, createResponse);

            ISitecoreItem resultItem = createResponse[0];

            this.testData.AssertItemsAreEqual(expectedItem, resultItem);


            var readJustCreatedItemRequest = ItemWebApiRequestBuilder.ReadItemsRequestWithId(resultItem.Id)
                                             .Database("master")
                                             .Build();
            var readJustCreatedItemResponse = await this.session.ReadItemAsync(readJustCreatedItemRequest);

            this.testData.AssertItemsCount(1, readJustCreatedItemResponse);
            this.testData.AssertItemsAreEqual(expectedItem, readJustCreatedItemResponse[0]);
        }
Esempio n. 7
0
        public async void TestOverrideVersionAndDbInRequestById()
        {
            const string Db       = "master";
            const string Language = "en";
            const int    Version  = 2;
            var          source   = new ItemSource("web", Language, 1);

            var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
                          .Credentials(testData.Users.Admin)
                          .DefaultDatabase(source.Database)
                          .DefaultLanguage(source.Language)
                          .BuildReadonlySession();

            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
                          .Version(Version)
                          .Database(Db)
                          .Payload(PayloadType.Content)
                          .Build();
            var response = await session.ReadItemAsync(request);

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

            testData.AssertItemsAreEqual(testData.Items.ItemWithVersions, resultItem);
            var sourceExpected = new ItemSource(Db, Language, Version);

            testData.AssertItemSourcesAreEqual(sourceExpected, resultItem.Source);
            Assert.AreEqual("English version 2 master", resultItem["Title"].RawValue);
        }
Esempio n. 8
0
        public async Task <ScItemsResponse> GetItemById(string itemId, PayloadType itemLoadType, List <ScopeType> itemScopeTypes, string itemLanguage = "en")
        {
            try
            {
                using (ISitecoreWebApiSession session = GetSession())
                {
                    IReadItemsByIdRequest request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(itemId)
                                                    .Payload(itemLoadType)
                                                    .AddScope(itemScopeTypes)
                                                    .Language(itemLanguage)
                                                    .Build();

                    return(await session.ReadItemAsync(request));
                }
            }
            catch (SitecoreMobileSdkException ex)
            {
                Log.Error("Error in GetItemById,  id {0} . Error: {1}", itemId, ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                Log.Error("Error in GetItemById,  id {0} . Error: {1}", itemId, ex.Message);
                throw ex;
            }
        }
        private async Task <ScItemsResponse> GetItemById(string id)
        {
            var request  = ItemWebApiRequestBuilder.ReadItemsRequestWithId(id).Database("master").Build();
            var response = await this.session.ReadItemAsync(request);

            return(response);
        }
Esempio n. 10
0
        public static async Task <ObservableCollection <WorkflowState> > GetWorkflowStatesInWorkflow(Workflow workflow)
        {
            var workflowStates = new ObservableCollection <WorkflowState> ();

            using (var session = CreateBaseSession().BuildSession()) {
                var request = ItemWebApiRequestBuilder
                              .ReadItemsRequestWithId(workflow.Id)
                              .AddScope(ScopeType.Children)
                              .AddFieldsToRead("Final")
                              .Build();

                var results = await session.ReadItemAsync(request);

                foreach (var result in results)
                {
                    //Don't add states that are considered the final state of the workflow
                    bool isFinal = result["Final"].RawValue == "1" ? true : false;
                    if (!isFinal)
                    {
                        workflowStates.Add(new WorkflowState(result));
                    }
                }
            }

            return(workflowStates);
        }
        public void TestSingleItemFieldsCanBeAddedIncrementally()
        {
            string[] expectedFields = { "Мыла", "Раму", "Мама" };

            IReadItemsByIdRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}")
                                           .AddFieldsToRead("Мыла")
                                           .AddFieldsToRead("Раму")
                                           .AddFieldsToRead("Мама")
                                           .Build();

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



            Assert.AreEqual("{dead-c0de}", result.ItemId);
            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
            Assert.IsNull(result.QueryParameters.Payload);
            Assert.AreEqual(expectedFields, result.QueryParameters.Fields);
        }
Esempio n. 12
0
        private async void SendRequest()
        {
            try
            {
                using (ISitecoreWebApiSession session = this.instanceSettings.GetSession())
                {
                    var builder = ItemWebApiRequestBuilder.ReadItemsRequestWithId(itemIdTextField.Text)
                                  .Payload(this.currentPayloadType)
                                  .AddFieldsToRead(this.fieldNameTextField.Text);

                    if (this.parentScopeButton.Selected)
                    {
                        builder = builder.AddScope(ScopeType.Parent);
                    }
                    if (this.selfScopeButton.Selected)
                    {
                        builder = builder.AddScope(ScopeType.Self);
                    }
                    if (this.childrenScopeButton.Selected)
                    {
                        builder = builder.AddScope(ScopeType.Children);
                    }

                    var request = builder.Build();

                    this.ShowLoader();

                    ScItemsResponse response = await session.ReadItemAsync(request);

                    if (response.Any())
                    {
                        this.ShowItemsList(response);

                        //items serialization test
                        ScItem item         = response[0] as ScItem;
                        string json         = JsonConvert.SerializeObject(item);
                        ScItem restoredItem = JsonConvert.DeserializeObject <ScItem>(json);
                        Console.WriteLine(restoredItem.DisplayName);
                    }
                    else
                    {
                        AlertHelper.ShowLocalizedAlertWithOkOption("Message", "Item is not exist");
                    }
                }
            }
            catch (Exception e)
            {
                this.CleanupTableViewBindings();
                AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
            }
            finally
            {
                BeginInvokeOnMainThread(delegate
                {
                    this.HideLoader();
                    this.FieldsTableView.ReloadData();
                });
            }
        }
        public void TestGetItemWithNullLanguageInRequestByIdDoNotReturnsException()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id)
                          .Language(null)
                          .Build();

            Assert.IsNotNull(request);
        }
 public void TestVersionCannotBeAssignedTwice()
 {
     Assert.Throws <InvalidOperationException>(() =>
                                               ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-beef}")
                                               .Version(2)
                                               .Version(99)
                                               );
 }
        public void TestGetItemByIdDuplicateScopeParamsReturnsException()
        {
            Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id)
                                                                            .AddScope(ScopeType.Self, ScopeType.Self)
                                                                            .Build());

            Assert.AreEqual("ReadItemByIdRequestBuilder.Scope : Adding scope parameter duplicates is forbidden", exception.Message);
        }
        public void TestEmptyLanguageCanBeAssignedExplicitly()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-beef}")
                          .Language(string.Empty)
                          .Build();

            Assert.IsNotNull(request);
        }
        public void TestNullDatabaseCanBeAssignedExplicitly()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-beef}")
                          .Database(null)
                          .Build();

            Assert.IsNotNull(request);
        }
        public void TestGetItemWithEmptyDatabaseInRequestByIdDoNotReturnsException()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id)
                          .Database("")
                          .Build();

            Assert.IsNotNull(request);
        }
Esempio n. 19
0
        public void TestGetItemByIdWithNullDatabaseDoNotReturnsError()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id)
                          .Database(null)
                          .Payload(PayloadType.Content)
                          .Build();

            Assert.IsNotNull(request);
        }
Esempio n. 20
0
        public void TestGetItemByIdWithOverridenPayloadReturnsException()
        {
            Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id)
                                                                            .Payload(PayloadType.Content)
                                                                            .Payload(PayloadType.Full)
                                                                            .Build());

            Assert.AreEqual("ReadItemByIdRequestBuilder.Payload : Property cannot be assigned twice.", exception.Message);
        }
 public void TestCaseInsensitiveDuplicatedFieldsCauseException()
 {
     Assert.Throws <InvalidOperationException>(() =>
                                               ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}")
                                               .AddFieldsToRead("XXXXX")
                                               .AddFieldsToRead("YYY")
                                               .AddFieldsToRead("xxXXx")
                                               .Build());
 }
        public void TestGetItemByIdWithOverrideVersionTwiceReturnsException()
        {
            Exception exception = Assert.Throws <InvalidOperationException>(() =>
                                                                            ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
                                                                            .Version(2)
                                                                            .Version(1)
                                                                            .Build());

            Assert.AreEqual("ReadItemByIdRequestBuilder.Version : Property cannot be assigned twice.", exception.Message);
        }
Esempio n. 23
0
        public void TestOverrideLanguageWithEmptyValueInRequestByIdDoNotReturnsError()
        {
            const string Language = "";

            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
                          .Language(Language)
                          .Build();

            Assert.IsNotNull(request);
        }
Esempio n. 24
0
        public async void TestGetItemByIdWithDefaultPayload() // ALR: PayloadType.Default constant should be removed
        {
            var request  = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id).Payload(PayloadType.Default).Build();
            var response = await this.sessionAuthenticatedUser.ReadItemAsync(request);

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

            Assert.AreEqual(0, item.FieldsCount);
        }
Esempio n. 25
0
        public async void TestGetItemByIdWithContentFields()
        {
            var request  = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.Home.Id).Payload(PayloadType.Content).Build();
            var response = await this.sessionAuthenticatedUser.ReadItemAsync(request);

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

            Assert.AreEqual(2, item.FieldsCount);
            Assert.AreEqual("Sitecore", item["Title"].RawValue);
        }
        public void TestNullFieldsAreNotIgnored()
        {
            {
                TestDelegate action = () => ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}").AddFieldsToRead((string)null);
                Assert.Throws <ArgumentNullException>(action);
            }

            {
                TestDelegate action = () => ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}").AddFieldsToRead((IEnumerable <string>)null);
                Assert.Throws <ArgumentNullException>(action);
            }
        }
        public async void TestGetNotAllowedItemWithChildrenScopeById()
        {
            var sessionWithNoReadAccessUser = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(this.testData.InstanceUrl)
                                              .Credentials(this.testData.Users.NoReadUserExtranet)
                                              .BuildReadonlySession();

            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(this.testData.Items.Home.Id)
                          .AddScope(ScopeType.Children)
                          .Build();
            var response = await sessionWithNoReadAccessUser.ReadItemAsync(request);

            testData.AssertItemsCount(0, response);
        }
        public void TestWhitespaceFieldsAreIgnored()
        {
            var request =
                ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}")
                .AddFieldsToRead("\n   \t   \r")
                .Build();

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.QueryParameters);
            if (null != request.QueryParameters.Fields)
            {
                Assert.AreEqual(0, request.QueryParameters.Fields.Count());
            }
        }
        public async void TestGetItemWithChildrenAndParentScopeById()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(this.testData.Items.AllowedItem.Id)
                          .AddScope(ScopeType.Children, ScopeType.Parent)
                          .Database("master")
                          .AddFieldsToRead("title")
                          .Payload(PayloadType.Full)
                          .Build();
            var response = await this.session.ReadItemAsync(request);

            testData.AssertItemsCount(3, response);
            Assert.AreEqual("Allowed_Child", response[0].DisplayName);
            testData.AssertItemsAreEqual(this.testData.Items.AllowedParent, response[2]);
        }
        public async void TestGetPage2WithSize3ByItemIdWithChildrenScope()
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId(this.testData.Items.MediaImagesItem.Id)
                          .AddScope(ScopeType.Children)
                          .PageNumber(2)
                          .ItemsPerPage(3)
                          .Build();

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

            Assert.IsNotNull(response);
            Assert.AreEqual(2, response.ResultCount);
            Assert.AreEqual(8, response.TotalCount);
        }