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);
    }
 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);
 }
    public void Setup()
    {
      this.sessionConfig = new MutableSessionConfig("http://testurl");
      this.scopeParameters = new ScopeParameters();

      this.id = "{B0ED4777-1F5D-478D-AF47-145CCA9E4311}";
      this.database = "master";

      this.builder = new DeleteItemByIdUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());
    }
    public void TearDown()
    {
      this.sessionConfig = null;
      this.scopeParameters = null;

      this.id = null;
      this.database = null;

      this.builder = null;
    }
    public void Setup()
    {
      this.sessionConfig = new MutableSessionConfig("http://testurl");
      this.scopeParameters = new ScopeParameters();

      this.path = "/sitecore/content/Home/Android/Folder for deleting/1";
      this.database = "master";

      this.builder = new DeleteItemByPathUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());
    }
    public void Setup()
    {
      this.sessionConfig = new MutableSessionConfig("http://testurl");
      this.scopeParameters = new ScopeParameters();

      this.query = "/Sitecore/Content/*";
      this.fastQuery = "fast:/sitecore/content/Home/Products/*[@@name = 'Hammer']";
      this.database = "master";

      this.builder = new DeleteItemByQueryUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());
    }
    public void TestScopeParamsCanNotBeSetTwice()
    {
      var scope = new ScopeParameters();
      scope.AddScope(ScopeType.Children);
      scope.AddScope(ScopeType.Self);

      Assert.IsFalse(scope.AddScope(ScopeType.Children));
    }
 public void TestSimpleFieldListOfIdsIsProcessedCorrectly()
 {
   string[] fields = { "{0000-1111-2222}", "{1123-5813-21-34}" };
   var scope = new ScopeParameters();
   scope.AddScope(ScopeType.Children);
   string result = this.builder.BuildUrlString(new QueryParameters(PayloadType.Min, scope, fields));
   Assert.AreEqual("payload=min&scope=c&fields=%7b0000-1111-2222%7d|%7b1123-5813-21-34%7d", result);
 }
    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);
      }
    }
    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);
      }
    }
    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);
      }
    }