Ejemplo n.º 1
0
        public void InvokingPropertiesAndMethodsBeforeInitializationThrows()
        {
            // Arrange
            var mockVpp = new Mock<VirtualPathProvider>().Object;
            var scope = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(mockVpp, scope);

            // Act and Assert
            Assert.Throws<InvalidOperationException>(() => themesImpl.CurrentTheme = "Foo",
                                                              @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            Assert.Throws<InvalidOperationException>(() => { var x = themesImpl.CurrentTheme; },
                                                              @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            Assert.Throws<InvalidOperationException>(() => { var x = themesImpl.AvailableThemes; },
                                                              @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            Assert.Throws<InvalidOperationException>(() => { var x = themesImpl.DefaultTheme; },
                                                              @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            Assert.Throws<InvalidOperationException>(() => { var x = themesImpl.GetResourcePath("baz"); },
                                                              @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");

            Assert.Throws<InvalidOperationException>(() => { var x = themesImpl.GetResourcePath("baz", "some-file"); },
                                                              @"You must call the ""Themes.Initialize"" method before you call any other method of the ""Themes"" class.");
        }
Ejemplo n.º 2
0
        public void CurrentThemeThrowsIfAssignedNullOrEmpty()
        {
            // Arrange
            var mockVpp = new Mock<VirtualPathProvider>().Object;
            var scope = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(mockVpp, scope);

            // Act and Assert
            Assert.ThrowsArgumentNullOrEmptyString(() => { themesImpl.CurrentTheme = null; }, "value");
            Assert.ThrowsArgumentNullOrEmptyString(() => { themesImpl.CurrentTheme = String.Empty; }, "value");
        }
Ejemplo n.º 3
0
        public void GetResourcePathReturnsItemFromDefaultThemeDirectoryIfNotFoundInCurrentThemeDirectory()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile\styles", "wp7.css"), new Dir(@"default\styles", "main.css")));

            themesImpl.Initialize("themes", "default");

            // Act
            themesImpl.CurrentTheme = "mobile";
            var themePath = themesImpl.GetResourcePath(folder: "styles", fileName: "main.css");

            // Assert
            Assert.Equal(themePath, @"themes/default/styles/main.css");
        }
Ejemplo n.º 4
0
        public void ThemesImplUsesDefaultThemeWhenNoCurrentThemeIsSpecified()
        {
            // Arrange
            var defaultTheme   = "default-theme";
            var themeDirectory = "theme-directory";

            var scope      = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme)), scope);

            themesImpl.Initialize(themeDirectory, defaultTheme);

            // Act and Assert
            // CurrentTheme falls back to default theme when null
            Assert.Equal(themesImpl.CurrentTheme, defaultTheme);
        }
Ejemplo n.º 5
0
        public void GetResourcePathReturnsItemFromThemeRootIfAvailable()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile", "wp7.css")));

            themesImpl.Initialize("themes", "default");

            // Act
            themesImpl.CurrentTheme = "mobile";
            var themePath = themesImpl.GetResourcePath(fileName: "wp7.css");

            // Assert
            Assert.Equal(themePath, @"themes/mobile/wp7.css");
        }
Ejemplo n.º 6
0
        public void InitializeThrowsIfDefaultThemeDirectoryDoesNotExist()
        {
            // Arrange
            var defaultTheme = "default-theme";
            var themeDirectory = "theme-directory";

            var scope = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir("not-default-theme")), scope);

            // Act And Assert
            Assert.ThrowsArgument(
                () => themesImpl.Initialize(themeDirectory: themeDirectory, defaultTheme: defaultTheme),
                "defaultTheme",
                "Unknown theme 'default-theme'. Ensure that a directory labeled 'default-theme' exists under the theme directory.");
        }
        public void ThemesImplUsesScopeStorageToStoreCurrentTheme()
        {
            // Arrange
            var defaultTheme    = "default-theme";
            var themeDirectory  = "theme-directory";
            var currentThemeDir = "custom-theme-dir";
            var scope           = new ScopeStorageDictionary();
            var themesImpl      = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme), new Dir("custom-theme-dir")), scope);

            // Act
            themesImpl.Initialize(themeDirectory, defaultTheme);
            themesImpl.CurrentTheme = currentThemeDir;

            // Assert
            Assert.Equal(scope[ThemesImplementation.CurrentThemeKey], currentThemeDir);
        }
        public void AvaliableThemesReturnsTopLevelDirectoriesUnderThemeDirectory()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir("rotary-phone")));

            // Act
            themesImpl.Initialize("themes", "default");
            var themes = themesImpl.AvailableThemes;

            // Assert
            Assert.Equal(3, themes.Count);
            Assert.Equal(themes[0], "default");
            Assert.Equal(themes[1], "mobile");
            Assert.Equal(themes[2], "rotary-phone");
        }
