public void GetLanguagesReturnsEmptyCollectionIfNoLanguagesSwitched(
     SwitchingLanguageDataProvider sut,
     CallContext context)
 {
     sut.GetLanguages(context)
     .Should().BeEmpty();
 }
 public void GetLanguagesReturnsEmptyCollectionIfNoLanguagesSwitched(
     SwitchingLanguageDataProvider sut,
     CallContext context)
 {
     sut.GetLanguages(context)
         .Should().BeEmpty();
 }
예제 #3
0
        public override ID SelectSingleID(string query, CallContext context)
        {
            query = query.Replace("fast:", string.Empty);
            var item = Query.SelectSingleItem(query, this.Database);

            return(item != null ? item.ID : ID.Null);
        }
 public override ItemDefinition GetItemDefinition(ID itemId, Sitecore.Data.DataProviders.CallContext context)
 {
     if (_cacheClearer == null)
     {
         lock (_lockObj)
         {
             if (_cacheClearer == null)
             {
                 _cacheClearer = new MongoOplogCacheClearer(this.ConnectionString, this.MongoDatabase, this.Collection, this.MappingCollection);
                 new Thread(_cacheClearer.Start).Start();
             }
         }
     }
     if (!_initialized)
     {
         lock (_lockObj)
         {
             if (!_initialized)
             {
                 _cacheClearer.AddDatabase(this.Database);
                 _initialized = true;
             }
         }
     }
     return(null);
 }
예제 #5
0
        public override IDList SelectIDs(string query, CallContext context)
        {
            query = query.Replace("fast:", string.Empty);
            var items = Query.SelectItems(query, this.Database);

            return(items != null?IDList.Build(items.Select(i => i.ID).ToArray()) : new IDList());
        }
    public override bool AddToPublishQueue(ID itemId, string action, DateTime date, CallContext context)
    {
      if (this.publishQueue.Value == null)
      {
        this.publishQueue.Value = new List<PublishQueueItem>();
      }

      this.publishQueue.Value.Add(new PublishQueueItem(itemId, date));
      return true;
    }
    public override IdCollection GetTemplateItemIds(CallContext context)
    {
      if (this.DataStorage() == null)
      {
        return new IdCollection();
      }

      var ids = this.DataStorage().GetFakeTemplates().Select(t => t.ID).ToArray();

      return new IdCollection { ids };
    }
    public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
    {
      if (this.DataStorage() == null)
      {
        return null;
      }

      var item = this.DataStorage().GetFakeItem(itemId);

      return item != null ? new ItemDefinition(itemId, item.Name, item.TemplateID, ID.Null) : null;
    }
예제 #9
0
        public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
        {
            if (this.DataStorage == null)
            {
                return(null);
            }

            var item = this.DataStorage.GetFakeItem(itemId);

            return(item != null ? new ItemDefinition(itemId, item.Name, item.TemplateID, ID.Null) : null);
        }
예제 #10
0
        /// <summary>
        /// Get the property.
        /// </summary>
        /// <param name="name">The property name.</param>
        /// <param name="context">The context. Ignored.</param>
        /// <returns>The property value if exists. Otherwise null.</returns>
        public override string GetProperty(string name, CallContext context)
        {
            Assert.ArgumentNotNull(name, "name");
            var currentProp = this.properties.Value;

            if (currentProp == null)
            {
                return(null);
            }

            return(currentProp.ContainsKey(name) ? currentProp[name] : null);
        }
예제 #11
0
    public override bool ChangeTemplate(ItemDefinition itemDefinition, TemplateChangeList changes, CallContext context)
    {
      Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
      Assert.ArgumentNotNull(changes, "changes");

      var item = this.DataStorage().GetFakeItem(itemDefinition.ID);
      Assert.IsNotNull(item, "Unable to change item template. The item '{0}' is not found.", itemDefinition.ID);
      Assert.IsNotNull(changes.Target, "Unable to change item template. The target template is not found.");

      item.TemplateID = changes.Target.ID;
      return true;
    }
