Ejemplo n.º 1
0
        public void UpgradeConfig_WithSourceAndDestinationDirectory_UpgradesWebConfig()
        {
            // arrange
            const string newConfig = @"<configuration><connectionStrings><connectionString name=""default"" /></connectionStrings><Foo /></configuration>";
            const string oldConfig = @"<configuration><connectionStrings><connectionString name=""mine"" /></connectionStrings></configuration>";
            var newConfigFile = new Mock<IFile>();

            var stream = new NonDisposableMemoryStream();
            newConfigFile.Setup(f => f.OpenWrite()).Returns(stream);
            newConfigFile.Setup(f => f.Contents).Returns(newConfig);
            var existingFileConfig = new Mock<IFile>();
            newConfigFile.Setup(f => f.Overwrite(existingFileConfig.Object));
            existingFileConfig.Setup(f => f.Contents).Returns(oldConfig);
            existingFileConfig.Setup(f => f.Exists).Returns(true);
            var sourceDirectory = new Mock<IDirectory>();
            sourceDirectory.Setup(s => s.CombineFile("Web.config")).Returns(newConfigFile.Object);
            var destinationDirectory = new Mock<IDirectory>();
            destinationDirectory.Setup(d => d.CombineFile("Web.config")).Returns(existingFileConfig.Object);
            var upgrader = new WebConfigUpgrader(sourceDirectory.Object);

            // act
            upgrader.UpgradeConfig(destinationDirectory.Object);

            // assert
            const string expected = @"<configuration>
              <connectionStrings>
            <connectionString name=""mine"" />
              </connectionStrings>
              <Foo />
            </configuration>";
            Assert.AreEqual(expected, stream.ToStringContents());
        }
        public void UpgradeSkins_WritesNewSkins_ToSkinTemplateDirectory()
        {
            // arrange
            var targetDirectory = new Mock <IDirectory>();

            targetDirectory.Setup(d => d.Combine("Skins")).Returns(targetDirectory.Object);
            targetDirectory.Setup(d => d.Combine("Foo")).Returns(targetDirectory.Object);

            const string configXml = @"<?xml version=""1.0""?>
<SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
  <Skins>
    <SkinTemplate Name=""Foo"" TemplateFolder=""Foo"" StyleMergeMode=""MergedAfter"">
      <Styles>
        <Style href=""csharp.css"" />
      </Styles>
    </SkinTemplate>
  </Skins>
</SkinTemplates>";
            var          file      = new Mock <IFile>();

            file.Setup(f => f.Contents).Returns(configXml);
            file.Setup(f => f.Directory.Parent).Returns(targetDirectory.Object);
            var memoryStream = new NonDisposableMemoryStream();
            var skinFile     = new Mock <IFile>();

            skinFile.Setup(f => f.OpenWrite()).Returns(memoryStream);
            var skinDirectory = new Mock <IDirectory>();

            skinDirectory.Setup(d => d.Exists).Returns(false);
            skinDirectory.Setup(d => d.CombineFile("skin.config")).Returns(skinFile.Object);
            skinDirectory.Setup(d => d.Ensure()).Returns(skinDirectory.Object);
            var skinsDirectory = new Mock <IDirectory>();

            skinsDirectory.Setup(d => d.Combine("Foo")).Returns(skinDirectory.Object);
            skinsDirectory.Setup(d => d.Ensure()).Returns(skinDirectory.Object);
            var oldConfig = new LegacySkinsConfig(file.Object);

            // act
            oldConfig.UpgradeSkins(skinsDirectory.Object);

            // assert
            targetDirectory.Verify(d => d.CopyTo(skinDirectory.Object));
            const string expected =
                @"<SkinTemplates>
  <SkinTemplate Name=""Foo"" StyleMergeMode=""MergedAfter"">
    <Styles>
      <Style href=""csharp.css"" />
    </Styles>
  </SkinTemplate>
</SkinTemplates>";

            Assert.AreEqual(expected, memoryStream.ToStringContents());
        }
