コード例 #1
0
ファイル: GetAttributes.cs プロジェクト: KerwinMa/revolver
    public void IDOnly()
    {
      var cmd = new Cmd.GetAttributes();
      InitCommand(cmd);

      _context.CurrentItem = _testContent;
      cmd.Attribute = "id";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(_testContent.ID.ToString()));
    }
コード例 #2
0
ファイル: GetAttributes.cs プロジェクト: KerwinMa/revolver
    public void TemplateOnlyAbsolute()
    {
      var cmd = new Cmd.GetAttributes();
      InitCommand(cmd);

      _context.CurrentItem = _context.CurrentDatabase.GetRootItem();
      cmd.Attribute = "templatE";
      cmd.Path = _testContent.Paths.FullPath;

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(_testContent.Template.InnerItem.Paths.FullPath));
    }
コード例 #3
0
ファイル: GetAttributes.cs プロジェクト: KerwinMa/revolver
    public void NameOnlyRelative()
    {
      var cmd = new Cmd.GetAttributes();
      InitCommand(cmd);

      _context.CurrentItem = _testContent.Parent;
      cmd.Attribute = "NAME";
      cmd.Path = _testContent.Name;

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(_testContent.Name));
    }
コード例 #4
0
ファイル: GetAttributes.cs プロジェクト: KerwinMa/revolver
    public void AllAttributes()
    {
      var cmd = new Cmd.GetAttributes();
      InitCommand(cmd);

      _context.CurrentItem = _testContent;

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.StringMatching(@".*id\s+" + _testContent.ID.ToString() + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*name\s+" + _testContent.Name + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*key\s+" + _testContent.Key + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*template\s+" + _testContent.Template.InnerItem.Paths.FullPath + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*templateid\s+" + _testContent.TemplateID.ToString() + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*branch\s+" + Revolver.Core.Constants.NotDefinedLiteral + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*branchid\s+" + _testContent.BranchId.ToString() + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*language\s+.*" + _testContent.Language.Name + ".*"));
      Assert.That(result.Message, Is.StringMatching(@".*version\s+" + _testContent.Version.Number + ".*"));
    }
コード例 #5
0
ファイル: FindItems.cs プロジェクト: KerwinMa/revolver
    protected virtual bool FilterByAttribute(Item item)
    {
      if (string.IsNullOrEmpty(FindByAttribute.Key) || string.IsNullOrEmpty(FindByAttribute.Value))
        return true;

      if (_attributeRegex == null)
      {
        var options = RegexOptions.Compiled;
        if (!FindByAttributeCaseSensitive)
          options |= RegexOptions.IgnoreCase;

        _attributeRegex = new Regex(FindByAttribute.Value, options);
      }

      var attrcmd = new GetAttributes();
      attrcmd.Initialise(Context, Formatter);
      attrcmd.Attribute = FindByAttribute.Key;
      attrcmd.Path = item.ID.ToString();

      var result = attrcmd.Run();
      if (result.Status == CommandStatus.Success)
      {
        var output = result.Message;
        return _attributeRegex.IsMatch(output);
      }

      return false;
    }
コード例 #6
0
ファイル: SetAttribute.cs プロジェクト: KerwinMa/revolver
    public override CommandResult Run()
    {
      if (string.IsNullOrEmpty(Attribute))
        return new CommandResult(CommandStatus.Failure, Constants.Messages.MissingRequiredParameter.FormatWith("attribute"));

      if (string.IsNullOrEmpty(Value))
        return new CommandResult(CommandStatus.Failure, Constants.Messages.MissingRequiredParameter.FormatWith("value"));

      // resolve template
      TemplateItem template = null;

      if (Attribute == "template")
      {
        template = Context.CurrentDatabase.GetItem(Value);
        if (template == null)
        {
          if (ID.IsID(Attribute))
            return new CommandResult(CommandStatus.Failure, "Failed to find template with ID '" + Attribute + "'");
          else
            return new CommandResult(CommandStatus.Failure, "Failed to find template '" + Attribute + "'");
        }
      }

      string toRet = string.Empty;

      using (var cs = new ContextSwitcher(Context, Path))
      {
        if (cs.Result.Status != CommandStatus.Success)
          return cs.Result;

        string query = Attribute;

        Item item = Context.CurrentItem;
        item.Editing.BeginEdit();

        switch (Attribute)
        {
          case "name":
            Value = Value.Replace("$prev", item.Name);
            item.Name = Value;
            break;

          case "template":
            item.TemplateID = template.ID;
            if (Value.StartsWith("{"))
              query += "id";
            break;

          default:
            return new CommandResult(CommandStatus.Failure, "Unknown attribute " + Attribute);
        }

        item.Editing.EndEdit();

        GetAttributes ga = new GetAttributes();
        ga.Initialise(Context, Formatter);
        ga.Attribute = query;
        CommandResult result = ga.Run();
        StringBuilder sb = new StringBuilder(200);
        Formatter.PrintDefinition(query, result.ToString(), sb);
        toRet = sb.ToString();
      }

      return new CommandResult(CommandStatus.Success, toRet);
    }
コード例 #7
0
ファイル: GetAttributes.cs プロジェクト: KerwinMa/revolver
    public void InvalidAttribute()
    {
      var cmd = new Cmd.GetAttributes();
      InitCommand(cmd);

      _context.CurrentItem = _testContent;
      cmd.Attribute = "bler";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure));
    }
コード例 #8
0
ファイル: GetAttributes.cs プロジェクト: KerwinMa/revolver
    public void KeyOnlyRelativeAncestor()
    {
      var cmd = new Cmd.GetAttributes();
      InitCommand(cmd);

      _context.CurrentItem = _testContent.Axes.SelectSingleItem("Proteus/child1");
      cmd.Attribute = "key";
      cmd.Path = "../..";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(_testContent.Key));
    }