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")); }
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 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 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"); }
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"); }
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 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); }
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 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 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); }