Ejemplo n.º 3
0
        public void UpgradeConfig_WithSourceAndDestinationDirectory_UpgradesWebConfig()
        {
            // arrange
            const string newConfig     = @"<configuration><connectionStrings><connectionString name=""default"" /></connectionStrings><Foo /></configuration>";
            const string oldConfig     = @"<configuration><connectionStrings><connectionString name=""mine"" /></connectionStrings></configuration>";
            var          newConfigFile = new Mock <IFile>();

            var stream = new NonDisposableMemoryStream();

            newConfigFile.Setup(f => f.OpenWrite()).Returns(stream);
            newConfigFile.Setup(f => f.Contents).Returns(newConfig);
            var existingFileConfig = new Mock <IFile>();

            newConfigFile.Setup(f => f.Overwrite(existingFileConfig.Object));
            existingFileConfig.Setup(f => f.Contents).Returns(oldConfig);
            existingFileConfig.Setup(f => f.Exists).Returns(true);
            var sourceDirectory = new Mock <IDirectory>();

            sourceDirectory.Setup(s => s.CombineFile("Web.config")).Returns(newConfigFile.Object);
            var destinationDirectory = new Mock <IDirectory>();

            destinationDirectory.Setup(d => d.CombineFile("Web.config")).Returns(existingFileConfig.Object);
            var upgrader = new WebConfigUpgrader(sourceDirectory.Object);

            // act
            upgrader.UpgradeConfig(destinationDirectory.Object);

            // assert
            const string expected = @"<configuration>
  <connectionStrings>
    <connectionString name=""mine"" />
  </connectionStrings>
  <Foo />
</configuration>";

            Assert.AreEqual(expected, stream.ToStringContents());
        }
Ejemplo n.º 4
0
        public void UpgradeSkins_WritesNewSkins_ToSkinTemplateDirectory()
        {
            // arrange
            var targetDirectory = new Mock<IDirectory>();
            targetDirectory.Setup(d => d.Combine("Skins")).Returns(targetDirectory.Object);
            targetDirectory.Setup(d => d.Combine("Foo")).Returns(targetDirectory.Object);

            const string configXml = @"<?xml version=""1.0""?>
            <SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
              <Skins>
            <SkinTemplate Name=""Foo"" TemplateFolder=""Foo"" StyleMergeMode=""MergedAfter"">
              <Styles>
            <Style href=""csharp.css"" />
              </Styles>
            </SkinTemplate>
              </Skins>
            </SkinTemplates>";
            var file = new Mock<IFile>();
            file.Setup(f => f.Contents).Returns(configXml);
            file.Setup(f => f.Directory.Parent).Returns(targetDirectory.Object);
            var memoryStream = new NonDisposableMemoryStream();
            var skinFile = new Mock<IFile>();
            skinFile.Setup(f => f.OpenWrite()).Returns(memoryStream);
            var skinDirectory = new Mock<IDirectory>();
            skinDirectory.Setup(d => d.Exists).Returns(false);
            skinDirectory.Setup(d => d.CombineFile("skin.config")).Returns(skinFile.Object);
            skinDirectory.Setup(d => d.Ensure()).Returns(skinDirectory.Object);
            var skinsDirectory = new Mock<IDirectory>();
            skinsDirectory.Setup(d => d.Combine("Foo")).Returns(skinDirectory.Object);
            skinsDirectory.Setup(d => d.Ensure()).Returns(skinDirectory.Object);
            var oldConfig = new LegacySkinsConfig(file.Object);

            // act
            oldConfig.UpgradeSkins(skinsDirectory.Object);

            // assert
            targetDirectory.Verify(d => d.CopyTo(skinDirectory.Object));
            const string expected =
                @"<SkinTemplates>
              <SkinTemplate Name=""Foo"" StyleMergeMode=""MergedAfter"">
            <Styles>
              <Style href=""csharp.css"" />
            </Styles>
              </SkinTemplate>
            </SkinTemplates>";
            Assert.AreEqual(expected, memoryStream.ToStringContents());
        }