예제 #12
0
        public override bool DeleteItem(ItemDefinition itemDefinition, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            if (item == null)
            {
                return(false);
            }

            return(this.DataStorage.RemoveFakeItem(item.ID));
        }
예제 #13
0
        public override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            if (itemDefinition.ID == ItemIDs.RootID)
            {
                return(null);
            }

            var fakeItem = this.DataStorage.GetFakeItem(itemDefinition.ID);

            return(fakeItem?.ParentID);
        }
예제 #14
0
        public override IdCollection GetTemplateItemIds(CallContext context)
        {
            if (this.DataStorage == null)
            {
                return(new IdCollection());
            }

            var ids = this.DataStorage.GetFakeTemplates().Select(t => t.ID).ToArray();

            return(new IdCollection {
                ids
            });
        }
 public void GetLanguagesReturnsLanguagesIfSwitched(
     SwitchingLanguageDataProvider sut,
     CallContext context)
 {
     var en = Language.Parse("en");
     var da = Language.Parse("da");
     var contextLanguages = new DbLanguages(en, da);
     using (new Switcher<DbLanguages>(contextLanguages))
     {
         sut.GetLanguages(context)
             .ShouldAllBeEquivalentTo(new[] { en, da });
     }
 }
    public override IDList GetPublishQueue(DateTime @from, DateTime to, CallContext context)
    {
      if (this.publishQueue.Value == null)
      {
        return new IDList();
      }

      return IDList.Build(
        this.publishQueue.Value
          .Where(i => i.Date >= @from && i.Date <= to)
          .Select(i => i.ItemId)
          .Distinct()
          .ToArray());
    }
        public void GetLanguagesReturnsLanguagesIfSwitched(
            SwitchingLanguageDataProvider sut,
            CallContext context)
        {
            var en = Language.Parse("en");
            var da = Language.Parse("da");
            var contextLanguages = new DbLanguages(en, da);

            using (new Switcher <DbLanguages>(contextLanguages))
            {
                sut.GetLanguages(context)
                .ShouldAllBeEquivalentTo(new[] { en, da });
            }
        }
예제 #18
0
        public override IDList GetPublishQueue(DateTime @from, DateTime to, CallContext context)
        {
            if (this.publishQueue.Value == null)
            {
                return(new IDList());
            }

            return(IDList.Build(
                       this.publishQueue.Value
                       .Where(i => i.Date >= @from && i.Date <= to)
                       .Select(i => i.ItemId)
                       .Distinct()
                       .ToArray()));
        }
예제 #19
0
        public override TemplateCollection GetTemplates(CallContext context)
        {
            var templates = new TemplateCollection();

            if (this.DataStorage == null)
            {
                return(templates);
            }

            foreach (var ft in this.DataStorage.GetFakeTemplates())
            {
                templates.Add(this.BuildTemplate(ft, templates));
            }

            return(templates);
        }
예제 #20
0
        public override ID ResolvePath(string itemPath, CallContext context)
        {
            var storage = this.DataStorage;

            // TODO: Move the validation to a global place
            Assert.IsNotNull(storage, "Sitecore.FakeDb.Db instance has not been initialized.");

            if (ID.IsID(itemPath))
            {
                return(new ID(itemPath));
            }

            itemPath = StringUtil.RemovePostfix("/", itemPath);
            var item = storage.GetFakeItems().FirstOrDefault(fi => string.Compare(fi.FullPath, itemPath, StringComparison.OrdinalIgnoreCase) == 0);

            return(item?.ID);
        }
예제 #21
0
        /// <summary>
        /// Sets the property.
        /// </summary>
        /// <param name="name">The property name.</param>
        /// <param name="value">The property value.</param>
        /// <param name="context">The context. Ignored.</param>
        /// <returns>Always True.</returns>
        public override bool SetProperty(string name, string value, CallContext context)
        {
            Assert.ArgumentNotNull(name, "name");
            var currentProp = this.properties.Value;

            if (currentProp == null)
            {
                this.properties.Value = new Dictionary <string, string> {
                    { name, value }
                };
            }
            else
            {
                this.properties.Value[name] = value;
            }

            return(true);
        }
