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.");
        }
        public void ContainsKeyReturnsFalseIfItDoesNotContainKeyAndBaseIsNull()
        {
            // Arrange
            var scopeStorage = new ScopeStorageDictionary() { { "foo", "bar" } };

            // Act and Assert
            Assert.False(scopeStorage.ContainsKey("baz"));
        }
Ejemplo n.º 3
0
        public void ScopeStorageDictionaryIsNotReadOnly()
        {
            // Arrange
            var dictionary = new ScopeStorageDictionary();

            // Act and Assert
            Assert.False(dictionary.IsReadOnly);
        }
        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");
        }
        public void ContainsKeyReturnsFalseIfItDoesNotContainKeyAndBaseIsNull()
        {
            // Arrange
            var scopeStorage = new ScopeStorageDictionary()
            {
                { "foo", "bar" }
            };

            // Act and Assert
            Assert.False(scopeStorage.ContainsKey("baz"));
        }
Ejemplo n.º 6
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.º 7
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."
                );
        }
        public void AspNetStorageRetrievesRequestScopeAfterSettingAnonymousScopes() {
            // Arrange
            var provider = GetProvider();

            // Act 
            var requestScope = provider.RequestScope;
            
            var Scope = new ScopeStorageDictionary();
            provider.CurrentScope = Scope;

            Assert.AreEqual(provider.CurrentScope, Scope);
            Assert.AreEqual(provider.RequestScope, requestScope);
        }
        public void ClearRemovesAllItemsFromCurrentScope()
        {
            // Arrange
            var dictionary = new ScopeStorageDictionary {
                { "foo", "bar" }, { "foo2", "bar2" }
            };

            // Act
            dictionary.Clear();

            // Assert
            Assert.Equal(0, dictionary.Count);
        }
        public void Initialize_WithBadParams_Throws()
        {
            // Arrange
            var mockVpp = new Mock <VirtualPathProvider>().Object;
            var scope   = new ScopeStorageDictionary();

            // Act and Assert
            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize(null, "foo"), "themeDirectory");
            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize("", "foo"), "themeDirectory");

            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize("~/folder", null), "defaultTheme");
            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize("~/folder", ""), "defaultTheme");
        }
Ejemplo n.º 11
0
        public void Initialize_WithBadParams_Throws()
        {
            // Arrange
            var mockVpp = new Mock<VirtualPathProvider>().Object;
            var scope = new ScopeStorageDictionary();

            // Act and Assert
            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize(null, "foo"), "themeDirectory");
            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize("", "foo"), "themeDirectory");

            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize("~/folder", null), "defaultTheme");
            Assert.ThrowsArgumentNullOrEmptyString(() => new ThemesImplementation(mockVpp, scope).Initialize("~/folder", ""), "defaultTheme");
        }
Ejemplo n.º 12
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 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);
        }
        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.º 15
0
        public void AspNetStorageRetrievesRequestScopeAfterSettingAnonymousScopes()
        {
            // Arrange
            var provider = GetProvider();

            // Act
            var requestScope = provider.RequestScope;

            var Scope = new ScopeStorageDictionary();

            provider.CurrentScope = Scope;

            Assert.AreEqual(provider.CurrentScope, Scope);
            Assert.AreEqual(provider.RequestScope, requestScope);
        }
Ejemplo n.º 16
0
        public void ViewContextGlobalValidationMessageElementAffectsLocalOne()
        {
            // Arrange
            AppDomainUtils.RunInSeparateAppDomain(
                () =>
            {
                var httpContext = new Mock <HttpContextBase>();
                ScopeStorageDictionary localScope = null;
                var globalViewContext             = new ViewContext
                {
                    ScopeThunk  = () => ScopeStorage.GlobalScope,
                    HttpContext = httpContext.Object
                };
                var localViewContext = new ViewContext
                {
                    ScopeThunk = () =>
                    {
                        if (localScope == null)
                        {
                            localScope = new ScopeStorageDictionary(ScopeStorage.GlobalScope);
                        }
                        ;
                        return(localScope);
                    },
                    HttpContext = httpContext.Object
                };
                // A ScopeCache object will be stored into the hash table but the ScopeCache class is private,
                // so we cannot get the validation message element from it for Assert.
                httpContext.Setup(c => c.Items).Returns(new Hashtable());

                // Act
                globalViewContext.ValidationMessageElement = "label";

                // Assert
                // Global element was changed from "span" to "label".
                Assert.Equal("label", HtmlHelper.ValidationMessageElement);
                Assert.Equal("label", globalViewContext.ValidationMessageElement);
                object value;
                ScopeStorage.GlobalScope.TryGetValue("ValidationMessageElement", out value);
                Assert.Equal("label", value);

                // Local element was also changed to "label".
                Assert.Equal("label", localViewContext.ValidationMessageElement);
                localScope.TryGetValue("ValidationMessageElement", out value);
                Assert.Equal("label", value);
            }
                );
        }
        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 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.º 19
