private async Task <ScItemsResponse> GetItemByPath(string itemPath) { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(itemPath).Build(); var response = await this.sessionAuthenticatedUser.ReadItemAsync(request); return(response); }
public void TestNegativeVersionCannotBeAssignedExplicitly() { Assert.Throws <ArgumentException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/pppp/sss") .Version(-34) ); }
public void TestAddScopeThrowsExceptionOnDuplicates() { Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/SitecoreDotShell") .AddScope(ScopeType.Self) .AddScope(ScopeType.Self)); }
public void TestWhitespaceLanguageCannotBeAssignedExplicitly() { Assert.Throws <ArgumentException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/aaa/bb/fff") .Language("\t \r \n") ); }
public void TestNullVersionCannotBeAssignedExplicitly() { Assert.Throws <ArgumentNullException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/aaa/bb/fff") .Version(null) ); }
private async void MakeRequest() { using (var credentials = new Credentials("admin", "b")) using (var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost("http://cms80full.build.test24dk1.dk.sitecore.net/") .Credentials(credentials) .Site("/sitecore/shell") .BuildSession()) { try { var builder = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home") .Payload(PayloadType.Full); var response = await session.ReadItemAsync(builder.Build()); if (response.ResultCount != 0) { ResultBlock.DataContext = response[0]["Text"]; } } catch (Exception exception) { MessageBox.Show("Failed to receive item. Message : " + exception.Message); } } }
public void TestOverrideVersionWithNegativeValueInRequestByPathReturnsError() { var requestBuilder = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path); Exception exception = Assert.Throws <ArgumentException>(() => requestBuilder.Version(-1).Build()); Assert.AreEqual("ReadItemByPathRequestBuilder.Version : Positive number expected", exception.Message); }
public void TestAddScopeThrowsExceptionOnDuplicatesInIncrementCalls() { Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecoreDOTshell") .AddScope(ScopeType.Self, ScopeType.Parent) .AddScope(ScopeType.Self)); }
public override async void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); #warning first we have to setup connection info and create a session var instanceUrl = "http://my.site.com"; using (var credentials = new SecureStringPasswordProvider("login", "password")) using ( var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl) .Credentials(credentials) .WebApiVersion("v1") .DefaultDatabase("web") .DefaultLanguage("en") .BuildSession()) { // In order to fetch some data we have to build a request var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home") .AddFieldsToRead("text") .AddScope(ScopeType.Self) .Build(); // And execute it on a session asynchronously var response = await session.ReadItemAsync(request); // Now that it has succeeded we are able to access downloaded items ISitecoreItem item = response[0]; // And content stored it its fields string fieldContent = item["text"].RawValue; UIAlertView alert = new UIAlertView("Sitecore SDK Demo", fieldContent, null, "Ok", null); alert.Show(); } }
public void TestGetItemByPathWithEmptyDatabaseReturnsError() { var requestBuilder = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path); Exception exception = Assert.Throws <ArgumentException>(() => requestBuilder.Database(" ").Payload(PayloadType.Content).Build()); Assert.AreEqual("ReadItemByPathRequestBuilder.Database : The input cannot be empty.", exception.Message); }
public async Task <ScItemsResponse> GetItemByPath(string itemPath, PayloadType itemLoadType, List <ScopeType> itemScopeTypes, string itemLanguage = "en") { try { using (ISitecoreWebApiSession session = GetSession()) { IReadItemsByPathRequest request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(itemPath) .Payload(itemLoadType) .AddScope(itemScopeTypes) .Language(itemLanguage) .Build(); return(await session.ReadItemAsync(request)); } } catch (SitecoreMobileSdkException ex) { Log.Error("Error in GetItemByPath, id {0} . Error: {1}", itemPath, ex.Message); throw ex; } catch (Exception ex) { Log.Error("Error in GetItemByPath, id {0} . Error: {1}", itemPath, ex.Message); throw ex; } }
public void TestPayloadCannotBeAssignedTwice() { Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/aaa/bb/fff") .Payload(PayloadType.Content) .Payload(PayloadType.Min) ); }
public void TestGetItemWithNullDatabaseInRequestByPathDoNotReturnsException() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path) .Database(null) .Build(); Assert.IsNotNull(request); }
public void TestLanguageCannotBeAssignedTwice() { Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/aaa/bb/fff") .Language("en") .Language("fr") ); }
public void TestAddScopeSupportsParamsSyntax() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/sHell") .AddScope(ScopeType.Self, ScopeType.Parent, ScopeType.Children); Assert.IsNotNull(request); }
public void TestEmptyDatabaseCanBeAssignedExplicitly() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/aaa/bb/fff") .Database(string.Empty) .Build(); Assert.IsNotNull(request); }
public async void TestGetItemByPathWithoutFields() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path).Payload(PayloadType.Min).Build(); var response = await this.sessionAuthenticatedUser.ReadItemAsync(request); testData.AssertItemsCount(1, response); testData.AssertItemsAreEqual(testData.Items.Home, response[0]); Assert.AreEqual(0, response[0].FieldsCount); }
public void TestGetItemByPathWithOverridenPayloadReturnsException() { Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path) .Payload(PayloadType.Full) .Payload(PayloadType.Min) .Build()); Assert.AreEqual("ReadItemByPathRequestBuilder.Payload : Property cannot be assigned twice.", exception.Message); }
public void TestAddScopeSupportsCollection() { ScopeType[] scopeArgs = { ScopeType.Self, ScopeType.Parent, ScopeType.Children }; var scopeArgsList = new List <ScopeType>(scopeArgs); var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/aaaa") .AddScope(scopeArgsList); Assert.IsNotNull(request); }
public void TestGetItemByPathWithOverrideLanguageTwiceReturnsException() { Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path) .Language("da") .Language("en") .Build()); Assert.AreEqual("ReadItemByPathRequestBuilder.Language : Property cannot be assigned twice.", exception.Message); }
public async void TestGetItemWitchHasNotChildrenWithChildrenScopeByPath() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(this.testData.Items.TestFieldsItem.Path) .AddScope(ScopeType.Children) .Build(); var response = await this.session.ReadItemAsync(request); testData.AssertItemsCount(0, response); }
public async void TestGetItemWWithSelfScopeByNotExistentPath() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/not existent/path") .AddScope(ScopeType.Children) .Build(); var response = await this.session.ReadItemAsync(request); testData.AssertItemsCount(0, response); }
public void TestGetItemByPathDuplicateScopeParamsReturnsException() { Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path) .AddScope(ScopeType.Parent) .AddScope(ScopeType.Children) .AddScope(ScopeType.Parent) .Build()); Assert.AreEqual("ReadItemByPathRequestBuilder.Scope : Adding scope parameter duplicates is forbidden", exception.Message); }
public void TestOverrideDatabaseInRequestByPathSeveralTimesReturnsError() { const string Db = "web"; Exception exception = Assert.Throws <InvalidOperationException>(() => ItemWebApiRequestBuilder.ReadItemsRequestWithPath(testData.Items.Home.Path) .Database("master") .Database(Db) .Payload(PayloadType.Content).Build()); Assert.AreEqual("ReadItemByPathRequestBuilder.Database : Property cannot be assigned twice.", exception.Message); }
public void TestPagingSettingsCanBeCalledOnlyOnce() { Assert.Throws <InvalidOperationException>(() => { ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/A/B/C/D/E") .AddScope(ScopeType.Self) .PageNumber(5) .ItemsPerPage(10) .PageNumber(1); }); }
private async void SendRequest() { try { using (ISitecoreWebApiSession session = this.instanceSettings.GetSession()) { var builder = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(this.ItemPathField.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); } else { AlertHelper.ShowLocalizedAlertWithOkOption("Message", "Item is not exist"); } } } catch (Exception e) { this.CleanupTableViewBindings(); AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message); } finally { BeginInvokeOnMainThread(delegate { this.FieldsTableView.ReloadData(); this.HideLoader(); }); } }
public async void TestGetItemByPathWithUserWithoutReadAccessToHomeItem() { var sessionWithoutAccess = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(this.testData.InstanceUrl) .Credentials(this.testData.Users.NoReadUserExtranet) .BuildReadonlySession(); var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(this.testData.Items.Home.Path).Build(); var response = await sessionWithoutAccess.ReadItemAsync(request); testData.AssertItemsCount(0, response); }
public async void TestGetItemWithInternationalFields() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/Home/Android/Static/Japanese/宇都宮").Payload(PayloadType.Content).Build(); var response = await this.sessionAuthenticatedUser.ReadItemAsync(request); testData.AssertItemsCount(1, response); Assert.AreEqual("宇都宮", response[0].DisplayName); Assert.AreEqual("/sitecore/content/Home/Android/Static/Japanese/宇都宮", response[0].Path); ISitecoreItem item = response[0]; Assert.AreEqual(2, item.FieldsCount); Assert.AreEqual("宇都宮", item["Title"].RawValue); }
public async void TestGetItemWithParentScopeByPath() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/Home/Allowed_Parent") .Payload(PayloadType.Full) .AddScope(ScopeType.Parent) .Build(); var response = await this.session.ReadItemAsync(request); testData.AssertItemsCount(1, response); var resultItem = response[0]; testData.AssertItemsAreEqual(testData.Items.Home, resultItem); Assert.AreEqual("The Home item is the default starting point for a website.", resultItem["__Long description"].RawValue); }
public async void TestOutOfRangeRequestReturnsEmptyDataset() { var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath(this.testData.Items.Home.Path) .AddScope(ScopeType.Children) .PageNumber(10) .ItemsPerPage(5) .Build(); ScItemsResponse response = await this.session.ReadItemAsync(request); Assert.IsNotNull(response); Assert.AreEqual(0, response.ResultCount); Assert.AreEqual(4, response.TotalCount); }