예제 #22
0
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            var childIds = new IDList();
            var item     = this.DataStorage.GetFakeItem(itemDefinition.ID);

            if (item == null)
            {
                return(childIds);
            }

            foreach (var child in item.Children)
            {
                childIds.Add(child.ID);
            }

            return(childIds);
        }
예제 #23
0
    public override TemplateCollection GetTemplates(CallContext context)
    {
      var templates = new TemplateCollection();

      foreach (var ft in this.DataStorage.FakeTemplates.Values)
      {
        var builder = new Template.Builder(ft.Name, ft.ID, new TemplateCollection());
        var section = builder.AddSection("Data", ID.NewID);

        foreach (var field in ft.Fields)
        {
          section.AddField(field.Name, field.ID);
        }

        templates.Add(builder.Template);
      }

      return templates;
    }
예제 #24
0
    public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context)
    {
      var list = new List<VersionUri>();
      var versions = new VersionUriList();

      var item = this.DataStorage().GetFakeItem(itemDefinition.ID);
      if (item == null)
      {
        return versions;
      }

      foreach (var field in item.Fields)
      {
        foreach (var fieldLang in field.Values)
        {
          var language = fieldLang.Key;

          foreach (var fieldVer in fieldLang.Value)
          {
            var version = fieldVer.Key;

            if (list.Any(l => l.Language.Name == language && l.Version.Number == version))
            {
              continue;
            }

            list.Add(new VersionUri(Language.Parse(language), new Version(version)));
          }
        }
      }

      foreach (var version in list)
      {
        versions.Add(version);
      }

      return versions;
    }
예제 #25
0
        public override bool RemoveVersion(ItemDefinition itemDefinition, VersionUri version, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(version, "version");

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            Assert.IsNotNull(item, "Unable to remove item version. The item '{0}' is not found.", itemDefinition.ID);

            return(item.RemoveVersion(version.Language.Name, version.Version.Number));
        }
예제 #26
0
 public override LanguageCollection GetLanguages(CallContext context)
 {
     return(new LanguageCollection());
 }
예제 #27
0
        public override bool MoveItem(ItemDefinition itemDefinition, ItemDefinition destination, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(destination, "destination");

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            Assert.IsNotNull(item, "Unable to move item. The item '{0}' is not found.", itemDefinition.ID);

            var newDestination = this.DataStorage.GetFakeItem(destination.ID);

            Assert.IsNotNull(newDestination, "Unable to move item. The destination item '{0}' is not found.", destination.ID);

            var oldParent = this.DataStorage.GetFakeItem(item.ParentID);

            oldParent?.Children.Remove(item);
            newDestination.Children.Add(item);

            return(true);
        }
예제 #28
0
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            var storage = this.DataStorage;
            var item    = storage.GetFakeItem(itemDefinition.ID);

            if (item == null)
            {
                return(null);
            }

            return(storage.BuildItemFieldList(item, itemDefinition.TemplateID, versionUri.Language, versionUri.Version));
        }
예제 #29
0
    public override TemplateCollection GetTemplates(CallContext context)
    {
      var templates = new TemplateCollection();

      if (this.DataStorage() == null)
      {
        return templates;
      }

      foreach (var ft in this.DataStorage().GetFakeTemplates())
      {
        templates.Add(this.BuildTemplate(ft, templates));
      }

      return templates;
    }
예제 #30
0
        public override bool AddToPublishQueue(ID itemId, string action, DateTime date, CallContext context)
        {
            if (this.publishQueue.Value == null)
            {
                this.publishQueue.Value = new List <PublishQueueItem>();
            }

            this.publishQueue.Value.Add(new PublishQueueItem(itemId, date));
            return(true);
        }
예제 #31
0
        public override bool ChangeTemplate(ItemDefinition itemDefinition, TemplateChangeList changes, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(changes, "changes");

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            Assert.IsNotNull(item, "Unable to change item template. The item '{0}' is not found.", itemDefinition.ID);
            Assert.IsNotNull(changes.Target, "Unable to change item template. The target template is not found.");

            item.TemplateID = changes.Target.ID;
            return(true);
        }
