Exemplo n.º 1
0
        public void TestMultipleItemFieldsCanBeAddedIncrementally()
        {
            string[] fields         = { "Мама", "Мыла", "Раму" };
            string[] moarFields     = { "1", "2", "4" };
            string[] expectedFields = { "Мама", "Мыла", "Раму", "1", "2", "4" };

            IReadItemsByIdRequest result = ItemSSCRequestBuilder.ReadItemsRequestWithId("110d559f-dea5-42ea-9c1c-8a5df7e70ef9")
                                           .AddFieldsToRead(fields)
                                           .AddFieldsToRead(moarFields)
                                           .Build();

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



            Assert.AreEqual("110d559f-dea5-42ea-9c1c-8a5df7e70ef9", result.ItemId);
            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
            Assert.AreEqual(expectedFields, result.QueryParameters.Fields);
        }
Exemplo n.º 2
0
        private async Task <ScItemsResponse> GetItemByIdWithItemSource(ItemSource itemSource)
        {
            var session = SitecoreSSCSessionBuilder.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 = ItemSSCRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
                          .Version(itemSource.VersionNumber.Value)
                          .Build();
            }

            var response = await session.ReadItemAsync(request);

            return(response);
        }
        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);
        }
Exemplo n.º 4
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;
            }
        }
        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);
        }
Exemplo n.º 6
0
        public void Setup()
        {
            this.testData = TestEnvironment.DefaultTestEnvironment();

            var builder = new ReadItemByIdRequestBuilder(this.testData.Items.ItemWithVersions.Id);

            this.requestWithVersionsItemId = builder.Build();

            homeItemRequestBuilder = new ReadItemByIdRequestBuilder(this.testData.Items.Home.Id);
        }
    public void Setup()
    {
      this.testData = TestEnvironment.DefaultTestEnvironment();

      var builder = new ReadItemByIdRequestBuilder(this.testData.Items.ItemWithVersions.Id).Payload(PayloadType.Content);
      this.requestWithVersionsItemId = builder.Build();

      homeItemRequestBuilder = new ReadItemByIdRequestBuilder(this.testData.Items.Home.Id);
      homeItemRequestBuilder.Payload(PayloadType.Content);
    }
        public IReadItemsByIdRequest FillReadItemByIdGaps(IReadItemsByIdRequest userRequest)
        {
            IItemSource    mergedSource        = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
            ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

            return(new ReadItemsByIdParameters(
                       mergedSessionConfig,
                       mergedSource,
                       userRequest.QueryParameters,
                       userRequest.IncludeStandardTemplateFields,
                       userRequest.ItemId));
        }
        public async Task <ScItemsResponse> ReadItemAsync(IReadItemsByIdRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            IReadItemsByIdRequest requestCopy = request.DeepCopyGetItemByIdRequest();

            await this.GetPublicKeyAsync(cancelToken);

            IReadItemsByIdRequest autocompletedRequest = this.requestMerger.FillReadItemByIdGaps(requestCopy);

            var urlBuilder = new ItemByIdUrlBuilder(this.restGrammar, this.sscGrammar);
            var taskFlow   = new GetItemsByIdTasks(urlBuilder, this.httpClient);

            return(await RestApiCallFlow.LoadRequestFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken));
        }
    public IReadItemsByIdRequest FillReadItemByIdGaps(IReadItemsByIdRequest userRequest)
    {
      IItemSource mergedSource = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
      ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

      IPagingParameters pagingSettings = userRequest.PagingSettings;
      return new ReadItemsByIdParameters(
        mergedSessionConfig, 
        mergedSource, 
        userRequest.QueryParameters, 
        pagingSettings, 
        userRequest.ItemId);
    }
Exemplo n.º 11
0
        public async Task <ScItemsResponse> ReadItemAsync(IReadItemsByIdRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            IReadItemsByIdRequest requestCopy = request.DeepCopyGetItemByIdRequest();

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

                var urlBuilder = new ItemByIdUrlBuilder(this.restGrammar, this.webApiGrammar);
                var taskFlow   = new GetItemsByIdTasks(urlBuilder, this.httpClient, cryptor);

                return(await RestApiCallFlow.LoadRequestFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken));
            }
        }
