public bool ProcessResult(Item item, string result, out string errorMessage)
        {
            errorMessage = string.Empty;

            ShortID sid;
            if (!ShortID.TryParse(result, out sid))
            {
                errorMessage = "Could not get the ID of the selected base layout.";
                return false;
            }

            var itemId = sid.ToID();
            Item baseLayoutItem = null;
            if (itemId != ID.Null)
            {
                baseLayoutItem = item.Database.GetItem(itemId);
                if (baseLayoutItem == null)
                {
                    errorMessage = "The selected base layout item was not found.";
                    return false;
                }
            }

            var args = new SaveBaseLayoutArgs(item) {NewBaseLayoutItem = baseLayoutItem};
            _pipelineRunner.Run(args);
            if (!string.IsNullOrEmpty(args.Message))
            {
                errorMessage = args.Message;
            }

            return args.Successful;
        }
        /// <summary>
        ///     Checks for a circular reference in the base layout chain
        /// </summary>
        /// <param name="args">the pipeline arguments</param>
        public void Process(SaveBaseLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.NewBaseLayoutItem == null) return;

            if (_validator.CreatesCircularBaseLayoutReference(args.Item, args.NewBaseLayoutItem))
            {
                args.Successful = false;
                args.AddMessage("Selecting this base layout would create a circular reference in the base layout chain.");
                args.AbortPipeline();
            }
        }
        public void Process_WithNewBaseLayoutItemNull_SetsFieldValueToEmptyString()
        {
            // Arrange
            var args = new SaveBaseLayoutArgs(MasterFakesFactory.CreateFakeItem());
            var processor = new SaveNewBaseLayout();

            // Act
            processor.Process(args);

            // Assert
            Assert.Equal(string.Empty, args.Item.InnerItem.Fields[BaseLayoutItem.BaseLayoutFieldId].Value);
        }
        public void Process_WithNewBaseLayoutItemNull_SetsSuccessfulTrue()
        {
            // Arrange
            var args = new SaveBaseLayoutArgs(MasterFakesFactory.CreateFakeItem());
            var processor = new SaveNewBaseLayout();

            // Act
            processor.Process(args);

            // Assert
            Assert.True(args.Successful);
        }
        /// <summary>
        ///     Checks for a versioning conflict with the base layout.
        ///     It is not allowed to have an item apply a shared layout delta over a
        ///     versioned layout value on a base layout.
        /// </summary>
        /// <param name="args">the pipeline arguments</param>
        public void Process(SaveBaseLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.NewBaseLayoutItem == null) return;

            if (_validator.CreatesVersioningConflict(args.Item, args.NewBaseLayoutItem))
            {
                args.Successful = false;
                args.AddMessage(
                    "Selecting this base layout would create apply a shared layout delta over a versioned layout value.");
                args.AbortPipeline();
            }
        }
        public void Process_WithNewBaseLayoutItemNotNull_SetsFieldValueToIdString()
        {
            // Arrange
            var item = MasterFakesFactory.CreateFakeItem();
            var item2 = MasterFakesFactory.CreateFakeItem();
            var args = new SaveBaseLayoutArgs(item) {NewBaseLayoutItem = item2};
            var processor = new SaveNewBaseLayout();

            // Act
            processor.Process(args);

            // Assert
            Assert.Equal(item2.ID.ToString(), args.Item.InnerItem.Fields[BaseLayoutItem.BaseLayoutFieldId].Value);
        }
        public void Process_WithNewBaseLayoutItemNull_DoesNotCallValidator()
        {
            // Arrange
            var item = MasterFakesFactory.CreateFakeItem();
            var args = new SaveBaseLayoutArgs(item);
            var validator = Substitute.For<IBaseLayoutValidator>();
            var processor = new CheckForVersioningConflict(validator);

            // Act
            processor.Process(args);

            // Assert
            validator.DidNotReceive().CreatesVersioningConflict(Arg.Any<Item>(), Arg.Any<Item>());
        }
예제 #8
0
        /// <summary>
        ///     Checks for a circular reference in the base layout chain
        /// </summary>
        /// <param name="args">the pipeline arguments</param>
        public void Process(SaveBaseLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.NewBaseLayoutItem == null)
            {
                return;
            }

            if (_validator.CreatesCircularBaseLayoutReference(args.Item, args.NewBaseLayoutItem))
            {
                args.Successful = false;
                args.AddMessage("Selecting this base layout would create a circular reference in the base layout chain.");
                args.AbortPipeline();
            }
        }
        public void Process_WhenValidatorReturnsFalse_DoesNotAbortPipeline()
        {
            // Arrange
            var item = MasterFakesFactory.CreateFakeItem();
            var item2 = MasterFakesFactory.CreateFakeItem();
            var args = new SaveBaseLayoutArgs(item) {NewBaseLayoutItem = item2};
            var validator = Substitute.For<IBaseLayoutValidator>();
            validator.CreatesVersioningConflict(Arg.Any<Item>(), Arg.Any<Item>()).Returns(false);
            var processor = new CheckForVersioningConflict(validator);

            // Act
            processor.Process(args);

            // Assert
            Assert.False(args.Aborted);
        }
        /// <summary>
        ///     Checks for a versioning conflict with the base layout.
        ///     It is not allowed to have an item apply a shared layout delta over a
        ///     versioned layout value on a base layout.
        /// </summary>
        /// <param name="args">the pipeline arguments</param>
        public void Process(SaveBaseLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.NewBaseLayoutItem == null)
            {
                return;
            }

            if (_validator.CreatesVersioningConflict(args.Item, args.NewBaseLayoutItem))
            {
                args.Successful = false;
                args.AddMessage(
                    "Selecting this base layout would create apply a shared layout delta over a versioned layout value.");
                args.AbortPipeline();
            }
        }
        public void Process(SaveBaseLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.IsNotNull(args.Item, "The item cannot be null.");

            var newValue = args.NewBaseLayoutItem == null ? string.Empty : args.NewBaseLayoutItem.ID.ToString();
            var field = args.Item.InnerItem.Fields[BaseLayoutItem.BaseLayoutFieldId];
            if (!field.Value.Equals(newValue, StringComparison.OrdinalIgnoreCase))
            {
                using (new EditContext(args.Item.InnerItem))
                {
                    field.Value = newValue;
                }
            }

            args.Successful = true;
        }
        public void Process_WhenValidatorReturnsTrue_SetsSuccessfulFalseAndAbortsPipeline()
        {
            // Arrange
            var item = MasterFakesFactory.CreateFakeItem();
            var item2 = MasterFakesFactory.CreateFakeItem();
            var args = new SaveBaseLayoutArgs(item) {NewBaseLayoutItem = item2};
            var validator = Substitute.For<IBaseLayoutValidator>();
            validator.CreatesCircularBaseLayoutReference(Arg.Any<Item>(), Arg.Any<Item>()).Returns(true);
            var processor = new CheckForCircularReference(validator);

            // Act
            processor.Process(args);

            // Assert
            Assert.False(args.Successful);
            Assert.True(args.Aborted);
        }
        public void Process(SaveBaseLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.IsNotNull(args.Item, "The item cannot be null.");

            var newValue = args.NewBaseLayoutItem == null ? string.Empty : args.NewBaseLayoutItem.ID.ToString();
            var field    = args.Item.InnerItem.Fields[BaseLayoutItem.BaseLayoutFieldId];

            if (!field.Value.Equals(newValue, StringComparison.OrdinalIgnoreCase))
            {
                using (new EditContext(args.Item.InnerItem))
                {
                    field.Value = newValue;
                }
            }

            args.Successful = true;
        }