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);
        }
    public IReadItemsByQueryRequest FillReadItemByQueryGaps(IReadItemsByQueryRequest userRequest)
    {
      IItemSource mergedSource = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
      ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

      IPagingParameters pagingSettings = userRequest.PagingSettings;
      return new ReadItemByQueryParameters(
        mergedSessionConfig, 
        mergedSource, 
        userRequest.QueryParameters, 
        pagingSettings,
        userRequest.SitecoreQuery);
    }
        public void TestQueryCannotBeWhitespace()
        {
            MockGetItemsByQueryParameters mutableParameters = new MockGetItemsByQueryParameters();

            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.SitecoreQuery   = "   \t \r \n   ";
            mutableParameters.SessionSettings = this.sessionConfig;
            mutableParameters.QueryParameters = this.payload;

            IReadItemsByQueryRequest request = mutableParameters;

            Assert.Throws <ArgumentException> (() => this.builder.GetUrlForRequest(request));
        }
Beispiel #4
0
        public IReadItemsByQueryRequest FillReadItemByQueryGaps(IReadItemsByQueryRequest userRequest)
        {
            IItemSource    mergedSource        = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
            ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

            IPagingParameters pagingSettings = userRequest.PagingSettings;

            return(new ReadItemByQueryParameters(
                       mergedSessionConfig,
                       mergedSource,
                       userRequest.QueryParameters,
                       pagingSettings,
                       userRequest.SitecoreQuery));
        }
        public async Task <ScItemsResponse> ReadItemAsync(IReadItemsByQueryRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            IReadItemsByQueryRequest requestCopy = request.DeepCopyGetItemByQueryRequest();

            using (ICredentialsHeadersCryptor cryptor = await this.GetCredentialsCryptorAsync(cancelToken))
            {
                IReadItemsByQueryRequest autocompletedRequest = this.requestMerger.FillReadItemByQueryGaps(requestCopy);

                var urlBuilder = new ItemByQueryUrlBuilder(this.restGrammar, this.webApiGrammar);
                var taskFlow   = new GetItemsByQueryTasks(urlBuilder, this.httpClient, cryptor);

                return(await RestApiCallFlow.LoadRequestFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken));
            }
        }
        public void TestBuildWithFastQuery()
        {
            MockGetItemsByQueryParameters mutableParameters = new MockGetItemsByQueryParameters();

            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.SitecoreQuery   = "fast:/sitecore/content/Home/Products/*[@@name = 'Hammer']";
            mutableParameters.SessionSettings = this.sessionConfig;
            mutableParameters.QueryParameters = this.payload;

            IReadItemsByQueryRequest request = mutableParameters;

            string result   = this.builder.GetUrlForRequest(request);
            string expected = "http://mobiledev1ua1.dk.sitecore.net:722/-/item/v13?sc_database=web&language=en&payload=full&query=fast%3a%2fsitecore%2fcontent%2fHome%2fProducts%2f%2a%5b%40%40name%20%3d%20%27Hammer%27%5d";

            Assert.AreEqual(expected, result);
        }
        public void TestNullPayloadStructIsIgnored()
        {
            MockGetItemsByQueryParameters mutableParameters = new MockGetItemsByQueryParameters();

            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.SitecoreQuery   = "/Sitecore/Content/*";
            mutableParameters.SessionSettings = this.sessionConfig;
            mutableParameters.QueryParameters = null;

            IReadItemsByQueryRequest request = mutableParameters;

            string result   = this.builder.GetUrlForRequest(request);
            string expected = "http://mobiledev1ua1.dk.sitecore.net:722/-/item/v13?sc_database=web&language=en&query=%2fSitecore%2fContent%2f%2a";

            Assert.AreEqual(expected, result);
        }
        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 TestDuplicateFieldsCauseException()
        {
            var mutableParameters = new MockGetItemsByQueryParameters();

            mutableParameters.SessionSettings = this.sessionConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.SitecoreQuery   = "/aaa/bbb/ccc/*";

            string[]         fields           = { "x", "y", "x" };
            IQueryParameters duplicatedFields = new QueryParameters(null, null, fields);

            mutableParameters.QueryParameters = duplicatedFields;


            IReadItemsByQueryRequest parameters = mutableParameters;

            Assert.Throws <ArgumentException>(() => this.builder.GetUrlForRequest(parameters));
        }
Beispiel #10
0
        //gets the item or child item on specifying the query
        public async Task <ScItemsResponse> GetItemByQuery(string query, string itemLanguage = "en")
        {
            try
            {
                using (ISitecoreWebApiSession session = GetSession())

                {
                    IReadItemsByQueryRequest request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery(query).Language(itemLanguage).Build();
                    return(await session.ReadItemAsync(request));
                }
            }
            catch (SitecoreMobileSdkException ex)
            {
                Log.Error("Error in GetItemByQuery, id{0}. Error{1}", query, ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                Log.Error("Error in GetItemByQuery, id{0}. Error{1}", query, ex.Message);
                throw ex;
            }
        }
    public async Task<ScItemsResponse> ReadItemAsync(IReadItemsByQueryRequest request, CancellationToken cancelToken = default(CancellationToken))
    {
      IReadItemsByQueryRequest requestCopy = request.DeepCopyGetItemByQueryRequest();

      using (ICredentialsHeadersCryptor cryptor = await this.GetCredentialsCryptorAsync(cancelToken))
      {
        IReadItemsByQueryRequest autocompletedRequest = this.requestMerger.FillReadItemByQueryGaps(requestCopy);

        var urlBuilder = new ItemByQueryUrlBuilder(this.restGrammar, this.webApiGrammar);
        var taskFlow = new GetItemsByQueryTasks(urlBuilder, this.httpClient, cryptor);

        return await RestApiCallFlow.LoadRequestFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken);
      }
    }
 public async Task <ScItemsResponse> ReadItemAsync(IReadItemsByQueryRequest request, CancellationToken cancelToken = default(CancellationToken))
 {
     return(await this.InvokeNoThrow(this.workerSession.ReadItemAsync(request, cancelToken)));
 }