Exemplo n.º 12
0
        public IReadItemsByIdRequest FillReadItemByIdGaps(IReadItemsByIdRequest userRequest)
        {
            IItemSource    mergedSource        = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
            ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

            IPagingParameters pagingSettings = userRequest.PagingSettings;

            return(new ReadItemsByIdParameters(
                       mergedSessionConfig,
                       mergedSource,
                       userRequest.QueryParameters,
                       pagingSettings,
                       userRequest.ItemId));
        }
Exemplo n.º 13
0
        public void Setup()
        {
            this.testData = TestEnvironment.DefaultTestEnvironment();

            this.sessionAuthenticatedUser =
                SitecoreSSCSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
                .Credentials(testData.Users.Admin)
                .DefaultDatabase("web")
                .DefaultLanguage("en")
                .BuildReadonlySession();

            this.requestWithItemId = ItemSSCRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
                                     .Build();
        }
        public void TestInvaliItemIdCausesArgumentException()
        {
            MockGetItemsByIdParameters mutableParameters = new MockGetItemsByIdParameters();

            mutableParameters.SessionSettings = this.sessionConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.ItemId          = "someInvalidItemId";
            mutableParameters.QueryParameters = this.payload;

            IReadItemsByIdRequest parameters = mutableParameters;

            TestDelegate action = () => this.builder.GetUrlForRequest(parameters);

            Assert.Throws <ArgumentException>(action);
        }
    public void Setup()
    {
      this.testData = TestEnvironment.DefaultTestEnvironment();

      this.sessionAuthenticatedUser =
        SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(testData.InstanceUrl)
          .Credentials(testData.Users.Admin)
          .DefaultDatabase("web")
          .DefaultLanguage("en")
          .BuildReadonlySession();

      this.requestWithItemId = ItemWebApiRequestBuilder.ReadItemsRequestWithId(testData.Items.ItemWithVersions.Id)
        .Payload(PayloadType.Content)
        .Build();
    }
        public void TestUrlBuilderAddsItemSource()
        {
            MockGetItemsByIdParameters mutableParameters = new MockGetItemsByIdParameters();

            mutableParameters.SessionSettings = this.sitecoreShellConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.ItemId          = "110d559f-dea5-42ea-9c1c-8a5df7e70ef9";
            mutableParameters.QueryParameters = this.payload;

            IReadItemsByIdRequest parameters = mutableParameters;

            string result   = this.builder.GetUrlForRequest(parameters);
            string expected = "https://mobiledev1ua1.dk.sitecore.net:7119/sitecore/api/ssc/item/110d559f-dea5-42ea-9c1c-8a5df7e70ef9?database=web&language=en";

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 17
0
        public void TestItemIdRequestBuilderWithIdOnly()
        {
            IReadItemsByIdRequest result = ItemSSCRequestBuilder.ReadItemsRequestWithId("110d559f-dea5-42ea-9c1c-8a5df7e70ef9").Build();

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


            Assert.AreEqual("110d559f-dea5-42ea-9c1c-8a5df7e70ef9", result.ItemId);
            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
        }
        public void TestUrlBuilderAddsItemSource()
        {
            MockGetItemsByIdParameters mutableParameters = new MockGetItemsByIdParameters();

            mutableParameters.SessionSettings = this.sitecoreShellConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.ItemId          = "{   xxx   }";
            mutableParameters.QueryParameters = this.payload;

            IReadItemsByIdRequest parameters = mutableParameters;

            string result   = this.builder.GetUrlForRequest(parameters);
            string expected = "http://mobiledev1ua1.dk.sitecore.net:7119/-/item/v234%2fsitecore%2fshell?sc_database=web&language=en&payload=min&sc_itemid=%7b%20%20%20xxx%20%20%20%7d";

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

            mutableParameters.SessionSettings = this.sessionConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.ItemId          = "{   xxx   }";
            mutableParameters.QueryParameters = null;

            IReadItemsByIdRequest parameters = mutableParameters;

            string result   = this.builder.GetUrlForRequest(parameters);
            string expected = "http://sitecore.net/-/item/v1?sc_database=web&language=en&sc_itemid=%7b%20%20%20xxx%20%20%20%7d";

            Assert.AreEqual(expected, result);
        }
        public void TestItemIdRequestBuilderWithIdOnly()
        {
            IReadItemsByIdRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{abra-kadabra}").Build();

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


            Assert.AreEqual("{abra-kadabra}", result.ItemId);
            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
            Assert.IsNull(result.QueryParameters.Payload);
        }
        public void TestEmptyFieldEntriesCaseCauseException()
        {
            MockGetItemsByIdParameters mutableParameters = new MockGetItemsByIdParameters();

            mutableParameters.SessionSettings = this.sitecoreShellConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.ItemId          = "{   xxx   }";

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

            mutableParameters.QueryParameters = duplicatedFields;


            IReadItemsByIdRequest parameters = mutableParameters;

            Assert.Throws <ArgumentException>(() => this.builder.GetUrlForRequest(parameters));
        }
        public void TestDuplicateFieldsWithDifferentCaseCauseException()
        {
            MockGetItemsByIdParameters mutableParameters = new MockGetItemsByIdParameters();

            mutableParameters.SessionSettings = this.sitecoreShellConfig;
            mutableParameters.ItemSource      = LegacyConstants.DefaultSource();
            mutableParameters.ItemId          = "110d559f-dea5-42ea-9c1c-8a5df7e70ef9";

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

            mutableParameters.QueryParameters = duplicatedFields;


            IReadItemsByIdRequest parameters = mutableParameters;

            Assert.Throws <ArgumentException>(() => this.builder.GetUrlForRequest(parameters));
        }
        public void TestItemIdRequestBuilderWithAllFields()
        {
            IReadItemsByIdRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-beef}")
                                           .Database("web")
                                           .Language("en")
                                           .Version(1)
                                           .Payload(PayloadType.Full)
                                           .Build();

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

            Assert.AreEqual("{dead-beef}", result.ItemId);
            Assert.AreEqual("en", result.ItemSource.Language);
            Assert.AreEqual("web", result.ItemSource.Database);
            Assert.AreEqual(1, result.ItemSource.VersionNumber);
            Assert.AreEqual(PayloadType.Full, result.QueryParameters.Payload);
        }
