public void CreateFriendlyName_WhenFunctionInfoHasName_ShouldReturnInfoName()
        {
            // Arrange
            var functionInfo = new ComposerContentFunctionInformation { Name = "Info name" };
            var subject = CreateSubject(functionInfo: functionInfo);

            // Act
            var result = subject.CreateFriendlyName(null, functionInfo);

            // Assert
            Assert.AreEqual(functionInfo.Name, result);
        }
        public virtual string CreateFriendlyName(RawContent content, ComposerContentFunctionInformation functionInfo)
        {
            if (functionInfo != null && !string.IsNullOrEmpty(functionInfo.Name))
            {
                return functionInfo.Name;
            }

            string friendlyName = content.PageType();

            if (_possibleFunctionNameProperties.Count > 0)
            {
                var headingProperty = content.Property.FirstOrDefault(p => _possibleFunctionNameProperties.Contains(p.Name));

                if (headingProperty != null && !headingProperty.IsNull)
                {
                    friendlyName += " - " + headingProperty.Value;
                }
            }

            return friendlyName;
        }
        public void Transform_WhenFunctionIsGlobal_ShouldUpdateParentLink()
        {
            // Arrange
            const string expected = "EXPECTED";
            var resolver = new Mock<ExportLinkResolver>(null);
            resolver.Setup(x => x.GetExportableLink(It.IsAny<ContentReference>())).Returns(expected);
            var functionInfo = new ComposerContentFunctionInformation { Type = ComposerContentFunctionCategory.Global };
            var subject = CreateSubject(functionInfo: functionInfo, exportLinkResolver: resolver.Object);
            var content = new RawContent
            {
                Property = new[]
                {
                    new RawProperty { Name = ComposerProperties.ContentFunction },
                    new RawProperty { Name = MetaDataProperties.PageParentLink, Value = "Initial" }
                }
            };

            // Act
            subject.Transform(TestUtil.TransferData(content));

            // Assert
            Assert.AreEqual(expected, content.GetPropertyValue(MetaDataProperties.PageParentLink));
        }
 private static ComposerFunctionTransform CreateSubject(IContentMap contentMap = null, ComposerContentFunctionInformation functionInfo = null, ExportLinkResolver exportLinkResolver = null, IComposerImportOptions options = null)
 {
     contentMap = contentMap ?? new Mock<IContentMap>().Object;
     exportLinkResolver = exportLinkResolver ?? new Mock<ExportLinkResolver>(null).Object;
     return new ComposerFunctionTransform(contentMap, CreateSerializer(functionInfo), exportLinkResolver, options);
 }
 private static ComposerSerializer CreateSerializer(ComposerContentFunctionInformation info)
 {
     var serializer = new Mock<ComposerSerializer>();
     serializer.Setup(x => x.Deserialize<ComposerContentFunctionInformation>(It.IsAny<string>())).Returns(info);
     return serializer.Object;
 }
        public void Transform_WhenFunctionIsLocal_ShouldSetMasterLanguageToParentLanguage()
        {
            // Arrange
            var parent = new ComposerPage { Language = "no" };
            var contentMap = new Mock<IContentMap>();
            contentMap.Setup(x => x.GetParentPage(It.IsAny<Guid>())).Returns(parent);

            var functionInfo = new ComposerContentFunctionInformation { Type = ComposerContentFunctionCategory.Content };
            var subject = CreateSubject(contentMap.Object, functionInfo);
            var content = new RawContent
            {
                Property = new[]
                {
                    new RawProperty { Name = ComposerProperties.ContentFunction },
                    new RawProperty { Name = MetaDataProperties.PageMasterLanguageBranch, Value = "sv" }
                }
            };

            // Act
            subject.Transform(TestUtil.TransferData(content));

            // Assert
            Assert.AreEqual(parent.Language, content.MasterLanguage());
        }
        public void Transform_WhenFunctionIsLocal_ShouldNotTouchParentLink()
        {
            // Arrange
            const string expected = "Initial";
            var functionInfo = new ComposerContentFunctionInformation { Type = ComposerContentFunctionCategory.Content };
            var subject = CreateSubject(functionInfo: functionInfo);
            var content = new RawContent
            {
                Property = new[]
                {
                    new RawProperty { Name = ComposerProperties.ContentFunction },
                    new RawProperty { Name = MetaDataProperties.PageParentLink, Value = expected }
                }
            };

            // Act
            subject.Transform(TestUtil.TransferData(content));

            // Assert
            Assert.AreEqual(expected, content.GetPropertyValue(MetaDataProperties.PageParentLink));
        }