Ejemplo n.º 9
0
        public void MatchingFiles_ReturnsCorrectFile()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(
                scopeStorage: new ScopeStorageDictionary(),
                vpp: GetVirtualPathProvider("themes", new Dir(@"nomatchingfiles", "foo.cs"))
                );

            // Act
            var bar = themesImpl.FindMatchingFile(@"themes\nomatchingfiles", "bar.cs");
            var foo = themesImpl.FindMatchingFile(@"themes\nomatchingfiles", "foo.cs");

            // Assert
            Assert.Null(bar);
            Assert.Equal(@"themes/nomatchingfiles/foo.cs", foo);
        }
        public void ThemesImplUsesScopeStorageToStoreProperties()
        {
            // Arrange
            var defaultTheme   = "default-theme";
            var themeDirectory = "theme-directory";

            var scope      = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme)), scope);

            // Act
            themesImpl.Initialize(themeDirectory: themeDirectory, defaultTheme: defaultTheme);

            // Ensure Theme use scope storage to store properties
            Assert.Equal(scope[ThemesImplementation.ThemesInitializedKey], true);
            Assert.Equal(scope[ThemesImplementation.ThemeDirectoryKey], themeDirectory);
            Assert.Equal(scope[ThemesImplementation.DefaultThemeKey], defaultTheme);
        }
Ejemplo n.º 11
0
        public void FileWithSlash_ReturnsNull()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(
                scopeStorage: new ScopeStorageDictionary(),
                vpp: GetVirtualPathProvider(
                    "themes",
                    new Dir("default"),
                    new Dir("root"),
                    new Dir(@"root\foo", "wp7.css"),
                    new Dir(@"default\styles", "main.css")
                    )
                );

            // Act
            var actual = themesImpl.FindMatchingFile("root", "foo/bar.cs");

            // Assert
            Assert.Null(actual);
        }
Ejemplo n.º 12
0
        public void GetResourcePathThrowsIfCurrentDirectoryIsNull()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(
                scopeStorage: new ScopeStorageDictionary(),
                vpp: GetVirtualPathProvider(
                    "themes",
                    new Dir("default"),
                    new Dir("mobile"),
                    new Dir(@"mobile", "wp7.css")
                    )
                );

            themesImpl.Initialize("themes", "default");

            // Act and Assert
            Assert.ThrowsArgumentNull(
                () => themesImpl.GetResourcePath(folder: null, fileName: "wp7.css"),
                "folder"
                );
        }
Ejemplo n.º 13
0
        public void CurrentThemeThrowsIfAssignedNullOrEmpty()
        {
            // Arrange
            var mockVpp    = new Mock <VirtualPathProvider>().Object;
            var scope      = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(mockVpp, scope);

            // Act and Assert
            Assert.ThrowsArgumentNullOrEmptyString(
                () =>
            {
                themesImpl.CurrentTheme = null;
            },
                "value"
                );
            Assert.ThrowsArgumentNullOrEmptyString(
                () =>
            {
                themesImpl.CurrentTheme = String.Empty;
            },
                "value"
                );
        }
Ejemplo n.º 14
0
        public void ThemesImplThrowsIfCurrentThemeIsInvalid()
        {
            // Arrange
            var defaultTheme   = "default-theme";
            var themeDirectory = "theme-directory";
            var themesImpl     = new ThemesImplementation(
                GetVirtualPathProvider(
                    themeDirectory,
                    new Dir(defaultTheme),
                    new Dir("not-a-random-value")
                    ),
                new ScopeStorageDictionary()
                );

            themesImpl.Initialize(themeDirectory, defaultTheme);

            // Act and Assert
            Assert.ThrowsArgument(
                () => themesImpl.CurrentTheme = "random-value",
                "value",
                "Unknown theme 'random-value'. Ensure that a directory labeled 'random-value' exists under the theme directory."
                );
        }
