public void ShouldUpdateExistingItemInDataStorage(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
        {
            // arrange
            var originalItem = new DbItem("original item", itemId)
            {
                new DbField("Title", fieldId)
                {
                    Value = "original title"
                }
            };

            sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
            sut.DataStorage.GetFakeTemplate(null).ReturnsForAnyArgs(new DbTemplate("Sample", templateId));

            var fields = new FieldList {
                { fieldId, "updated title" }
            };
            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

            sut.Initialize(updatedItem);

            // act
            ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            originalItem.Name.Should().Be("updated item");
            originalItem.Fields[fieldId].Value.Should().Be("updated title");
        }
        public void ShouldThrowExceptionIfNoFieldFoundInOriginalItem(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
        {
            // arrange
            var originalItem = new DbItem("original item", itemId)
            {
                new DbField("Title")
            };

            sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
            sut.DataStorage.GetFakeTemplate(null).ReturnsForAnyArgs(new DbTemplate("Sample", templateId));

            var fields = new FieldList {
                { fieldId, "updated title" }
            };
            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

            sut.Initialize(updatedItem);

            // act
            Action action = () => ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            action
            .ShouldThrow <TargetInvocationException>()
            .WithInnerException <InvalidOperationException>()
            .WithInnerMessage("Item field not found. Item: 'updated item', '{0}'; field: '{1}'.".FormatWith(itemId, fieldId));
        }
        public void ShouldAddMissingFieldToItemIfFieldExistsInTemplate(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
        {
            // arrange
            var template = new DbTemplate("Sample", templateId)
            {
                fieldId
            };
            var originalItem = new DbItem("original item", itemId, templateId);

            sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
            sut.DataStorage.GetFakeTemplate(templateId).Returns(template);

            var fields = new FieldList {
                { fieldId, "updated title" }
            };
            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

            sut.Initialize(updatedItem);

            // act
            ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            originalItem.Name.Should().Be("updated item");
            originalItem.Fields[fieldId].Value.Should().Be("updated title");
        }
        public void ShouldUpdateBranchId(SaveItemCommand sut, DbItem item, ID branchId, FieldList fields, Language language)
        {
            // arrange
            sut.DataStorage.GetFakeItem(item.ID).Returns(item);
            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", item.ID, ID.NewID, branchId, fields, language, Version.Parse(0));

            sut.Initialize(updatedItem);

            // act
            ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            item.BranchId.Should().Be(branchId);
        }
        public void ShouldNotUpdateFieldsIfItemVersionIsZero(SaveItemCommand sut, DbItem item, FieldList fields, Language language)
        {
            // arrange
            sut.DataStorage.GetFakeItem(item.ID).Returns(item);
            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", item.ID, ID.NewID, ID.Null, fields, language, Version.Parse(0));

            sut.Initialize(updatedItem);

            // act
            Action action = () => ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            action.ShouldNotThrow();
        }
    public void ShouldUpdateExistingItemInDataStorage(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
    {
      // arrange
      var originalItem = new DbItem("original item", itemId) { new DbField("Title", fieldId) { Value = "original title" } };
      sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
      sut.DataStorage.GetFakeTemplate(null).ReturnsForAnyArgs(new DbTemplate("Sample", templateId));

      var fields = new FieldList { { fieldId, "updated title" } };
      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

      sut.Initialize(updatedItem);

      // act
      ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      originalItem.Name.Should().Be("updated item");
      originalItem.Fields[fieldId].Value.Should().Be("updated title");
    }
    public void ShouldThrowExceptionIfNoTemplateFound(SaveItemCommand sut, ID itemId, ID templateId)
    {
      // arrange
      var originalItem = new DbItem("original item", itemId, templateId);
      sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
      sut.DataStorage.GetFakeTemplate(templateId).Returns(x => null);

      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, templateId);

      sut.Initialize(updatedItem);

      // act
      Action action = () => ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      action
        .ShouldThrow<TargetInvocationException>()
        .WithInnerException<InvalidOperationException>()
        .WithInnerMessage("Item template not found. Item: 'updated item', '{0}'; template: '{1}'.".FormatWith(itemId, templateId));
    }
    public void ShouldThrowExceptionIfNoFieldFoundInOriginalItem(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
    {
      // arrange
      var originalItem = new DbItem("original item", itemId) { new DbField("Title") };
      sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
      sut.DataStorage.GetFakeTemplate(null).ReturnsForAnyArgs(new DbTemplate("Sample", templateId));

      var fields = new FieldList { { fieldId, "updated title" } };
      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

      sut.Initialize(updatedItem);

      // act
      Action action = () => ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      action
        .ShouldThrow<TargetInvocationException>()
        .WithInnerException<InvalidOperationException>()
        .WithInnerMessage("Item field not found. Item: 'updated item', '{0}'; field: '{1}'.".FormatWith(itemId, fieldId));
    }
        public void ShouldThrowExceptionIfNoTemplateFound(SaveItemCommand sut, ID itemId, ID templateId)
        {
            // arrange
            var originalItem = new DbItem("original item", itemId, templateId);

            sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
            sut.DataStorage.GetFakeTemplate(templateId).Returns(x => null);

            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, templateId);

            sut.Initialize(updatedItem);

            // act
            Action action = () => ReflectionUtil.CallMethod(sut, "DoExecute");

            // assert
            action
            .ShouldThrow <TargetInvocationException>()
            .WithInnerException <InvalidOperationException>()
            .WithInnerMessage("Item template not found. Item: 'updated item', '{0}'; template: '{1}'.".FormatWith(itemId, templateId));
        }
        public void ShouldUpdateItemPathAfterRename(string originalPath, string expectedPath, SaveItemCommand sut, ID itemId, ID templateId)
        {
            // arrange
            var originalItem = new DbItem("original item")
            {
                FullPath = originalPath
            };

            sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
            sut.DataStorage.GetFakeTemplate(null).ReturnsForAnyArgs(new DbTemplate("Sample", templateId));

            var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId);

            sut.Initialize(updatedItem);

            // act
            ReflectionUtil.CallMethod(sut, "DoExecute");

            // assertt
            originalItem.FullPath.Should().Be(expectedPath);
        }
Пример #11
0
    public void ShouldUpdateItemPathAfterRename(string originalPath, string expectedPath, SaveItemCommand sut, ID itemId, ID templateId)
    {
      // arrange
      var originalItem = new DbItem("original item") { FullPath = originalPath };
      sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
      sut.DataStorage.GetFakeTemplate(null).ReturnsForAnyArgs(new DbTemplate("Sample", templateId));

      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId);
      sut.Initialize(updatedItem);

      // act
      ReflectionUtil.CallMethod(sut, "DoExecute");

      // assertt
      originalItem.FullPath.Should().Be(expectedPath);
    }
Пример #12
0
    public void ShouldUpdateBranchId(SaveItemCommand sut, DbItem item, ID branchId, FieldList fields, Language language)
    {
      // arrange
      sut.DataStorage.GetFakeItem(item.ID).Returns(item);
      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", item.ID, ID.NewID, branchId, fields, language, new Version(0));

      sut.Initialize(updatedItem);

      // act
      ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      item.BranchId.Should().Be(branchId);
    }
Пример #13
0
    public void ShouldNotUpdateFieldsIfItemVersionIsZero(SaveItemCommand sut, DbItem item, FieldList fields, Language language)
    {
      // arrange
      sut.DataStorage.GetFakeItem(item.ID).Returns(item);
      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", item.ID, ID.NewID, ID.Null, fields, language, new Version(0));

      sut.Initialize(updatedItem);

      // act
      Action action = () => ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      action.ShouldNotThrow();
    }
Пример #14
0
    public void ShouldAddMissingFieldToItemIfFieldExistsInTemplate(SaveItemCommand sut, ID itemId, ID templateId, ID fieldId)
    {
      // arrange
      var template = new DbTemplate("Sample", templateId) { fieldId };
      var originalItem = new DbItem("original item", itemId, templateId);

      sut.DataStorage.GetFakeItem(itemId).Returns(originalItem);
      sut.DataStorage.GetFakeTemplate(templateId).Returns(template);

      var fields = new FieldList { { fieldId, "updated title" } };
      var updatedItem = ItemHelper.CreateInstance(sut.Database, "updated item", itemId, ID.NewID, ID.Null, fields);

      sut.Initialize(updatedItem);

      // act
      ReflectionUtil.CallMethod(sut, "DoExecute");

      // assert
      originalItem.Name.Should().Be("updated item");
      originalItem.Fields[fieldId].Value.Should().Be("updated title");
    }