public void TestBuildValidScopeParams()
    {
      var scope = new ScopeParameters();
      scope.AddScope(ScopeType.Parent);
      var qp = new QueryParameters(null, scope, null);
      string result = this.builder.BuildUrlString(qp);
      Assert.AreEqual("scope=p", result);

      scope = new ScopeParameters();
      scope.AddScope(ScopeType.Self);
      qp = new QueryParameters(null, scope, null);
      result = this.builder.BuildUrlString(qp);
      Assert.AreEqual("scope=s", result);

      scope = new ScopeParameters();
      scope.AddScope(ScopeType.Children);
      qp = new QueryParameters(null, scope, null);
      result = this.builder.BuildUrlString(qp);
      Assert.AreEqual("scope=c", result);

      scope = new ScopeParameters();
      scope.AddScope(ScopeType.Parent);
      scope.AddScope(ScopeType.Self);
      scope.AddScope(ScopeType.Children);
      qp = new QueryParameters(null, scope, null);
      result = this.builder.BuildUrlString(qp);
      Assert.AreEqual("scope=p|s|c", result);
    }
コード例 #2
0
    public async void TestItemByIdRequestMutationDoesNotAffectSession()
    {
      string homeId = this.env.Items.Home.Id;

      IQueryParameters payload = new QueryParameters(PayloadType.Min, null, null);

      MockGetItemsByIdParameters mockMutableRequest = new MockGetItemsByIdParameters();
      mockMutableRequest.ItemId = homeId;
      mockMutableRequest.QueryParameters = payload;
      mockMutableRequest.ItemSource = this.itemSource;

      try
      {
        Task<ScItemsResponse> loadItemsTask = this.session.ReadItemAsync(mockMutableRequest);
        //      await Task.Factory.StartNew(() => mockMutableRequest.ItemId = this.env.Items.MediaLibrary.Id);
        ScItemsResponse response = await loadItemsTask;
        var item = response[0];
        Assert.AreEqual(homeId, item.Id);
      }
      catch (LoadDataFromNetworkException)
      {
        //IDLE
      }
      catch (Exception ex)
      {
        Debug.WriteLine(ex.Message);
      }
      finally
      {
        Assert.AreEqual(1, this.itemSource.CopyInvocationCount);
        Assert.AreEqual(1, mockMutableRequest.CopyInvocationCount);
      }
    }
    public void SetUp()
    {
      IRestServiceGrammar restGrammar = RestServiceGrammar.ItemWebApiV2Grammar();
      IWebApiUrlParameters webApiGrammar = WebApiUrlParameters.ItemWebApiV2UrlParameters();

      this.builder = new ItemByQueryUrlBuilder(restGrammar, webApiGrammar);

      SessionConfigPOD mutableSession = new SessionConfigPOD ();
      mutableSession.InstanceUrl = "http://mobiledev1ua1.dk.sitecore.net:722";
      mutableSession.ItemWebApiVersion = "v13";
      mutableSession.Site = null;
      this.sessionConfig = mutableSession;

      this.payload = new QueryParameters( PayloadType.Full, null, null );
    }
コード例 #4
0
    public void SetUp()
    {
      IRestServiceGrammar restGrammar = RestServiceGrammar.ItemWebApiV2Grammar();
      IWebApiUrlParameters webApiGrammar = WebApiUrlParameters.ItemWebApiV2UrlParameters();

      this.builder = new ItemByIdUrlBuilder(restGrammar, webApiGrammar);

      SessionConfigPOD mutableSessionConfig = new SessionConfigPOD();
      mutableSessionConfig.ItemWebApiVersion = "v1";
      mutableSessionConfig.InstanceUrl = "sitecore.net";
      mutableSessionConfig.Site = null;
      this.sessionConfig = mutableSessionConfig;


      mutableSessionConfig = new SessionConfigPOD();
      mutableSessionConfig.ItemWebApiVersion = "v234";
      mutableSessionConfig.InstanceUrl = "mobiledev1ua1.dk.sitecore.net:7119";
      mutableSessionConfig.Site = "/sitecore/shell";
      this.sitecoreShellConfig = mutableSessionConfig;

      this.payload = new QueryParameters(PayloadType.Min, null, null);
    }
 public void TestScopeParamsOrderIsPreserved()
 {
   var scope = new ScopeParameters();
   scope.AddScope(ScopeType.Children);
   scope.AddScope(ScopeType.Self);
   scope.AddScope(ScopeType.Parent);
   var qp = new QueryParameters(null, scope, null);
   string result = this.builder.BuildUrlString(qp);
   Assert.AreEqual("scope=c|s|p", result);
 }
コード例 #6
0
    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(null, null, fields);
      mutableParameters.QueryParameters = duplicatedFields;


      IReadItemsByIdRequest parameters = mutableParameters;
      Assert.Throws<ArgumentException>(() => this.builder.GetUrlForRequest(parameters));
    }
コード例 #7
0
    public async void TestItemByPathRequestMutationDoesNotAffectSession()
    {
      string homePath = "/sitecore/content/home";

      IQueryParameters payload = new QueryParameters(PayloadType.Min, null, null);

      MockGetItemsByPathParameters mockMutableRequest = new MockGetItemsByPathParameters();
      mockMutableRequest.ItemPath = homePath;
      mockMutableRequest.QueryParameters = payload;
      mockMutableRequest.ItemSource = this.itemSource;

      try
      {
        Task<ScItemsResponse> loadItemsTask = this.session.ReadItemAsync(mockMutableRequest);
        //      await Task.Factory.StartNew(() => mockMutableRequest.ItemPath = this.env.Items.MediaLibrary.Path);
        ScItemsResponse response = await loadItemsTask;
        var item = response[0];
        Assert.AreEqual(homePath.ToLowerInvariant(), item.Path.ToLowerInvariant());
      }
      catch (LoadDataFromNetworkException)
      {
        //IDLE
      }
      finally
      {
        Assert.AreEqual(1, this.itemSource.CopyInvocationCount);
        Assert.AreEqual(1, mockMutableRequest.CopyInvocationCount);
      }
    }
 public void TearDown()
 {
   this.builder = null;
   this.sessionConfig = null;
   this.payload = null;
 }
    public void TestDuplicateFieldsWithDifferentCaseCauseException()
    {
      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));
    }