0
        public void ViewContextLocalValidationMessageElementDoesNotAffectGlobalOne()
        {
            // Arrange
            ScopeStorageDictionary localScope = null;
            var httpContext       = new Mock <HttpContextBase>();
            var globalViewContext = new ViewContext
            {
                ScopeThunk  = () => ScopeStorage.GlobalScope,
                HttpContext = httpContext.Object
            };
            var localViewContext = new ViewContext
            {
                ScopeThunk = () =>
                {
                    if (localScope == null)
                    {
                        localScope = new ScopeStorageDictionary(ScopeStorage.GlobalScope);
                    }
                    return(localScope);
                },
                HttpContext = httpContext.Object
            };

            // A ScopeCache object will be stored into the hash table but the ScopeCache class is private,
            // so we cannot get the validation message element from it for Assert.
            httpContext.Setup(c => c.Items).Returns(new Hashtable());

            // Act & Assert
            // Local element will be changed from "span" to "h4".
            Assert.Equal("span", localViewContext.ValidationMessageElement);
            localViewContext.ValidationMessageElement = "h4";
            Assert.Equal("h4", localViewContext.ValidationMessageElement);
            object value;

            localScope.TryGetValue("ValidationMessageElement", out value);
            Assert.Equal("h4", value);

            // Global element is still "span".
            Assert.Equal("span", globalViewContext.ValidationMessageElement);
            Assert.Empty(ScopeStorage.GlobalScope);
            Assert.Equal("span", HtmlHelper.ValidationMessageElement);
        }
        private ScopeStorageDictionary GetChainedStorageStateDictionary() {
            var root = new ScopeStorageDictionary();
            root["a"] = "a0";
            root["b"] = "b0";
            root["c"] = "c0";
            
            var firstGen = new ScopeStorageDictionary(baseScope: root);
            firstGen["a"] = "a1";
            firstGen["b"] = "b1";
            firstGen["d"] = "d1";
            firstGen["e"] = "e1";
                

            var secondGen = new ScopeStorageDictionary(baseScope: firstGen);
            secondGen["a"] = "a2";
            secondGen["d"] = "d2";
            secondGen["f"] = "f2";

            return secondGen;
        }
        private ScopeStorageDictionary GetChainedStorageStateDictionary()
        {
            var root = new ScopeStorageDictionary();

            root["a"] = "a0";
            root["b"] = "b0";
            root["c"] = "c0";

            var firstGen = new ScopeStorageDictionary(baseScope: root);

            firstGen["a"] = "a1";
            firstGen["b"] = "b1";
            firstGen["d"] = "d1";
            firstGen["e"] = "e1";

            var secondGen = new ScopeStorageDictionary(baseScope: firstGen);

            secondGen["a"] = "a2";
            secondGen["d"] = "d2";
            secondGen["f"] = "f2";

            return(secondGen);
        }
        public void ClearRemovesAllItemsFromCurrentScope()
        {
            // Arrange
            var dictionary = new ScopeStorageDictionary { { "foo", "bar" }, { "foo2", "bar2" } };

            // Act
            dictionary.Clear();

            // Assert
            Assert.Equal(0, dictionary.Count);
        }
Ejemplo n.º 23
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.º 24
0
        public void ViewContextGlobalValidationMessageElementAffectsLocalOne()
        {
            // Arrange
            AppDomainUtils.RunInSeparateAppDomain(() =>
            {
                var httpContext = new Mock<HttpContextBase>();
                ScopeStorageDictionary localScope = null;
                var globalViewContext = new ViewContext
                {
                    ScopeThunk = () => ScopeStorage.GlobalScope,
                    HttpContext = httpContext.Object
                };
                var localViewContext = new ViewContext
                {
                    ScopeThunk = () =>
                    {
                        if (localScope == null)
                        {
                            localScope = new ScopeStorageDictionary(ScopeStorage.GlobalScope);
                        };
                        return localScope;
                    },
                    HttpContext = httpContext.Object
                };
                // A ScopeCache object will be stored into the hash table but the ScopeCache class is private,
                // so we cannot get the validation message element from it for Assert.
                httpContext.Setup(c => c.Items).Returns(new Hashtable());

                // Act
                globalViewContext.ValidationMessageElement = "label";

                // Assert
                // Global element was changed from "span" to "label".
                Assert.Equal("label", HtmlHelper.ValidationMessageElement);
                Assert.Equal("label", globalViewContext.ValidationMessageElement);
                object value;
                ScopeStorage.GlobalScope.TryGetValue("ValidationMessageElement", out value);
                Assert.Equal("label", value);

                // Local element was also changed to "label".
                Assert.Equal("label", localViewContext.ValidationMessageElement);
                localScope.TryGetValue("ValidationMessageElement", out value);
                Assert.Equal("label", value);
            });
        }
Ejemplo n.º 25
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.º 26
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);
        }
        public void ScopeStorageDictionaryIsNotReadOnly()
        {
            // Arrange
            var dictionary = new ScopeStorageDictionary();

            // Act and Assert
            Assert.False(dictionary.IsReadOnly);
        }
Ejemplo n.º 28
0
        public void ViewContextLocalValidationMessageElementDoesNotAffectGlobalOne()
        {
            // Arrange
            ScopeStorageDictionary localScope = null;
            var httpContext = new Mock<HttpContextBase>();
            var globalViewContext = new ViewContext
            {
                ScopeThunk = () => ScopeStorage.GlobalScope,
                HttpContext = httpContext.Object
            };
            var localViewContext = new ViewContext
            {
                ScopeThunk = () =>
                {
                    if (localScope == null)
                    {
                        localScope = new ScopeStorageDictionary(ScopeStorage.GlobalScope);
                    }
                    return localScope;
                },
                HttpContext = httpContext.Object
            };
            // A ScopeCache object will be stored into the hash table but the ScopeCache class is private,
            // so we cannot get the validation message element from it for Assert.
            httpContext.Setup(c => c.Items).Returns(new Hashtable());

            // Act & Assert
            // Local element will be changed from "span" to "h4".
            Assert.Equal("span", localViewContext.ValidationMessageElement);
            localViewContext.ValidationMessageElement = "h4";
            Assert.Equal("h4", localViewContext.ValidationMessageElement);
            object value;
            localScope.TryGetValue("ValidationMessageElement", out value);
            Assert.Equal("h4", value);

            // Global element is still "span".
            Assert.Equal("span", globalViewContext.ValidationMessageElement);
            Assert.Empty(ScopeStorage.GlobalScope);
            Assert.Equal("span", HtmlHelper.ValidationMessageElement);
        }