예제 #32
0
 public override bool AddToPublishQueue(ID itemId, string action, DateTime date, string language, CallContext context)
 {
     return(this.AddToPublishQueue(itemId, action, date, context));
 }
예제 #33
0
    public override IDList SelectIDs(string query, CallContext context)
    {
      query = query.Replace("fast:", string.Empty);
      var items = Query.SelectItems(query, this.Database);

      return items != null ? IDList.Build(items.Select(i => i.ID).ToArray()) : new IDList();
    }
예제 #34
0
 public override Stream GetBlobStream(Guid blobId, CallContext context)
 {
     return(this.DataStorage.GetBlobStream(blobId));
 }
    public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
    {
      var storage = this.DataStorage;
      var item = storage.GetFakeItem(itemDefinition.ID);
      if (item == null)
      {
        return null;
      }

      return storage.BuildItemFieldList(item, itemDefinition.TemplateID, versionUri.Language, versionUri.Version);
    }
 public override LanguageCollection GetLanguages(CallContext context)
 {
   return new LanguageCollection();
 }
예제 #37
0
        public override bool CreateItem(ID itemId, string itemName, ID templateId, ItemDefinition parent, CallContext context)
        {
            Assert.ArgumentNotNull(itemId, "itemId");
            Assert.ArgumentNotNull(itemName, "itemName");
            Assert.ArgumentNotNull(templateId, "templateId");
            Assert.ArgumentNotNull(parent, "parent");

            var item = new DbItem(itemName, itemId, templateId)
            {
                ParentID = parent.ID
            };

            this.DataStorage.AddFakeItem(item);

            // TODO: Should not require the version removing.
            item.RemoveVersion(Language.Current.Name);

            return(true);
        }
    /// <summary>
    /// Sets the property.
    /// </summary>
    /// <param name="name">The property name.</param>
    /// <param name="value">The property value.</param>
    /// <param name="context">The context. Ignored.</param>
    /// <returns>Always True.</returns>
    public override bool SetProperty(string name, string value, CallContext context)
    {
      Assert.ArgumentNotNull(name, "name");
      var currentProp = this.properties.Value;
      if (currentProp == null)
      {
        this.properties.Value = new Dictionary<string, string> { { name, value } };
      }
      else
      {
        this.properties.Value[name] = value;
      }

      return true;
    }
예제 #39
0
 public override LanguageCollection GetLanguages(CallContext context)
 {
   return new LanguageCollection { Language.Parse("en") };
 }
예제 #40
0
    public override IdCollection GetTemplateItemIds(CallContext context)
    {
      var ids = this.DataStorage.FakeTemplates.Select(t => t.Key).ToArray();

      return new IdCollection { ids };
    }
예제 #41
0
        public override bool SaveItem(ItemDefinition itemDefinition, ItemChanges changes, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(changes, "changes");

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            if (item == null)
            {
                return(false);
            }

            var newName = changes.Properties
                          .Where(p => p.Key == "name")
                          .Select(p => p.Value.Value.ToString()).ToList();

            if (newName.Any())
            {
                var fullPath = item.FullPath;
                if (!string.IsNullOrEmpty(fullPath) && fullPath.Contains(item.Name))
                {
                    item.FullPath = fullPath.Substring(0, fullPath.LastIndexOf(item.Name, StringComparison.Ordinal)) + newName.First();
                }

                item.Name = newName.First();
            }

            if (changes.HasFieldsChanged)
            {
                foreach (FieldChange change in changes.FieldChanges)
                {
                    if (item.Fields.ContainsKey(change.FieldID))
                    {
                        item.Fields[change.FieldID]
                        .SetValue(change.Language.Name, change.Version.Number, change.Value);
                    }
                    else
                    {
                        var newField = new DbField(change.FieldID);
                        newField.SetValue(change.Language.Name, change.Version.Number, change.Value);
                        item.Fields.Add(newField);
                    }
                }
            }

            return(false);
        }