Ejemplo n.º 15
0
        public void InitializeThrowsIfDefaultThemeDirectoryDoesNotExist()
        {
            // Arrange
            var defaultTheme   = "default-theme";
            var themeDirectory = "theme-directory";

            var scope      = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(
                GetVirtualPathProvider(themeDirectory, new Dir("not-default-theme")),
                scope
                );

            // Act And Assert
            Assert.ThrowsArgument(
                () =>
                themesImpl.Initialize(
                    themeDirectory: themeDirectory,
                    defaultTheme: defaultTheme
                    ),
                "defaultTheme",
                "Unknown theme 'default-theme'. Ensure that a directory labeled 'default-theme' exists under the theme directory."
                );
        }
Ejemplo n.º 16
0
        public void DirectoryWithNoFilesReturnsNull()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("empty-dir")));

            // Act
            var actual = themesImpl.FindMatchingFile(@"themes\empty-dir", "main.css");

            // Assert
            Assert.Null(actual);
        }
Ejemplo n.º 17
0
        public void GetResourcePathThrowsIfCurrentDirectoryIsNull()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile", "wp7.css")));
            themesImpl.Initialize("themes", "default");

            // Act and Assert
            Assert.ThrowsArgumentNull(() => themesImpl.GetResourcePath(folder: null, fileName: "wp7.css"), "folder");
        }
Ejemplo n.º 18
0
        public void GetResourcePathThrowsIfFileNameIsNullOrEmpty()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile", "wp7.css")));
            themesImpl.Initialize("themes", "default");

            // Act and Assert
            Assert.ThrowsArgumentNullOrEmptyString(() => themesImpl.GetResourcePath(folder: String.Empty, fileName: null), "fileName");
            Assert.ThrowsArgumentNullOrEmptyString(() => themesImpl.GetResourcePath(folder: String.Empty, fileName: String.Empty), "fileName");
        }
Ejemplo n.º 19
0
        public void GetResourcePathReturnsItemFromDefaultThemeDirectoryIfNotFoundInCurrentThemeDirectory()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile\styles", "wp7.css"), new Dir(@"default\styles", "main.css")));
            themesImpl.Initialize("themes", "default");

            // Act
            themesImpl.CurrentTheme = "mobile";
            var themePath = themesImpl.GetResourcePath(folder: "styles", fileName: "main.css");

            // Assert
            Assert.Equal(themePath, @"themes/default/styles/main.css");
        }
Ejemplo n.º 20
0
        public void GetResourcePathReturnsItemFromThemeRootIfAvailable()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile", "wp7.css")));
            themesImpl.Initialize("themes", "default");

            // Act
            themesImpl.CurrentTheme = "mobile";
            var themePath = themesImpl.GetResourcePath(fileName: "wp7.css");

            // Assert
            Assert.Equal(themePath, @"themes/mobile/wp7.css");
        }
Ejemplo n.º 21
0
        public void GetResourcePathReturnsNullIfDirectoryDoesNotExist()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile\styles", "wp7.css"), new Dir(@"default\styles", "main.css")));
            themesImpl.Initialize("themes", "default");

            // Act
            themesImpl.CurrentTheme = "mobile";
            var themePath = themesImpl.GetResourcePath(folder: "does-not-exist", fileName: "main.css");

            // Assert
            Assert.Null(themePath);
        }
Ejemplo n.º 22
0
        public void ThemesImplUsesScopeStorageToStoreProperties()
        {
            // Arrange
            var defaultTheme = "default-theme";
            var themeDirectory = "theme-directory";

            var scope = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme)), scope);

            // Act
            themesImpl.Initialize(themeDirectory: themeDirectory, defaultTheme: defaultTheme);

            // Ensure Theme use scope storage to store properties
            Assert.Equal(scope[ThemesImplementation.ThemesInitializedKey], true);
            Assert.Equal(scope[ThemesImplementation.ThemeDirectoryKey], themeDirectory);
            Assert.Equal(scope[ThemesImplementation.DefaultThemeKey], defaultTheme);
        }
