예제 #1
0
        public IReadItemsByPathRequest DeepCopyGetItemByPathRequest()
        {
            ++this.CopyInvocationCount;

            MockGetItemsByPathParameters result = new MockGetItemsByPathParameters();

            result.ItemPath = this.ItemPath;

            if (null != this.ItemSource)
            {
                result.ItemSource = this.ItemSource.ShallowCopy();
            }

            if (null != this.SessionSettings)
            {
                result.SessionSettings = this.SessionSettings.SessionConfigShallowCopy();
            }

            if (null == this.QueryParameters)
            {
                result.QueryParameters = this.QueryParameters.DeepCopy();
            }

            return(result);
        }
    public void TestBuildWithValidPath()
    {
      MockGetItemsByPathParameters mutableParameters = new MockGetItemsByPathParameters();
      mutableParameters.ItemSource = LegacyConstants.DefaultSource();
      mutableParameters.ItemPath = "/path/TO/iTEm";
      mutableParameters.SessionSettings = this.sessionConfig;
      mutableParameters.QueryParameters = this.payload;

      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=content";

      Assert.AreEqual(expected, result);
    }
    public IReadItemsByPathRequest DeepCopyGetItemByPathRequest()
    {
      ++this.CopyInvocationCount;

      MockGetItemsByPathParameters result = new MockGetItemsByPathParameters();
      result.ItemPath = this.ItemPath;

      if (null != this.ItemSource)
      {
        result.ItemSource = this.ItemSource.ShallowCopy();
      }

      if (null != this.SessionSettings)
      {
        result.SessionSettings = this.SessionSettings.SessionConfigShallowCopy();
      }

      if (null == this.QueryParameters)
      {
        result.QueryParameters = this.QueryParameters.DeepCopy();
      }

      return result;
    }
    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 TestDuplicateFieldsWithDifferentCaseCauseException()
    {
      var mutableParameters = new MockGetItemsByPathParameters();
      mutableParameters.SessionSettings = this.sessionConfig;
      mutableParameters.ItemSource = LegacyConstants.DefaultSource();
      mutableParameters.ItemPath = "/aaa/bbb/ccc/ddd";


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


      IReadItemsByPathRequest parameters = mutableParameters;
      Assert.Throws<ArgumentException>(() => this.builder.GetUrlForRequest(parameters));
    }
    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);
    }
    public void TestBuildWithWhitespacePathCausesArgumentException()
    {
      MockGetItemsByPathParameters mutableParameters = new MockGetItemsByPathParameters();
      mutableParameters.ItemSource = LegacyConstants.DefaultSource();
      mutableParameters.ItemPath = "\r\n\t";
      mutableParameters.SessionSettings = this.sessionConfig;
      mutableParameters.QueryParameters = this.payload;


      IReadItemsByPathRequest request = mutableParameters;

      TestDelegate action = () => this.builder.GetUrlForRequest(request);
      Assert.Throws<ArgumentException>(action);
    }
    public void TestPathMustStartWithSlash()
    {
      MockGetItemsByPathParameters mutableParameters = new MockGetItemsByPathParameters();
      mutableParameters.ItemSource = LegacyConstants.DefaultSource();
      mutableParameters.ItemPath = "path without starting slash";
      mutableParameters.SessionSettings = this.sessionConfig;
      mutableParameters.QueryParameters = this.payload;

      IReadItemsByPathRequest request = mutableParameters;

      TestDelegate action = () => this.builder.GetUrlForRequest(request);
      Assert.Throws<ArgumentException>(action);
    }