Exemplo n.º 24
0
        public void TestAddFieldMethodSupportsParamsKeyword()
        {
            string[] expectedFields = { "alpha", "beta", "gamma" };

            IReadItemsByIdRequest result = ItemSSCRequestBuilder.ReadItemsRequestWithId("110d559f-dea5-42ea-9c1c-8a5df7e70ef9")
                                           .AddFieldsToRead("alpha", "beta", "gamma")
                                           .Build();

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



            Assert.AreEqual("110d559f-dea5-42ea-9c1c-8a5df7e70ef9", result.ItemId);
            Assert.IsNull(result.ItemSource.Language);
            Assert.IsNull(result.ItemSource.Database);
            Assert.IsNull(result.ItemSource.VersionNumber);
            Assert.AreEqual(expectedFields, result.QueryParameters.Fields);
        }
        public void TestAddFieldMethodSupportsParamsKeyword()
        {
            string[] expectedFields = { "alpha", "beta", "gamma" };

            IReadItemsByIdRequest result = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{dead-c0de}")
                                           .AddFieldsToRead("alpha", "beta", "gamma")
                                           .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);
        }
 public void Setup()
 {
     testData = TestEnvironment.DefaultTestEnvironment();
     this.requestWithItemId = ItemSSCRequestBuilder.ReadItemsRequestWithId(this.testData.Items.Home.Id).Build();
 }
Exemplo n.º 27
0
    public async Task<ScItemsResponse> ReadItemAsync(IReadItemsByIdRequest request, CancellationToken cancelToken = default(CancellationToken))
    {
      IReadItemsByIdRequest requestCopy = request.DeepCopyGetItemByIdRequest();

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

        var urlBuilder = new ItemByIdUrlBuilder(this.restGrammar, this.webApiGrammar);
        var taskFlow = new GetItemsByIdTasks(urlBuilder, this.httpClient, cryptor);

        return await RestApiCallFlow.LoadRequestFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken);
      }
    }
Exemplo n.º 28
0
 public async Task <ScItemsResponse> ReadItemAsync(IReadItemsByIdRequest request, CancellationToken cancelToken = default(CancellationToken))
 {
     return(await this.InvokeNoThrow(this.workerSession.ReadItemAsync(request, cancelToken)));
 }
 public void Setup()
 {
   testData = TestEnvironment.DefaultTestEnvironment();
   this.requestWithItemId = ItemWebApiRequestBuilder.ReadItemsRequestWithId(this.testData.Items.Home.Id).Build();
 }