public FakeItem WithVersion(Sitecore.Data.Version version) { Item.Version.Returns(version); Item.Database.GetItem(Item.ID, Item.Language ?? Sitecore.Globalization.Language.Invariant, Item.Version).Returns(Item); return(this); }
/// <summary> /// Archive specific versions. /// /// </summary> /// <param name="item">The item. /// </param> private void ArchiveItemVersion(Item item, ListString list) { string databaseName = item.Database.Name; Database database = Database.GetDatabase(databaseName); Assert.IsNotNull((object)database, "Database \"{0}\" not found", (object)databaseName); Language language = Language.Parse(item.Language.Name); foreach (var v in list) { Sitecore.Data.Version version = Sitecore.Data.Version.Parse(item.Versions.GetVersionNumbers().Where(n => n.Number.ToString() == v.ToString()).FirstOrDefault()); Item obj = database.GetItem(item.ID, language, version); if (obj == null) { return; } Sitecore.Data.Archiving.Archive archive = ArchiveManager.GetArchive("archive", database); Log.Audit(new object(), "Archive version: {0}", new string[1] { AuditFormatter.FormatItem(obj) }); archive.ArchiveVersion(obj); } }
/// <summary> /// Returns an item always from the provided ItemID /// This will get the db from the context or look from query string /// This will get the language from the context or look from query string /// This will get the version from the query string or take the default version which is latest /// </summary> /// <param name="ItemID">Item id in string</param> /// <param name="dbName">dbName in string</param> /// <param name="language">language in string</param> /// <param name="versionNum">versionNum in string</param> /// <returns>Sitecore.Data.Items.Item</returns> public static Item GetItem(string ItemID, string dbName = "master", string language = "en", int versionNum = 1) { Item result = null; using (new SecurityDisabler()) { string itemcachekey = string.Empty; Database db = GetDatabase(dbName); Language lang = GetLanguage(language); Sitecore.Data.Version version = GetItemVersion(versionNum); if (db != null && lang != null && version != null) { itemcachekey = ItemID + lang.Name + version.Number.ToString(); if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName)) { result = db.GetItem(ItemID, lang, version); APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName); } else { result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName); } return(result); } } return(result); }
public virtual Item GetSitecoreItem(ID itemId, Language language, Version version) { Assert.ArgumentNotNull(itemId, "itemId"); Assert.ArgumentNotNull(language, "language"); Assert.ArgumentNotNull(version, "version"); if (!this.FakeItems.ContainsKey(itemId)) { return(null); } // TODO:[High] Avoid the templates resetting. Required to avoid sharing templates between unit tests. this.Database.Engines.TemplateEngine.Reset(); var fakeItem = this.FakeItems[itemId]; if (version == Version.Latest) { version = Version.Parse(fakeItem.GetVersionCount(language.Name)); if (version == Version.Latest) { version = Version.First; } } var fields = this.BuildItemFieldList(fakeItem, fakeItem.TemplateID, language, version); return(ItemHelper.CreateInstance(this.database, fakeItem.Name, fakeItem.ID, fakeItem.TemplateID, fakeItem.BranchId, fields, language, version)); }
public static LinkDatabaseCommand CreateInsertCommand( string sourceDatabase, ID sourceItemID, Language sourceLanguage, Sitecore.Data.Version sourceVersion, ID sourceFieldID, string targetDatabase, ID targetItemID, Language targetLanguage, Sitecore.Data.Version targetVersion, string targetPath, IBatchOperation operation) { var parameters = new List <object>(); var index = operation.Index; var sql = $@" INSERT INTO [Links] ( [SourceDatabase], [SourceItemID], [SourceLanguage], [SourceVersion], [SourceFieldID], [TargetDatabase], [TargetItemID], [TargetLanguage], [TargetVersion], [TargetPath] ) VALUES( @{LinksTableColumns.Database}{index}, @{LinksTableColumns.ItemID}{index}, @{LinksTableColumns.SourceLanguage}{index}, @{LinksTableColumns.SourceVersion}{index}, @{LinksTableColumns.FieldID}{index}, @{LinksTableColumns.TargetDatabase}{index}, @{LinksTableColumns.TargetID}{index}, @{LinksTableColumns.TargetLanguage}{index}, @{LinksTableColumns.TargetVersion}{index}, @{LinksTableColumns.TargetPath}{index} )"; AddToParameters(parameters, $"{LinksTableColumns.Database}{index}", GetString(sourceDatabase, DatabaseNameLength)); AddToParameters(parameters, $"{LinksTableColumns.ItemID}{index}", sourceItemID.Guid); AddToParameters(parameters, $"{LinksTableColumns.SourceLanguage}{index}", GetString(sourceLanguage.ToString(), LanguageNameLength)); AddToParameters(parameters, $"{LinksTableColumns.SourceVersion}{index}", sourceVersion.Number); AddToParameters(parameters, $"{LinksTableColumns.FieldID}{index}", sourceFieldID.Guid); AddToParameters(parameters, $"{LinksTableColumns.TargetDatabase}{index}", GetString(targetDatabase, DatabaseNameLength)); AddToParameters(parameters, $"{LinksTableColumns.TargetID}{index}", targetItemID.Guid); AddToParameters(parameters, $"{LinksTableColumns.TargetLanguage}{index}", GetString(targetLanguage.ToString(), LanguageNameLength)); AddToParameters(parameters, $"{LinksTableColumns.TargetVersion}{index}", targetVersion.Number); AddToParameters(parameters, $"{LinksTableColumns.TargetPath}{index}", targetPath); return(new LinkDatabaseCommand(sql, parameters)); }
public void IsDerived_ItemIsOfGivenTemplate_ReturnsTrue() { // setup #region Setup var baseTemplateId = ID.NewID; var itemId = ID.NewID; var item = Substitute.For <Item>( itemId, new ItemData( new ItemDefinition(itemId, "Item Of Template", baseTemplateId, ID.NewID), this.Language, Version.Parse(1), new FieldList() ), this.Database); var template = new Template.Builder("Base Template", baseTemplateId, new TemplateCollection()).Template; this.TemplateManager.GetTemplate(baseTemplateId, this.Database).Returns(template); this.TemplateManager.GetTemplate(item).Returns(template); #endregion // act var isDerived = this.ItemExtensions.IsDerived(item, baseTemplateId); // assert isDerived.Should().BeTrue(); }
protected virtual MediaData GetMediaData(MediaUri mediaUri) { Assert.ArgumentNotNull((object)mediaUri, nameof(mediaUri)); Database database = mediaUri.Database; if (database == null) { return((MediaData)null); } string mediaPath = mediaUri.MediaPath; if (string.IsNullOrEmpty(mediaPath)) { return((MediaData)null); } Language language = mediaUri.Language; if (language == (Language)null) { language = Context.Language; } Sitecore.Data.Version version = mediaUri.Version; if (version == (Sitecore.Data.Version)null) { version = Sitecore.Data.Version.Latest; } Item obj = database.GetItem(mediaPath, language, version); if (obj == null) { return((MediaData)null); } return(MediaManager.Config.ConstructMediaDataInstance((MediaItem)obj)); }
/// <summary> /// Gets an <see cref="Item"/> by path, language and version number. /// </summary> /// <param name="path">The item path.</param> /// <param name="language">The item language.</param> /// <param name="version">The item version.</param> /// <returns>The item.</returns> public Item GetItem(string path, string language, int version) { Assert.ArgumentNotNullOrEmpty(path, "path"); Assert.ArgumentNotNull(language, "language"); return(this.Database.GetItem(path, Language.Parse(language), Version.Parse(version))); }
public void GetItem_UsingItemPathLanguage4ParameterVersion_ReturnsItemName() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var service = new SitecoreService(db); string path = "/sitecore/content/Tests/SitecoreService/GetItem/EmptyItem"; var language = LanguageManager.GetLanguage("af-ZA"); Sitecore.Data.Version version = new Sitecore.Data.Version(1); int param1 = 1; string param2 = "2param"; DateTime param3 = DateTime.Now; bool param4 = true; //Act var result = service.GetItem <StubClass, int, string, DateTime, bool>(path, language, version, param1, param2, param3, param4); //Assert Assert.IsNotNull(result); Assert.AreEqual(path, result.Path); Assert.AreEqual(language, result.Language); Assert.AreEqual(param1, result.Param1); Assert.AreEqual(param2, result.Param2); Assert.AreEqual(param3, result.Param3); Assert.AreEqual(param4, result.Param4); Assert.AreEqual(version.Number, result.Version); }
private void AddBrokenLinks(IDataReader reader, List <ItemLink> links, Database database) { Assert.ArgumentNotNull((object)reader, "reader"); Assert.ArgumentNotNull((object)links, "links"); Assert.ArgumentNotNull((object)database, "database"); using (new SecurityDisabler()) { string name = database.Name; while (reader.Read()) { ID sourceItemID = ID.Parse(reader.GetGuid(0)); Language sourceItemLanguage = Language.Parse(reader.GetString(1)); Sitecore.Data.Version sourceItemVersion = Sitecore.Data.Version.Parse(reader.GetInt32(2)); ID sourceFieldID = ID.Parse(reader.GetGuid(3)); string string1 = reader.GetString(4); ID id = ID.Parse(reader.GetGuid(5)); Language language = Language.Parse(reader.GetString(6)); Sitecore.Data.Version version = Sitecore.Data.Version.Parse(reader.GetInt32(7)); string string2 = reader.GetString(8); Database database1 = Factory.GetDatabase(string1); if (!this.ItemExists(id, string2, language, version, database1)) { links.Add(new ItemLink(name, sourceItemID, sourceItemLanguage, sourceItemVersion, sourceFieldID, name, id, language, version, string2)); } Job job = Context.Job; if (job != null && job.Category == "GetBrokenLinks") { ++job.Status.Processed; } LinkCounters.DataRead.Increment(); DataCounters.PhysicalReads.Increment(); } } }
public void GetItem_UsingItemIdLanguage3ParameterVersion_ReturnsItemName() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var service = new SitecoreService(db); Guid id = new Guid("{6DE18DBD-0AF3-404A-8018-02B8A19515C1}"); var language = LanguageManager.GetLanguage("af-ZA"); Sitecore.Data.Version version = new Sitecore.Data.Version(1); int param1 = 1; string param2 = "2param"; DateTime param3 = DateTime.Now; //Act var result = service.GetItem <StubClass, int, string, DateTime>(id, language, version, param1, param2, param3); //Assert Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); Assert.AreEqual(language, result.Language); Assert.AreEqual(param1, result.Param1); Assert.AreEqual(param2, result.Param2); Assert.AreEqual(param3, result.Param3); Assert.AreEqual(version.Number, result.Version); }
private Item GetPolicyItem(string sPolicyId, string sVersion) { #region VARIABLES ID oPolicyId; Item oPolicyItem; Version oPolicyVersion; Language oCurrentLanguage; int iVersion; #endregion oPolicyItem = null; if (ID.TryParse(sPolicyId, out oPolicyId) && int.TryParse(sVersion, out iVersion)) { if (iVersion > 0) { oPolicyVersion = new Version(iVersion); oCurrentLanguage = Language.Parse(ContextExtension.CurrentLanguageCode); oPolicyItem = ContextExtension.CurrentDatabase.GetItem(oPolicyId, oCurrentLanguage, oPolicyVersion); } else { oPolicyItem = ContextExtension.CurrentDatabase.GetItem(oPolicyId); } } return(oPolicyItem); }
/// <summary> /// Executes the command in the specified context. /// </summary> /// <param name="context">The context.</param> public override void Execute(CommandContext context) { Assert.ArgumentNotNull((object)context, "context"); if (context.Items.Length != 1) { return; } NameValueCollection parameters = new NameValueCollection(); string itemID = context.Parameters["itemid"] ?? context.Parameters["id"]; ItemUri itemUri = ItemUri.ParseQueryString(); if (string.IsNullOrEmpty(itemID) && itemUri != (ItemUri)null) { itemID = itemUri.ItemID.ToString(); } parameters["itemid"] = itemID; string language = context.Parameters["language"]; if (string.IsNullOrEmpty(language)) { language = itemUri.Language.ToString(); } Sitecore.Data.Version version = itemUri.Version; parameters["database"] = itemUri.DatabaseName; parameters["language"] = language; parameters["navigate"] = context.Parameters["navigate"]; parameters["version"] = version.ToString(); Context.ClientPage.Start((object)this, "Run", parameters); }
private Sitecore.Data.Items.Item retrieveItem(ListviewItem listItem) { string path = listItem.Header; Sitecore.Globalization.Language lang = Sitecore.Globalization.Language.Current; Sitecore.Data.Version version = Sitecore.Data.Version.Latest; Sitecore.Data.Items.Item item = null; if (listItem.ColumnValues.Contains("lang")) { Sitecore.Globalization.Language.TryParse(listItem.ColumnValues["lang"].ToString(), out lang); } if (listItem.ColumnValues.Contains("version")) { version = new Sitecore.Data.Version(listItem.ColumnValues["version"].ToString()); } item = Properties.Db.GetItem(path, lang, version); if (item == null) { if (Properties.Db.HasContentItem) { path = "/sitecore/content/" + path; item = Properties.Db.GetItem(path, lang, version); if (item != null) { return(item); } } throw new Exception("Item does not exist in such language"); } return(item); }
public void ShouldGetItemByUri() { // arrange using (var db = new Db { new DbItem("home", this.itemId) { new DbField("Title") { { "en", 1, "Welcome!" }, { "da", 1, "Hello!" }, { "da", 2, "Velkommen!" } } } }) { // act & assert var uriEn1 = new ItemUri(this.itemId, Language.Parse("en"), Version.Parse(1), db.Database); Database.GetItem(uriEn1)["Title"].Should().Be("Welcome!"); var uriDa1 = new ItemUri(this.itemId, Language.Parse("da"), Version.Parse(1), db.Database); Database.GetItem(uriDa1)["Title"].Should().Be("Hello!"); var uriDa2 = new ItemUri(this.itemId, Language.Parse("da"), Version.Parse(2), db.Database); Database.GetItem(uriDa2)["Title"].Should().Be("Velkommen!"); } }
private Item GetCurrentItem() { // Parse the querystring to get the item string queryString = WebUtil.GetQueryString("id"); Language language = Language.Parse(WebUtil.GetQueryString("la")); Sitecore.Data.Version version = Sitecore.Data.Version.Parse(WebUtil.GetQueryString("vs")); return(master.GetItem(new ID(queryString), language, version)); }
public void FakeDataUri_WhenCalledWithParams_SetsLanguage(ID id, int versionNumber) { var language = Language.Invariant; var version = Version.Parse(versionNumber); var uri = FakeUtil.FakeDataUri(id, language, version); uri.Language.Should().Be(language); }
public Item GetSelectionItem(Language language, Sitecore.Data.Version version) { Item[] selectedItems = this.GetSelectedItems(language, version); if (selectedItems.Length != 0) { return(selectedItems[0]); } return(null); }
public void FakeDataUri_WhenCalledWithParams_NeverReturnsNull(ID id, int versionNumber) { var language = Language.Invariant; var version = Version.Parse(versionNumber); var uri = FakeUtil.FakeDataUri(id, language, version); uri.Should().NotBeNull(); }
/// <summary> /// Returns an item always from the provided Path /// This will get the db from the context or look from query string /// This will get the language from the context or look from query string /// This will get the version from the query string or take the default version which is latest /// </summary> /// <param name="path">Item path in string</param> /// <returns>Sitecore.Data.Items.Item</returns> public static Item GetItemPath(string path) { Item result = null; using (new SecurityDisabler()) { string itemcachekey = string.Empty; Database db = GetDatabase(); Language lang = GetLanguage(); Sitecore.Data.Version version = GetItemVersion(); if (db != null && lang != null && version != null) { itemcachekey = path.Trim() + lang.Name + version.Number.ToString(); if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName)) { result = db.GetItem(path, lang, version); APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName); } else { result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName); } return(result); } else if (db != null && lang != null) { itemcachekey = path.Trim() + lang.Name + "0"; if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName)) { result = db.GetItem(path, lang); APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName); } else { result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName); } return(result); } else if (db != null) { itemcachekey = path.Trim() + "default" + "0"; if (!APICache.isCacheExist(itemcachekey, Common.APICache.RegionName)) { result = db.GetItem(path); APICache.AddToAPICache(itemcachekey, result, APICachePriority.Default, Common.APICache.RegionName); } else { result = APICache.GetAPICachedItem <Item>(itemcachekey, Common.APICache.RegionName); } result = db.GetItem(path); return(result); } } return(result); }
public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context) { if (Items.ContainsKey(itemDefinition.ID)) { VersionUriList versionUriList = new VersionUriList(); versionUriList.Add(LanguageManager.DefaultLanguage, Version.Parse(1)); return(versionUriList); } return(null); }
public void CreatesItemData() { IFixture fixture = new Fixture().Customize(new AutoSitecoreCustomization()); var data = fixture.Create <ItemData>(); data.Should().NotBeNull(); data.Language.Should().Be(Language.Invariant); data.Version.Should().Be(Version.Parse(0)); }
public void Version_MatchesConstructedValue() { //Arrange ItemKey testItemKey = new ItemKey(_guid1, _path1, _ver1, _mockLanguageWrapperEnglish, _masterDbName); //Act Version testVersion = testItemKey.Version; //Assert Assert.AreEqual(_ver1, testVersion); }
/// <summary>Gets the current item.</summary> /// <returns>The current item.</returns> private static Item GetCurrentItem() { string queryString1 = WebUtil.GetQueryString("db"); string queryString2 = WebUtil.GetQueryString("id"); Language index1 = Language.Parse(WebUtil.GetQueryString("la")); Version index2 = Sitecore.Data.Version.Parse(WebUtil.GetQueryString("vs")); Database database = Factory.GetDatabase(queryString1); Assert.IsNotNull(database, queryString1); return(database.Items[queryString2, index1, index2]); }
private static Item GetCurrentItem() { string queryString = WebUtil.GetQueryString("db"); string path = WebUtil.GetQueryString("id"); Language language = Language.Parse(WebUtil.GetQueryString("la")); Version version = Version.Parse(WebUtil.GetQueryString("vs")); Database database = Factory.GetDatabase(queryString); Assert.IsNotNull(database, queryString); return(database.GetItem(path, language, version)); }
public void FakeItemUri_WhenCalledWithItem_SetsDatabaseName(string itemName, ID itemId, int versionNumber, string databaseName) { var database = FakeUtil.FakeDatabase(databaseName); var item = FakeUtil.FakeItem(itemId, itemName, database); FakeUtil.FakeItemLanguage(item); var version = Version.Parse(versionNumber); item.Version.Returns(version); var uri = FakeUtil.FakeItemUri(item).Uri; uri.DatabaseName.Should().Be(databaseName); }
public void AddVersionAddsNewVersionAndReturnsNewVersionNumber( [Greedy] FakeDataProvider sut, ItemDefinition itemDefinition, Language language, int version, DbItem item) { sut.DataStorage.GetFakeItem(itemDefinition.ID).Returns(item); var baseVersion = new VersionUri(language, Version.Parse(version)); var expectedVersion = version + 1; var result = sut.AddVersion(itemDefinition, baseVersion, null); result.Should().Be(expectedVersion); item.GetVersionCount(language.Name).Should().Be(expectedVersion); }
// public void Initialize(Item item) // { // Initialize(item.ID, item.Paths.FullPath, item.Version, (LanguageWrapper)item.Language, item.Database.Name); // } private void Initialize(ID guid, string path, Version version, ILanguageWrapper language, string databaseName) { if (guid == (ID)null || path == null || version == null || language == null || databaseName == null) { throw new ArgumentNullException(); } if (path == string.Empty || databaseName == string.Empty) { throw new ArgumentException(); } _guid = guid; _path = path; _version = version; _language = language; _databaseName = databaseName; }
public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context) { var versions = new VersionUriList(); if (itemDefinition == ItemDefinition.Empty) { return(versions); } var database = GetDatabase(context); var syncItem = database.GetItem(itemDefinition.ID.ToString()); foreach (var syncVersion in syncItem.Versions) { versions.Add(Language.Parse(syncVersion.Language), Version.Parse(syncVersion.Version)); } return(versions); }
protected static void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull((object)args, "args"); try { var dbName = args.Parameters["database"]; Version version; Language lan; Guid uid, itemId; if (!Guid.TryParse(args.Parameters["referenceId"], out uid) || !Guid.TryParse(args.Parameters["itemId"], out itemId) || !Version.TryParse(args.Parameters["version"], out version) || !Language.TryParse(args.Parameters["language"], out lan)) { Context.ClientPage.ClientResponse.Alert(Translate.Text("The Reset of the Component Changes is FAILED!")); return; } if (args.IsPostBack) { if (!args.HasResult || args.Result != "yes") { return; } var item = Database.GetDatabase(dbName).GetItem(new ID(itemId), lan, version); CompareProvider.GetRenderingsHelper().ResetRendering(item, new ID(uid)); Context.ClientPage.ClientResponse.Alert(Translate.Text("The Reset of the Component Changes is SUCCEEDED on the FINAL Layout for the Item Version {1} of the '{0}' language!").FormatWith(args.Parameters["language"].ToUpper(), args.Parameters["version"])); } else { Context.ClientPage.ClientResponse.Confirm(Translate.Text("Do you want to RESET all Component Changes on the FINAL Layout for the Item Version {1} of the '{0}' language?").FormatWith(args.Parameters["language"].ToUpper(), args.Parameters["version"])); args.WaitForPostBack(); } } catch (Exception ex) { Log.Error(ex.Message, ex, new ResetComponentsChanges()); } }
public void GetItem_UsingItemIdLanguageVersion_ReturnsItemName() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Factory.GetDatabase("master"); var service = new SitecoreService(db); Guid id = new Guid("{6DE18DBD-0AF3-404A-8018-02B8A19515C1}"); var language = LanguageManager.GetLanguage("af-ZA"); Version version = new Version(1); //Act var result = service.GetItem<StubClass>(id, language, version); //Assert Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); Assert.AreEqual(language, result.Language); Assert.AreEqual(version.Number, result.Version); }
public Item GetSelectionItem(Language language, Version version) { Item[] selectedItems = this.GetSelectedItems(language, version); if (selectedItems.Length != 0) { return selectedItems[0]; } return null; }
public void GetItem_UsingItemPathLanguage4ParameterVersion_ReturnsItemName() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var service = new SitecoreService(db); string path = "/sitecore/content/Tests/SitecoreService/GetItem/EmptyItem"; var language = LanguageManager.GetLanguage("af-ZA"); Sitecore.Data.Version version = new Sitecore.Data.Version(1); int param1 = 1; string param2 = "2param"; DateTime param3 = DateTime.Now; bool param4 = true; //Act var result = service.GetItem<StubClass, int, string, DateTime, bool>(path, language, version, param1, param2, param3, param4); //Assert Assert.IsNotNull(result); Assert.AreEqual(path, result.Path); Assert.AreEqual(language, result.Language); Assert.AreEqual(param1, result.Param1); Assert.AreEqual(param2, result.Param2); Assert.AreEqual(param3, result.Param3); Assert.AreEqual(param4, result.Param4); Assert.AreEqual(version.Number, result.Version); }
public void GetItem_UsingItemPathLanguageVersion_ReturnsItemName() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Factory.GetDatabase("master"); var service = new SitecoreService(db); string path = "/sitecore/content/Tests/SitecoreService/GetItem/EmptyItem"; var language = LanguageManager.GetLanguage("af-ZA"); Version version = new Version(1); //Act var result = service.GetItem<StubClass>(path, language, version); //Assert Assert.IsNotNull(result); Assert.AreEqual(path, result.Path); Assert.AreEqual(language, result.Language); Assert.AreEqual(version.Number, result.Version); }
protected void AddFieldsFromTemplate(FieldList allFields, DbItem fakeItem, DbTemplate fakeTemplate, Language language, Version version) { var sourceItem = this.GetSourceItem(fakeItem); foreach (var templateField in fakeTemplate.Fields) { var fieldId = templateField.ID; var itemField = this.FindItemDbField(fakeItem, templateField); if (itemField == null) { continue; } var value = itemField.GetValue(language.Name, version.Number); if (sourceItem != null && string.IsNullOrWhiteSpace(value)) { continue; } if (value != null) { allFields.Add(fieldId, value); } } foreach (var template in fakeTemplate.BaseIDs.Select(this.GetFakeTemplate).Where(t => t != null)) { this.AddFieldsFromTemplate(allFields, fakeItem, template, language, version); } if (fakeTemplate.BaseIDs.Any() || fakeTemplate.ID == TemplateIDs.StandardTemplate) { return; } var standardTemplate = this.GetFakeTemplate(TemplateIDs.StandardTemplate); this.AddFieldsFromTemplate(allFields, fakeItem, standardTemplate, language, version); }
public void GetItem_UsingItemIdLanguage3ParameterVersion_ReturnsItemName() { //Assign var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration")); var db = Sitecore.Configuration.Factory.GetDatabase("master"); var service = new SitecoreService(db); Guid id = new Guid("{6DE18DBD-0AF3-404A-8018-02B8A19515C1}"); var language = LanguageManager.GetLanguage("af-ZA"); Sitecore.Data.Version version = new Sitecore.Data.Version(1); int param1 = 1; string param2 = "2param"; DateTime param3 = DateTime.Now; //Act var result = service.GetItem<StubClass, int, string, DateTime>(id, language, version, param1, param2, param3); //Assert Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); Assert.AreEqual(language, result.Language); Assert.AreEqual(param1, result.Param1); Assert.AreEqual(param2, result.Param2); Assert.AreEqual(param3, result.Param3); Assert.AreEqual(version.Number, result.Version); }
public virtual Item GetSitecoreItem(ID itemId, Language language, Version version) { Assert.ArgumentNotNull(itemId, "itemId"); Assert.ArgumentNotNull(language, "language"); Assert.ArgumentNotNull(version, "version"); if (!this.FakeItems.ContainsKey(itemId)) { return null; } // TODO:[High] Avoid the templates resetting. Required to avoid sharing templates between unit tests. this.Database.Engines.TemplateEngine.Reset(); var fakeItem = this.FakeItems[itemId]; var itemVersion = version == Version.Latest ? Version.First : version; var fields = this.BuildItemFieldList(fakeItem, fakeItem.TemplateID, language, itemVersion); return ItemHelper.CreateInstance(this.database, fakeItem.Name, fakeItem.ID, fakeItem.TemplateID, fakeItem.BranchId, fields, language, itemVersion); }
public void GetItem_UsingItemPathLanguage4ParameterVersion_ReturnsItemName() { //Assign Guid id = Guid.NewGuid(); using (Db database = new Db { new Sitecore.FakeDb.DbItem("Target", new ID(id)) { new DbField("Value") { {"af-ZA", 1, "test"} } } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreService(database.Database); string path = "/sitecore/content/Target"; var language = LanguageManager.GetLanguage("af-ZA"); Version version = new Version(1); int param1 = 1; string param2 = "2param"; DateTime param3 = DateTime.Now; bool param4 = true; //Act var result = service.GetItem<StubClass, int, string, DateTime, bool>(path, language, version, param1, param2, param3, param4); //Assert Assert.IsNotNull(result); Assert.AreEqual(path, result.Path); Assert.AreEqual(language, result.Language); Assert.AreEqual(param1, result.Param1); Assert.AreEqual(param2, result.Param2); Assert.AreEqual(param3, result.Param3); Assert.AreEqual(param4, result.Param4); Assert.AreEqual(version.Number, result.Version); } }
public IStandardTemplateItem GetItem(ID itemId, Language language, Version version) { return _database.GetItem(itemId, language, version).AsStronglyTyped(); }
public IStandardTemplateItem GetItem(string path, Language language, Version version) { return _database.GetItem(path, language, version).AsStronglyTyped(); }
public void GetItem_UsingItemIdLanguage1ParameterVersion_ReturnsItemName() { //Assign Guid id = Guid.NewGuid(); using (Db database = new Db { new Sitecore.FakeDb.DbItem("Target", new ID(id)) { new DbField("Value") { {"af-ZA", 1, "test"} } } }) { var context = Context.Create(Utilities.CreateStandardResolver()); context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass))); var service = new SitecoreService(database.Database); Version version = new Version(1); var language = LanguageManager.GetLanguage("af-ZA"); int param1 = 1; //Act var result = service.GetItem<StubClass, int>(id, language, version, param1); //Assert Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); Assert.AreEqual(language, result.Language); Assert.AreEqual(param1, result.Param1); Assert.AreEqual(version.Number, result.Version); } }
public virtual IItem GetItem(string path, Language language, Version version) { return ItemFactory.BuildItem(_database.GetItem(path, language, version)); }
public virtual IItem GetItem(ID itemId, Language language, Version version) { return ItemFactory.BuildItem(_database.GetItem(itemId, language, version)); }
public Item[] GetSelectedItems(Language language, Version version) { List<Item> list = new List<Item>(); IDataView dataView = this.GetDataView(); if (dataView != null) { foreach (string str in this.GetSelectedIDs()) { if (!string.IsNullOrEmpty(str) && !(str == this.ID)) { string id = ShortID.Decode(str); Item item = dataView.GetItem(id, language, version); if (item != null) { list.Add(item); } } } } return list.ToArray(); }
public FieldList BuildItemFieldList(DbItem fakeItem, ID templateId, Language language, Version version) { // build a sequence of templates that the item inherits from var templates = this.ExpandTemplatesSequence(templateId); var fields = new FieldList(); foreach (var template in templates) { this.AddFieldsFromTemplate(fields, fakeItem, template, language, version); } // If the item is a Template item we also need to add the BaseTemplate field var fakeItemAsTemplate = fakeItem as DbTemplate; if (fakeItemAsTemplate != null && fakeItemAsTemplate.BaseIDs != null) { fields.Add(FieldIDs.BaseTemplate, string.Join("|", fakeItemAsTemplate.BaseIDs.ToList())); } return fields; }
public virtual Item GetSitecoreItem(ID itemId, Language language, Version version) { if (!this.FakeItems.ContainsKey(itemId)) { return null; } var fakeItem = this.FakeItems[itemId]; var fakeTemplate = this.GetFakeTemplate(fakeItem.TemplateID); var itemVersion = version == Version.Latest ? Version.First : version; var fields = this.GetFieldList(fakeItem.TemplateID, fakeItem.Name); foreach (var templateField in fakeTemplate.Fields) { var fieldId = templateField.ID; var value = string.Empty; if (fakeItem.Fields.InnerFields.ContainsKey(fieldId)) { var itemField = fakeItem.Fields[fieldId]; value = itemField.GetValue(language.Name, version.Number); } if (string.IsNullOrEmpty(value) && fakeTemplate.StandardValues.InnerFields.ContainsKey(fieldId)) { value = fakeTemplate.StandardValues[fieldId].Value; if (value == "$name") { value = fakeItem.Name; } } fields.Add(fieldId, value); } var item = ItemHelper.CreateInstance(fakeItem.Name, fakeItem.ID, fakeItem.TemplateID, fields, this.database, language, itemVersion); return item; }
private Sitecore.Data.Items.Item retrieveItem(ListviewItem listItem) { string path = listItem.Header; Sitecore.Globalization.Language lang = Sitecore.Globalization.Language.Current; Sitecore.Data.Version version = Sitecore.Data.Version.Latest; Sitecore.Data.Items.Item item = null; if (listItem.ColumnValues.Contains("lang")) { Sitecore.Globalization.Language.TryParse(listItem.ColumnValues["lang"].ToString(), out lang); } if (listItem.ColumnValues.Contains("version")) { version = new Sitecore.Data.Version(listItem.ColumnValues["version"].ToString()); } item = Properties.Db.GetItem(path, lang, version); if (item == null) { if (Properties.Db.HasContentItem) { path = "/sitecore/content/" + path; item = Properties.Db.GetItem(path, lang, version); if (item != null) { return item; } } throw new Exception("Item does not exist in such language"); } return item; }
public void ShouldGetItemFields([Greedy] FakeDataProvider sut, DbTemplate template, DbItem item, DbField field, Language language, Version version, CallContext context) { template.Fields.Add(field); item.Fields.Add(field); // ? item.TemplateID = template.ID; sut.DataStorage.GetFakeTemplate(template.ID).Returns(template); sut.DataStorage.GetFakeItem(item.ID).Returns(item); var def = new ItemDefinition(item.ID, item.Name, item.TemplateID, item.BranchId); var versionUri = new VersionUri(language, version); sut.GetItemFields(def, versionUri, context).Should().HaveCount(1); }
/// <summary> /// Fills the Versions ComboBox. /// </summary> /// <param name = "versionNumbers"></param> /// <param name = "item"></param> private void SetVersionsComboBox(Version[] versionNumbers, Item item) { //Set number to the current version number int number = item.Version.Number; //Set the version combobox for (int i = versionNumbers.Length - 1; i >= 0; i--) { Version version = versionNumbers[i]; ListItem child = new ListItem(); this.Version1.Controls.Add(child); child.ID = Control.GetUniqueID("ListItem"); child.Header = version.Number.ToString(); child.Value = version.Number.ToString(); if (version.Number == number) { child.Selected = true; } } }