public ISitecoreWebApiSession BuildSession()
    {
      string optionalWebApiVersion = this.OptionalWebApiVersion();
      string optionalMediaRoot = this.OptionalMediaRoot();
      string optionalMediaExtension = this.OptionalMediaExtension();
      string optionalMediaPrefix = this.OptionalMediaPrefix();


      ////////
      SessionConfig conf = new SessionConfig(
        this.instanceUrl,
        this.site,
        optionalWebApiVersion);

      var mediaSettings = new MediaLibrarySettings(
        optionalMediaRoot,
        optionalMediaExtension,
        optionalMediaPrefix,
        this.resizingFlag);

      var itemSource = new ItemSource(
        this.itemSourceAccumulator.Database,
        this.itemSourceAccumulator.Language,
        this.itemSourceAccumulator.VersionNumber);

      var result = new ScApiSession(conf, this.credentials, mediaSettings, itemSource);
      return result;
    }
        public virtual SessionConfig ShallowCopy()
        {
            SessionConfig result = new SessionConfig(
                this.InstanceUrl
                );

            return(result);
        }
    public virtual SessionConfig ShallowCopy()
    {
      SessionConfig result = new SessionConfig(
        this.InstanceUrl,
        this.Site,
        this.ItemWebApiVersion);

      return result;
    }
Exemple #4
0
        public virtual SessionConfig ShallowCopy()
        {
            SessionConfig result = new SessionConfig(
                this.InstanceUrl,
                this.Site,
                this.ItemWebApiVersion);

            return(result);
        }
    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.id = "{B0ED4777-1F5D-478D-AF47-145CCA9E4311}";
      this.database = "master";

      this.builder = new DeleteItemByIdUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());
    }
    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 TestSessionConfigAllowsNullUsernameForAuthenticatedSession()
    {
      var sessionSettings = new SessionConfig("localhost", "/sitecore/shell", "v1");
      var credentials = new WebApiCredentialsPOD(null, "pass");

      Assert.IsNotNull(sessionSettings);
      Assert.IsNotNull(credentials);

      Assert.AreEqual("localhost", sessionSettings.InstanceUrl);
      Assert.IsNull(credentials.Username);
      Assert.AreEqual("pass", credentials.Password);
      Assert.AreEqual("/sitecore/shell", sessionSettings.Site);
      Assert.AreEqual("v1", sessionSettings.ItemWebApiVersion);
    }
    public void SetUp()
    {
      this.mediaSettings = new MediaLibrarySettings(
        "/sitecore/media library",
        "ashx",
        "~/media/");

      this.testData = TestEnvironment.DefaultTestEnvironment();

      var config = new SessionConfig(testData.InstanceUrl);
      this.anonymousSession = new ScTestApiSession(config, null, this.mediaSettings, LegacyConstants.DefaultSource());

      config = new SessionConfig(testData.InstanceUrl);
      this.authenticatedSession = new ScTestApiSession(config, testData.Users.Admin, this.mediaSettings, LegacyConstants.DefaultSource());
    }
    public void Setup()
    {
      TestEnvironment env = TestEnvironment.DefaultTestEnvironment();
      this.env = env;

      this.mediaSettings = new MediaLibrarySettings(
        "/sitecore/media library",
        "ashx",
        "~/media/");

      var connection = new SessionConfig(this.env.InstanceUrl);
      var defaultSource = LegacyConstants.DefaultSource();

      this.session = new ScTestApiSession(connection, env.Users.Admin, this.mediaSettings, defaultSource);
      this.itemSource = new MutableItemSource("master", "en", 3872);
    }
    public void TestSessionDefaultSourceCannotBeMutated()
    {
      var connection = new SessionConfig("localhost");

      var defaultSource = new MutableItemSource("master", "en");
      var session = new ScApiSession(connection, null, this.mediaSettings, defaultSource);

      Assert.AreEqual(defaultSource, session.DefaultSource);
      Assert.AreNotSame(defaultSource, session.DefaultSource);



      defaultSource.SetDatabase("web");
      defaultSource.SetLanguage("da");
      defaultSource.SetVersion(100500);
      Assert.AreNotEqual(defaultSource, session.DefaultSource);
      Assert.AreNotSame(defaultSource, session.DefaultSource);
    }
    public void TestOptionalSourceInSessionAndUserRequest()
    {
      var connection = new SessionConfig("localhost");

      var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/home/*").Build();
      var requestMerger = new UserRequestMerger(connection, null);
      var mergedRequest = requestMerger.FillReadItemByQueryGaps(request);

      var urlBuilder = new ItemByQueryUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

      string result = urlBuilder.GetUrlForRequest(mergedRequest);
      string expected = "http://localhost/-/item/v1?query=%2fsitecore%2fcontent%2fhome%2f%2a";

      Assert.AreEqual(expected, result);
    }
    public void TestExplicitDatabase()
    {
      var connection = new SessionConfig("localhost");

      var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/oO")
        .Database("master")
        .Build();
      var requestMerger = new UserRequestMerger(connection, null);
      var mergedRequest = requestMerger.FillReadItemByPathGaps(request);

      var urlBuilder = new ItemByPathUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

      string result = urlBuilder.GetUrlForRequest(mergedRequest);
      string expected = "http://localhost/-/item/v1%2fsitecore%2fcontent%2foo?sc_database=master";

      Assert.AreEqual(expected, result);
    }
    public void TestExplicitDatabase()
    {
      var connection = new SessionConfig("localhost");

      var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{xxx-yyy-zzz}")
        .Database("master")
        .Build();
      var requestMerger = new UserRequestMerger(connection, null);
      var mergedRequest = requestMerger.FillReadItemByIdGaps(request);

      var urlBuilder = new ItemByIdUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

      string result = urlBuilder.GetUrlForRequest(mergedRequest);
      string expected = "http://localhost/-/item/v1?sc_database=master&sc_itemid=%7bxxx-yyy-zzz%7d";

      Assert.AreEqual(expected, result);
    }
    public void TestDatabaseAndExplicitLanguageAndPayload()
    {
      var connection = new SessionConfig("localhost");

      var request = ItemWebApiRequestBuilder.ReadItemsRequestWithId("{xxx-yyy-zzz}")
        .Language("da")
        .Payload(PayloadType.Content)
        .Build();
      var requestMerger = new UserRequestMerger(connection, null);
      var mergedRequest = requestMerger.FillReadItemByIdGaps(request);

      var urlBuilder = new ItemByIdUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

      string result = urlBuilder.GetUrlForRequest(mergedRequest);
      string expected = "http://localhost/-/item/v1?language=da&payload=content&sc_itemid=%7bxxx-yyy-zzz%7d";

      Assert.AreEqual(expected, result);
    }
    public void TestDatabaseAndExplicitLanguageAndPayload()
    {
      var connection = new SessionConfig("localhost");

      var request = ItemWebApiRequestBuilder.ReadItemsRequestWithSitecoreQuery("/sitecore/content/home/*")
        .Language("da")
        .Payload(PayloadType.Content)
        .Build();
      var requestMerger = new UserRequestMerger(connection, null);
      var mergedRequest = requestMerger.FillReadItemByQueryGaps(request);

      var urlBuilder = new ItemByQueryUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters());

      string result = urlBuilder.GetUrlForRequest(mergedRequest);
      string expected = "http://localhost/-/item/v1?language=da&payload=content&query=%2fsitecore%2fcontent%2fhome%2f%2a";

      Assert.AreEqual(expected, result);
    }