Example #1
0
    public void GetSingleInvalidField()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;
      cmd.FieldName = "a field that doesn't exist";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure));
    }
Example #2
0
    public void GetSingleValidFieldById()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;
      cmd.FieldName = _testItem.Fields["text"].ID.ToString();

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(TEXT));
    }
Example #3
0
    public void GetSingleValidField()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;
      cmd.FieldName = "title";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(TITLE));
    }
Example #4
0
	  public void GetAllFields()
	  {
	    var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;

	    var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Contains.Substring("Title"));
      Assert.That(result.Message, Contains.Substring(TITLE));
      Assert.That(result.Message, Contains.Substring("Text"));
      Assert.That(result.Message, Contains.Substring("consectetur adipisicing elit, sed do eiusmod tempor incididunt"));
      Assert.That(result.Message, Contains.Substring("__Created"));
      Assert.That(result.Message, Contains.Substring("__Created by"));
	  }
Example #5
0
    public override CommandResult Run()
    {
      var output = new StringBuilder();

      // Get the field name
      if (string.IsNullOrEmpty(Field))
        return new CommandResult(CommandStatus.Failure, Constants.Messages.MissingRequiredParameter.FormatWith("field"));

      // Get the field value
      if (Value == null && !Reset)
        return new CommandResult(CommandStatus.Failure, Constants.Messages.MissingRequiredParameter.FormatWith("value"));

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

        Item item = base.Context.CurrentItem;

        if (item.Fields[Field] != null)
        {
          // Check if we're using a replacement
          if (Value != null && Value.Contains("$prev"))
          {
            string previousValue = item.Fields[Field].Value;
            Value = Value.Replace("$prev", previousValue);
          }

          // Add a new version and move item to it
          if (!NoVersion)
          {
            item = item.Versions.AddVersion();
            base.Context.CurrentItem = item;
          }

          item.Editing.BeginEdit();
          if (Reset)
            item.Fields[Field].Reset();
          else
            item.Fields[Field].Value = Value;
          item.Editing.EndEdit(!NoStats, Silent);

          // Show new version
          Formatter.PrintLine("Version " + item.Version, output);

          // Show new field value
          var gf = new GetFields();
          gf.Initialise(base.Context, Formatter);
          gf.FieldName = Field;
          gf.Path = item.ID.ToString();
          
          var result = gf.Run();

          Formatter.PrintDefinition(Field, result.ToString(), output);
        }
        else
        {
          return new CommandResult(CommandStatus.Failure, "Failed to find field '" + Field + "'");
        }
      }

      return new CommandResult(CommandStatus.Success, output.ToString());
    }
Example #6
0
    public void GetSingleInvalidFieldById()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;
      cmd.FieldName = ID.NewID.ToString();

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure));
    }
Example #7
0
    public void GetSingleFieldRelativePath()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem.Parent.Parent;
      cmd.FieldName = "text";
      cmd.Path = _testItem.Parent.Name + "/" + _testItem.Name;

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(TEXT));
    }
Example #8
0
    public void GetSingleFieldAbsolutePath()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem.Database.GetItem(ItemIDs.ContentRoot);
      cmd.FieldName = "Text";
      cmd.Path = _testItem.Paths.FullPath;

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(TEXT));
    }
Example #9
0
    public void GetSingleFieldAbsolutePathByID()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem.Database.GetRootItem();
      cmd.FieldName = "text";
      cmd.Path = _testItem.ID.ToString();

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(TEXT));
    }
Example #10
0
    public void GetSingleValidFieldWithoutSVRecipricol()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;
      cmd.FieldName = "__default workflow";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(result.Message, Is.EqualTo(Constants.IDs.SampleWorkflowId.ToString()));
    }
Example #11
0
    public void GetSingleValidFieldWithoutSV()
    {
      var cmd = new Cmd.GetFields();
      InitCommand(cmd);

      _context.CurrentItem = _testItem;
      cmd.FieldName = "__default workflow";
      cmd.NoStandardValues = true;

      var result = cmd.Run();

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