Пример #1
0
    public void MissingField()
    {
      var cmd = new Cmd.SetField();
      InitCommand(cmd);

      _context.CurrentItem = _testRoot;
      cmd.Value = "lorem";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure));
    }
Пример #2
0
    public void InvalidField()
    {
      var item = _testRoot.Add("itemInvalidField" + DateUtil.IsoNow, _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]);

      var cmd = new Cmd.SetField();
      InitCommand(cmd);

      _context.CurrentItem = item;
      cmd.Field = "bler";
      cmd.Value = "lorem";

      var result = cmd.Run();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Failure));
    }
Пример #3
0
    public void ClearField()
    {
      var item = _testRoot.Add("itemTOClearField" + DateUtil.IsoNow, _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]);
      using (new EditContext(item))
      {
        item["title"] = "lorem";
      }

      var cmd = new Cmd.SetField();
      InitCommand(cmd);

      _context.CurrentItem = item;
      cmd.Field = "title";
      cmd.Reset = true;
      cmd.NoVersion = true;

      var result = cmd.Run();

      item.Reload();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(item["title"], Is.EqualTo("$name")); // This is the standard value fir the title field on the template
    }
Пример #4
0
    public void Ideal()
    {
      var item = _testRoot.Add("itemIdeal" + DateUtil.IsoNow, _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]);
      using (new EditContext(item))
      {
        item["title"] = "lorem";
      }

      var cmd = new Cmd.SetField();
      InitCommand(cmd);

      _context.CurrentItem = item;
      cmd.Field = "title";
      cmd.Value = "ipsum";

      var result = cmd.Run();
      item = item.Versions.GetLatestVersion();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(item["title"], Is.EqualTo("ipsum"));
      Assert.That(item.Version.Number, Is.EqualTo(2));
      Assert.That(result.Message, Is.StringContaining("title"));
      Assert.That(result.Message, Is.StringContaining("ipsum"));
    }
Пример #5
0
    public void IdealNoStats()
    {
      var item = _testRoot.Add("itemIdealNoStats" + DateUtil.IsoNow, _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId]);
      using (new EditContext(item))
      {
        item["title"] = "lorem";
      }

      var cmd = new Cmd.SetField();
      InitCommand(cmd);

      _context.CurrentItem = item;
      cmd.Field = "title";
      cmd.Value = "ipsum";
      cmd.NoStats = true;
      cmd.NoVersion = true; // A new version would get a different updated date

      var updatedDate = item.Statistics.Updated;

      var result = cmd.Run();
      item.Reload();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(item["title"], Is.EqualTo("ipsum"));
      Assert.That(item.Version.Number, Is.EqualTo(1));
      Assert.That(item.Statistics.Updated, Is.EqualTo(updatedDate));
      Assert.That(result.Message, Is.StringContaining("title"));
      Assert.That(result.Message, Is.StringContaining("ipsum"));
    }
Пример #6
0
    public void ResetField()
    {
      var template = _context.CurrentDatabase.Templates[Constants.IDs.DocTemplateId];
      var item = _testRoot.Add("itemResetField" + DateUtil.IsoNow, template);
      using (new EditContext(item))
      {
        item["title"] = "lorem";
      }

      var cmd = new Cmd.SetField();
      InitCommand(cmd);

      _context.CurrentItem = item;
      cmd.Field = "title";
      cmd.Reset = true;

      var result = cmd.Run();
      item = item.Versions.GetLatestVersion();

      Assert.That(result.Status, Is.EqualTo(CommandStatus.Success));
      Assert.That(item["title"], Is.EqualTo(template.StandardValues["title"]));
      Assert.That(item.Version.Number, Is.EqualTo(2));
    }