Ejemplo n.º 23
0
        public void ThemesImplUsesDefaultThemeWhenNoCurrentThemeIsSpecified()
        {
            // Arrange
            var defaultTheme = "default-theme";
            var themeDirectory = "theme-directory";

            var scope = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme)), scope);
            themesImpl.Initialize(themeDirectory, defaultTheme);

            // Act and Assert
            // CurrentTheme falls back to default theme when null
            Assert.Equal(themesImpl.CurrentTheme, defaultTheme);
        }
Ejemplo n.º 24
0
        public void ThemesImplUsesScopeStorageToStoreCurrentTheme()
        {
            // Arrange
            var defaultTheme = "default-theme";
            var themeDirectory = "theme-directory";
            var currentThemeDir = "custom-theme-dir";
            var scope = new ScopeStorageDictionary();
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme), new Dir("custom-theme-dir")), scope);

            // Act 
            themesImpl.Initialize(themeDirectory, defaultTheme);
            themesImpl.CurrentTheme = currentThemeDir;

            // Assert
            Assert.Equal(scope[ThemesImplementation.CurrentThemeKey], currentThemeDir);
        }
Ejemplo n.º 25
0
        public void GetResourcePathReturnsNullIfItemNotFoundInCurrentAndDefaultThemeDirectories()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir(@"mobile\styles", "wp7.css"), new Dir(@"default\styles", "main.css")));
            themesImpl.Initialize("themes", "default");

            // Act
            themesImpl.CurrentTheme = "mobile";
            var themePath = themesImpl.GetResourcePath(folder: "styles", fileName: "awesome-blinking-text.css");

            // Assert
            Assert.Null(themePath);
        }
Ejemplo n.º 26
0
        public void AvaliableThemesReturnsTopLevelDirectoriesUnderThemeDirectory()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("mobile"), new Dir("rotary-phone")));
            // Act
            themesImpl.Initialize("themes", "default");
            var themes = themesImpl.AvailableThemes;

            // Assert
            Assert.Equal(3, themes.Count);
            Assert.Equal(themes[0], "default");
            Assert.Equal(themes[1], "mobile");
            Assert.Equal(themes[2], "rotary-phone");
        }
Ejemplo n.º 27
0
        public void FileWithSlash_ReturnsNull()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir("default"), new Dir("root"), new Dir(@"root\foo", "wp7.css"), new Dir(@"default\styles", "main.css")));

            // Act
            var actual = themesImpl.FindMatchingFile("root", "foo/bar.cs");

            // Assert
            Assert.Null(actual);
        }
Ejemplo n.º 28
0
        public void MatchingFiles_ReturnsCorrectFile()
        {
            // Arrange
            var themesImpl = new ThemesImplementation(scopeStorage: new ScopeStorageDictionary(),
                                                      vpp: GetVirtualPathProvider("themes", new Dir(@"nomatchingfiles", "foo.cs")));

            // Act
            var bar = themesImpl.FindMatchingFile(@"themes\nomatchingfiles", "bar.cs");
            var foo = themesImpl.FindMatchingFile(@"themes\nomatchingfiles", "foo.cs");

            // Assert
            Assert.Null(bar);
            Assert.Equal(@"themes/nomatchingfiles/foo.cs", foo);
        }
Ejemplo n.º 29
0
        public void ThemesImplThrowsIfCurrentThemeIsInvalid()
        {
            // Arrange
            var defaultTheme = "default-theme";
            var themeDirectory = "theme-directory";
            var themesImpl = new ThemesImplementation(GetVirtualPathProvider(themeDirectory, new Dir(defaultTheme), new Dir("not-a-random-value")), new ScopeStorageDictionary());
            themesImpl.Initialize(themeDirectory, defaultTheme);

            // Act and Assert
            Assert.ThrowsArgument(() => themesImpl.CurrentTheme = "random-value",
                                                    "value",
                                                    "Unknown theme 'random-value'. Ensure that a directory labeled 'random-value' exists under the theme directory.");
        }