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 virtual IReadItemsByIdRequest DeepCopyGetItemByIdRequest()
        {
            ++this.CopyInvocationCount;

            MockGetItemsByIdParameters result = new MockGetItemsByIdParameters();

            result.ItemId = this.ItemId;

            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 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 virtual IReadItemsByIdRequest DeepCopyGetItemByIdRequest()
    {
      ++this.CopyInvocationCount;

      MockGetItemsByIdParameters result = new MockGetItemsByIdParameters();
      result.ItemId = this.ItemId;

      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 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 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));
    }
    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);
    }