public void Transform_WhenContainerHasMultipleLanguages_ShouldCallTransformContainerForAllLanguages()
        {
            // Arrange
            var parent = new ComposerPage { Name = "Parent name" };

            var contentMap = new Mock<IContentMap>();
            contentMap.Setup(x => x.GetParentPage(It.IsAny<Guid>())).Returns(parent);

            var subject = CreateSubject(contentMap.Object, null);

            var content = new RawContent
            {
                Property = new[]
                {
                    new RawProperty { Name = ComposerProperties.ContainerPage },
                    new RawProperty { Name = MetaDataProperties.PageName, Value = "Initial" }
                }
            };

            var language1 = new RawContent
            {
                Property = new[]
                {
                    new RawProperty { Name = ComposerProperties.ContainerPage },
                    new RawProperty { Name = MetaDataProperties.PageName, Value = "Initial" }
                }
            };

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

            // Assert
            Assert.AreEqual(parent.Name, content.PageName());
            Assert.AreEqual(parent.Name, language1.PageName());
        }
        public void TransformContainer_ShouldSetMasterLanguageToParentLanguage()
        {
            // Arrange
            var subject = CreateSubject(null, null);
            var content = new RawContent { Property = new[] { new RawProperty { Name = MetaDataProperties.PageMasterLanguageBranch, Value = "Initial" } } };
            var parent = new ComposerPage { Language = "no" };

            // Act
            subject.TransformContainer(content, parent);

            // Assert
            Assert.AreEqual(parent.Language, content.MasterLanguage());
        }
        public void TransformContainer_ShouldSetNameToParentName()
        {
            // Arrange
            var subject = CreateSubject(null, null);
            var content = new RawContent { Property = new[] { new RawProperty { Name = MetaDataProperties.PageName, Value = "Initial" } } };
            var parent = new ComposerPage { Name = "Parent name" };

            // Act
            subject.TransformContainer(content, parent);

            // Assert
            Assert.AreEqual(parent.Name, content.PageName());
        }
        public void AddPage_ShouldAddPageToMap()
        {
            // Arrange
            var subject = new ContentMap();
            var page = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage };

            // Act
            subject.AddPage(page);

            // Assert
            var result = subject.GetPage(page.Guid, page.Language);
            Assert.AreSame(page, result);
        }
        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 GetContentFunctions_WhenContentAreaDoesNotExist_ShouldReturnLookupWithoutFunctions()
        {
            // Arrange
            var subject = new ContentMap();
            var areaName = "Area54";
            var page = new ComposerPage
            {
                Guid = Guid.NewGuid(),
                Language = DefaultLanguage,
                ContentAreas = { new ComposerContentArea { Name = DefaultAreaName } }
            };
            subject.AddPage(page);

            // Act
            var result = subject.GetContentFunctions(page.Guid, page.Language)[areaName];

            // Assert
            Assert.IsFalse(result.Any());
        }
        public void GetParent_WhenShadowGuidOfAddedPageIsEmpty_ShouldReturnNull()
        {
            // Arrange
            var subject = new ContentMap();

            var page = new ComposerPage
            {
                Guid = Guid.NewGuid(),
                ShadowGuid = Guid.Empty,
                Language = DefaultLanguage,
            };

            subject.AddPage(page);

            // Act
            var result = subject.GetParentPage(page.ShadowGuid);

            // Assert
            Assert.IsNull(result);
        }
        public void GetParent_WhenGuidMatchPage_ShouldReturnNull()
        {
            // Arrange
            var subject = new ContentMap();
            var function = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage };
            var page = new ComposerPage
            {
                Guid = Guid.NewGuid(),
                Language = DefaultLanguage,
                ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { function } } }
            };
            subject.AddPage(page);

            // Act
            var result = subject.GetParentPage(page.Guid);

            // Assert
            Assert.IsNull(result);
        }
        public void GetParent_WhenGuidMatchesShadowGuidButPageHasNoFunctions_ShouldReturnNull()
        {
            // Arrange
            var subject = new ContentMap();

            var page = new ComposerPage
            {
                Name = "Page name",
                Guid = Guid.NewGuid(),
                Language = DefaultLanguage,
                ShadowGuid = Guid.NewGuid()
            };

            subject.AddPage(page);

            // Act
            var result = subject.GetParentPage(page.ShadowGuid);

            // Assert
            Assert.IsNull(result);
        }
        public void GetParent_WhenGuidMatchesShadowGuidAndHasFunctions_ShouldReturnPage()
        {
            // Arrange
            var subject = new ContentMap();

            var page = new ComposerPage
            {
                Name = "Page name",
                Guid = Guid.NewGuid(),
                Language = DefaultLanguage,
                ShadowGuid = Guid.NewGuid(),
                ContentAreas =
                {
                    new ComposerContentArea
                    {
                        Name = DefaultAreaName,
                        ContentFunctions = { new ComposerContentFunction { Guid = Guid.NewGuid() } }
                    }
                }
            };

            subject.AddPage(page);

            // Act
            var result = subject.GetParentPage(page.ShadowGuid);

            // Assert
            Assert.AreSame(page, result);
        }
        public void GetContentFunctions_WhenLanguageIsIncorrect_ShouldCheckParentLanguage()
        {
            // Arrange
            var subject = new ContentMap();
            var nestedFunction = new ComposerContentFunction { Guid = Guid.NewGuid(), Language = DefaultLanguage };

            var layoutFunction = new ComposerContentFunction
            {
                Guid = Guid.NewGuid(),
                Language = DefaultLanguage,
                ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { nestedFunction } } }
            };

            var page = new ComposerPage
            {
                Guid = Guid.NewGuid(),
                Language = "sv",
                ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { layoutFunction } } }
            };

            subject.AddPage(page);

            // Act
            var result = subject.GetContentFunctions(layoutFunction.Guid, DefaultLanguage)[DefaultAreaName];

            // Assert
            Assert.AreEqual(1, result.Count());
            Assert.IsTrue(result.Any(b => b.Guid == nestedFunction.Guid));
        }
        public void GetContentFunctions_WhenContentHasFunction_ShouldReturnLookupWithAnyFunction()
        {
            // Arrange
            var subject = new ContentMap();
            var function = new ComposerContentFunction { Guid = Guid.NewGuid() };
            var page = new ComposerPage
            {
                Guid = Guid.NewGuid(),
                Language = DefaultLanguage,
                ContentAreas = { new ComposerContentArea { Name = DefaultAreaName, ContentFunctions = { function } } }
            };
            subject.AddPage(page);

            // Act
            var result = subject.GetContentFunctions(page.Guid, page.Language)[DefaultAreaName];

            // Assert
            Assert.AreEqual(1, result.Count());
            Assert.IsTrue(result.Any(b => b.Guid == function.Guid));
        }
        public void GetContentFunctions_WhenContentDoesntHaveAnyFunctions_ShouldReturnEmptyLookup()
        {
            // Arrange
            var subject = new ContentMap();
            var composerPage = new ComposerPage { Guid = Guid.NewGuid(), Language = DefaultLanguage };
            subject.AddPage(composerPage);

            // Act
            var result = subject.GetContentFunctions(composerPage.Guid, composerPage.Language);

            // Assert
            Assert.IsFalse(result.Any());
        }