コード例 #10
0
    public void TestBuildRequestWithPathAndFieldList()
    {
      MockGetItemsByPathParameters mutableParameters = new MockGetItemsByPathParameters();
      mutableParameters.ItemSource = LegacyConstants.DefaultSource();
      mutableParameters.ItemPath = "/path/TO/iTEm";
      mutableParameters.SessionSettings = this.sessionConfig;

      QueryParameters fieldsList = new QueryParameters(PayloadType.Default, null, new string[2] { "x", "y" });
      mutableParameters.QueryParameters = fieldsList;

      IReadItemsByPathRequest request = mutableParameters;

      string result = this.builder.GetUrlForRequest(request);
      string expected = "http://mobiledev1ua1.dk.sitecore.net/-/item/v2%2fpath%2fto%2fitem?sc_database=web&language=en&payload=min&fields=x|y";

      Assert.AreEqual(expected, result);
    }
コード例 #11
0
    public void TestReadItemByIdCopiesSessionSettings()
    {
      var defaultSource = new MutableItemSource("master", "en", 33);
      var sessionSettings = new MutableSessionConfig("localhost", "/sitecore/shell", "v100500");

      ScopeParameters scope = new ScopeParameters();
      scope.AddScope(ScopeType.Parent);
      scope.AddScope(ScopeType.Self);

      string[] fields = { "Ukraine", "is", "Europe" };
      var queryParameters = new QueryParameters(PayloadType.Content, scope, fields);

      IPagingParameters pagingSettings = null;
      ReadItemsByIdParameters request = new ReadItemsByIdParameters(
        sessionSettings,
        defaultSource,
        queryParameters,
        pagingSettings,
        "{aaaa-aa-bb}");
      var otherRequest = request.DeepCopyGetItemByIdRequest();

      {
        sessionSettings.SetInstanceUrl("paappaa");

        Assert.AreEqual("localhost", otherRequest.SessionSettings.InstanceUrl);
        Assert.AreNotSame(request.SessionSettings, otherRequest.SessionSettings);
        Assert.AreNotSame(request.ItemSource, otherRequest.ItemSource);
        Assert.AreNotSame(request.QueryParameters, otherRequest.QueryParameters);
      }
    }
コード例 #12
0
    public void TestReadItemQueryRequestCopiesPagingOptions()
    {
      var defaultSource = new MutableItemSource("master", "en", 33);
      var sessionSettings = new MutableSessionConfig("localhost", "/sitecore/shell", "v100500");

      ScopeParameters scope = new ScopeParameters();
      scope.AddScope(ScopeType.Parent);
      scope.AddScope(ScopeType.Self);

      string[] fields = { "Ukraine", "is", "Europe" };
      var queryParameters = new QueryParameters(PayloadType.Content, scope, fields);

      var pagingSettings = new MutablePagingParameters(1, 10);
      ReadItemByQueryParameters request = new ReadItemByQueryParameters(
        sessionSettings,
        defaultSource,
        queryParameters,
        pagingSettings,
        "/x/y/z");
      var otherRequest = request.DeepCopyGetItemByQueryRequest();


      {
        pagingSettings.PageNumber = 20;
        pagingSettings.ItemsPerPageCount = 100500;


        Assert.AreEqual(10, otherRequest.PagingSettings.ItemsPerPageCount);
        Assert.AreEqual(1, otherRequest.PagingSettings.PageNumber);
      }
    }
コード例 #13
0
    public void TestReadItemByIdCopiesItemSource()
    {
      var defaultSource = new MutableItemSource("master", "en", 33);
      var sessionSettings = new MutableSessionConfig("localhost", "/sitecore/shell", "v100500");

      ScopeParameters scope = new ScopeParameters();
      scope.AddScope(ScopeType.Parent);
      scope.AddScope(ScopeType.Self);

      string[] fields = { "Ukraine", "is", "Europe" };
      var queryParameters = new QueryParameters(PayloadType.Content, scope, fields);

      IPagingParameters pagingSettings = null;
      ReadItemsByIdParameters request = new ReadItemsByIdParameters(
        sessionSettings,
        defaultSource,
        queryParameters,
        pagingSettings,
        "{aaaa-aa-bb}");
      var otherRequest = request.DeepCopyGetItemByIdRequest();

      {
        defaultSource.SetDatabase("web");
        defaultSource.SetLanguage("xyz");
        defaultSource.SetVersion(9999);

        Assert.AreEqual("master", otherRequest.ItemSource.Database);
        Assert.AreEqual("en", otherRequest.ItemSource.Language);
        Assert.AreEqual(33, otherRequest.ItemSource.VersionNumber.Value);

        Assert.AreNotSame(request.SessionSettings, otherRequest.SessionSettings);
        Assert.AreNotSame(request.ItemSource, otherRequest.ItemSource);
        Assert.AreNotSame(request.QueryParameters, otherRequest.QueryParameters);
      }
    }