예제 #42
0
 public override LanguageCollection GetLanguages(CallContext context)
 {
     return(new LanguageCollection {
         Language.Parse("en")
     });
 }
 public override bool AddToPublishQueue(ID itemId, string action, DateTime date, string language, CallContext context)
 {
   return this.AddToPublishQueue(itemId, action, date, context);
 }
    /// <summary>
    /// Get the property.
    /// </summary>
    /// <param name="name">The property name.</param>
    /// <param name="context">The context. Ignored.</param>
    /// <returns>The property value if exists. Otherwise null.</returns>
    public override string GetProperty(string name, CallContext context)
    {
      Assert.ArgumentNotNull(name, "name");
      var currentProp = this.properties.Value;
      if (currentProp == null)
      {
        return null;
      }

      return currentProp.ContainsKey(name) ? currentProp[name] : null;
    }
예제 #45
0
        public override bool SetBlobStream(Stream stream, Guid blobId, CallContext context)
        {
            this.DataStorage.SetBlobStream(blobId, stream);

            return(true);
        }
예제 #46
0
        public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context)
        {
            var list     = new List <VersionUri>();
            var versions = new VersionUriList();

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            if (item == null)
            {
                return(versions);
            }

            foreach (var field in item.Fields)
            {
                foreach (var fieldLang in field.Values)
                {
                    var language = fieldLang.Key;

                    foreach (var fieldVer in fieldLang.Value)
                    {
                        var version = fieldVer.Key;

                        if (list.Any(l => l.Language.Name == language && l.Version.Number == version))
                        {
                            continue;
                        }

                        list.Add(new VersionUri(Language.Parse(language), Version.Parse(version)));
                    }
                }
            }

            foreach (var version in list)
            {
                versions.Add(version);
            }

            return(versions);
        }
예제 #47
0
        public override int AddVersion(ItemDefinition itemDefinition, VersionUri baseVersion, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(baseVersion, "baseVersion");

            var item = this.DataStorage.GetFakeItem(itemDefinition.ID);

            Assert.IsNotNull(item, "Unable to add item version. The item '{0}' is not found.", itemDefinition.ID);

            item.AddVersion(baseVersion.Language.Name, baseVersion.Version.Number);
            return(item.GetVersionCount(baseVersion.Language.Name));
        }
예제 #48
0
    public override ID SelectSingleID(string query, CallContext context)
    {
      query = query.Replace("fast:", string.Empty);
      var item = Query.SelectSingleItem(query, this.Database);

      return item != null ? item.ID : ID.Null;
    }
예제 #49
0
        public override bool CopyItem(ItemDefinition source, ItemDefinition destination, string copyName, ID copyId, CallContext context)
        {
            Assert.ArgumentNotNull(source, "source");
            Assert.ArgumentNotNull(destination, "destination");
            Assert.ArgumentNotNull(copyName, "copyName");
            Assert.ArgumentNotNull(copyId, "copyId");

            var copy = new DbItem(copyName, copyId, source.TemplateID)
            {
                ParentID = destination.ID
            };
            var sourceDbItem = this.DataStorage.GetFakeItem(source.ID);

            Assert.IsNotNull(sourceDbItem, "Unable to copy item '{0}'. The source item '{1}' is not found.", copyName, source.ID);

            CopyFields(sourceDbItem, copy);
            this.DataStorage.AddFakeItem(copy);

            return(true);
        }
 /// <summary>
 /// Gets a list of <see cref="Database"/> languages.
 /// </summary>
 /// <param name="context">Not used.</param>
 /// <returns>
 /// Empty <see cref="LanguageCollection"/> if no <see cref="DbLanguages"/>
 /// set via <see cref="Switcher{DbLanguages}"/>; otherwise the list of
 /// configured languages.
 /// </returns>
 public override LanguageCollection GetLanguages(CallContext context)
 {
     return Switcher<DbLanguages>.CurrentValue == null
       ? new LanguageCollection()
       : Switcher<DbLanguages>.CurrentValue.GetLanguages();
 }