示例#1
0
        public void Ctor_DirectoryWithSubDirectories_ReplacesFilesUnderNeath()
        {
            //arrange
            using (var writer = File.CreateText("PageTemplate.ascx"))
            {
                writer.Write(@"<%@ Register TagPrefix=""SP"" Namespace=""Subtext.Web.Controls"" Assembly=""Subtext.Web.Controls"" %>");
            }
            var existingCustomSkinFile = new SubtextFile(new FileInfo("PageTemplate.ascx"));
            var files = new List <IFile> {
                existingCustomSkinFile
            };
            var sourceDirectory = new Mock <IDirectory>();
            var subDirectory    = new Mock <IDirectory>();

            subDirectory.Setup(s => s.GetFiles()).Returns(files);
            var directories = new List <IDirectory> {
                subDirectory.Object
            };

            sourceDirectory.Setup(s => s.GetDirectories()).Returns(directories);
            var upgrader = new SkinUpgrader(sourceDirectory.Object);

            // act
            upgrader.Run();

            //assert
            using (var reader = new StreamReader(File.OpenRead("PageTemplate.ascx")))
            {
                const string expected = @"<%@ Register TagPrefix=""SP"" Namespace=""Subtext.Web.Controls"" Assembly=""Subtext.Web"" %>";
                var          text     = reader.ReadToEnd();
                Assert.AreEqual(expected, text);
            }
        }
示例#2
0
        public void GetUpgradedSkinFileContents_WithEndSubstringSecurityHelperIsAdmin_DoesNotReplaceWithUserIsAdministrator()
        {
            // Arrange
            string content = "(AUser.IsAdministrator()) {%>";

            // Act
            var result = SkinUpgrader.GetUpgradedSkinFileContents(content);

            // Assert
            Assert.AreEqual("(AUser.IsAdministrator()) {%>", result);
        }
示例#3
0
        public void GetUpgradedSkinFileContents_WithChainedCallToSecurityHelperIsAdmin_ReplacesWithUserIsAdministrator()
        {
            // Arrange
            string content = "(User.IsAdministrator().ToString()) {%>";

            // Act
            var result = SkinUpgrader.GetUpgradedSkinFileContents(content);

            // Assert
            Assert.AreEqual("(User.IsAdministrator().ToString()) {%>", result);
        }
示例#4
0
        public void GetUpgradedSkinFileContents_WithCallToSecurityHelperIsAdmin_ReplacesWithUserIsAdministrator()
        {
            // Arrange
            string content = "<% if(Request.IsAuthenticated && User.IsAdministrator()) {%>";

            // Act
            var result = SkinUpgrader.GetUpgradedSkinFileContents(content);

            // Assert
            Assert.AreEqual("<% if(Request.IsAuthenticated && User.IsAdministrator()) {%>", result);
        }
示例#5
0
        public void Ctor_FileWithOldAssembly_KeepsOtherContent()
        {
            //arrange
            var upgrader = new SkinUpgrader(GetSourceDirectory());

            // act
            upgrader.Run();

            //assert
            using (var reader = new StreamReader(File.OpenRead("PageTemplate.ascx")))
            {
                const string expected = @"<%@ Register TagPrefix=""SP"" Namespace=""Subtext.Web.Controls"" Assembly=""Subtext.Web"" %>my other content";
                var          text     = reader.ReadToEnd();
                Assert.AreEqual(expected, text);
            }
        }