LegacySkinsConfigTests.cs :  » Bloggers » SubText » SubtextUpgraderTests » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » SubtextUpgraderTests » LegacySkinsConfigTests.cs
using System.Linq;
using MbUnit.Framework;
using Moq;
using SubtextUpgrader;

namespace SubtextUpgraderTests{
    [TestFixture]
    public class LegacySkinsConfigTests
    {
        [Test]
        public void GetNewSkinConfigs_WithLegacySkinConfigXml_ExtractsSkinConfigs()
        {
            // arrange
            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>
    <SkinTemplate Name=""Bar"" TemplateFolder=""Bar"">
      <Styles>
        <Style href=""bar.css"" />
      </Styles>
    </SkinTemplate>
  </Skins>
</SkinTemplates>";
            var file = new Mock<IFile>();
            file.Setup(f => f.Contents).Returns(configXml);
            var oldConfig = new LegacySkinsConfig(file.Object);

            // act
            var configs = oldConfig.GetNewSkinConfigs();

            // assert
            Assert.AreEqual(2, configs.Count());
            const string expectedFirstXml =
                @"<SkinTemplates><SkinTemplate Name=""Foo"" StyleMergeMode=""MergedAfter""><Styles><Style href=""csharp.css"" /></Styles></SkinTemplate></SkinTemplates>";
            Assert.AreEqual(expectedFirstXml, configs.First().Xml.OuterXml);
            Assert.AreEqual("Foo", configs.First().TemplateFolder);
            const string expectedSecondXml =
                @"<SkinTemplates><SkinTemplate Name=""Bar""><Styles><Style href=""bar.css"" /></Styles></SkinTemplate></SkinTemplates>";
            Assert.AreEqual(expectedSecondXml, configs.ElementAt(1).Xml.OuterXml);
            Assert.AreEqual("Bar", configs.ElementAt(1).TemplateFolder);
        }

        [Test]
        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());
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.