SkinEngineTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Skinning » 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 » UnitTests » Subtext » Framework » Skinning » SkinEngineTests.cs
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Hosting;
using MbUnit.Framework;
using Moq;
using Subtext.Framework.UI.Skinning;

namespace UnitTests.Subtext.Framework.Skinning{
    [TestFixture]
    public class SkinEngineTests
    {
        [Test]
        public void GetSkinTemplates_WithFolders_ReturnsSkinPerFolder()
        {
            //arrange
            var directories = new List<VirtualDirectory>();
            for(int i = 0; i < 3; i++)
            {
                var skinDir = new Mock<VirtualDirectory>("~/skins/skin" + i);
                skinDir.Setup(d => d.Name).Returns("Skin" + i);
                directories.Add(skinDir.Object);
            }
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(3, skinTemplates.Count);
            Assert.AreEqual("Skin0", skinTemplates.Values.First().Name);
            Assert.AreEqual("Skin0", skinTemplates.Values.First().TemplateFolder);
        }

        [Test]
        public void GetSkinTemplates_WithSpecialFolders_IgnoresSpecialFolders()
        {
            //arrange
            var directories = new List<VirtualDirectory>();
            var nonSkinDir = new Mock<VirtualDirectory>("~/skins/_system");
            nonSkinDir.Setup(d => d.Name).Returns("_system");
            directories.Add(nonSkinDir.Object);
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            Assert.AreEqual("Skin1", skinTemplates.Values.First().Name);
        }

        [Test]
        public void GetSkinTemplates_WithSkinConfigInFolder_AppliesConfig()
        {
            //arrange
            var virtualFile = new Mock<VirtualFile>("~/skins/skin1/skin.config");
            Stream stream =
                @"<?xml version=""1.0""?>
<SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
    <SkinTemplate Name=""Skinny"" StyleMergeMode=""MergedAfter"" ScriptMergeMode=""Merge"">
      <Styles>
        <Style href=""~/skins/_System/commonstyle.css"" />
      </Styles>
    </SkinTemplate>
</SkinTemplates>"
                    .ToStream();
            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List<VirtualDirectory>();
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            SkinTemplate template = skinTemplates.Values.First();
            Assert.AreEqual("Skinny", template.Name);
            Assert.AreEqual("Skin1", template.TemplateFolder);
            Assert.AreEqual(StyleMergeMode.MergedAfter, template.StyleMergeMode);
            Assert.AreEqual(ScriptMergeMode.Merge, template.ScriptMergeMode);
            Assert.AreEqual(1, template.Styles.Count());
        }

        [Test]
        public void GetSkinTemplates_WithMobileSpecified_ReturnsSkinWithMobileSupportSetToMobileOnly()
        {
            //arrange
            var virtualFile = new Mock<VirtualFile>("~/skins/skin1/skin.config");
            Stream stream =
                @"<?xml version=""1.0""?>
<SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
    <SkinTemplate Name=""Mobile"" MobileSupport=""MobileOnly"">
      <Styles>
        <Style href=""~/skins/_System/commonstyle.css"" />
      </Styles>
    </SkinTemplate>
</SkinTemplates>"
                    .ToStream();
            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List<VirtualDirectory>();
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(true /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            SkinTemplate template = skinTemplates.Values.First();
            Assert.AreEqual("Mobile", template.Name);
        }

        [Test]
        public void GetSkinTemplates_WithMobileSpecified_ReturnsSkinWithMobileSupportSetToSupported()
        {
            //arrange
            var virtualFile = new Mock<VirtualFile>("~/skins/skin1/skin.config");
            Stream stream =
                @"<?xml version=""1.0""?>
<SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
    <SkinTemplate Name=""Mobile"" MobileSupport=""Supported"">
      <Styles>
        <Style href=""~/skins/_System/commonstyle.css"" />
      </Styles>
    </SkinTemplate>
</SkinTemplates>"
                    .ToStream();
            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List<VirtualDirectory>();
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(true /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            SkinTemplate template = skinTemplates.Values.First();
            Assert.AreEqual("Mobile", template.Name);
        }

        [Test]
        public void GetSkinTemplates_WithMobileNotSpecified_ReturnsSkinWithMobileSupportSetToSupported()
        {
            //arrange
            var virtualFile = new Mock<VirtualFile>("~/skins/skin1/skin.config");
            Stream stream =
                @"<?xml version=""1.0""?>
<SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
    <SkinTemplate Name=""Mobile"" MobileSupport=""Supported"">
      <Styles>
        <Style href=""~/skins/_System/commonstyle.css"" />
      </Styles>
    </SkinTemplate>
</SkinTemplates>"
                    .ToStream();
            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List<VirtualDirectory>();
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(false /* mobile */);

            //assert
            Assert.AreEqual(1, skinTemplates.Count);
            SkinTemplate template = skinTemplates.Values.First();
            Assert.AreEqual("Mobile", template.Name);
        }

        [Test]
        public void GetSkinTemplates_WithMobileSpecified_DoesNotReturnSkinThatDoesNotSupportMobile()
        {
            //arrange
            var virtualFile = new Mock<VirtualFile>("~/skins/skin1/skin.config");
            Stream stream =
                @"<?xml version=""1.0""?>
    <SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
        <SkinTemplate Name=""Skinny"" MobileSupported=""None"">
          <Styles>
            <Style href=""~/skins/_System/commonstyle.css"" />
          </Styles>
        </SkinTemplate>
    </SkinTemplates>"
                    .ToStream();
            virtualFile.Setup(vf => vf.Open()).Returns(stream);

            var directories = new List<VirtualDirectory>();
            var skinDir = new Mock<VirtualDirectory>("~/skins/skin1");
            skinDir.Setup(d => d.Name).Returns("Skin1");
            directories.Add(skinDir.Object);
            var skinsDir = new Mock<VirtualDirectory>("~/skins");
            skinsDir.Setup(s => s.Directories).Returns(directories);
            var vpp = new Mock<VirtualPathProvider>();
            vpp.Setup(v => v.GetDirectory("~/skins")).Returns(skinsDir.Object);
            vpp.Setup(v => v.FileExists("~/skins/Skin1/skin.config")).Returns(true);
            vpp.Setup(v => v.GetFile("~/skins/Skin1/skin.config")).Returns(virtualFile.Object);
            var skins = new SkinEngine(vpp.Object);

            //act
            IDictionary<string, SkinTemplate> skinTemplates = skins.GetSkinTemplates(true /* mobile */);

            //assert
            Assert.AreEqual(0, skinTemplates.Count);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.