public void SetUp() { var settings = SettingsForTests.GetDefault(); ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(settings).WithDefaultConfig()); Resolution.Freeze(); }
public void CleanStringGreedyAcronyms() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, CutAcronymOnNonUpper = true, GreedyAcronyms = true, Separator = '*' }); Assert.AreEqual("foo*BARR*nil", helper.CleanString("foo BARRnil", CleanStringType.Alias)); Assert.AreEqual("foo*BAR*nil", helper.CleanString("foo BARnil", CleanStringType.Alias)); Assert.AreEqual("foo*BA*nil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, CutAcronymOnNonUpper = true, GreedyAcronyms = false, Separator = '*' }); Assert.AreEqual("foo*BAR*Rnil", helper.CleanString("foo BARRnil", CleanStringType.Alias)); Assert.AreEqual("foo*BA*Rnil", helper.CleanString("foo BARnil", CleanStringType.Alias)); Assert.AreEqual("foo*BAnil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); }
public void CleanStringSeparator() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("foo*bar", helper.CleanString("foo bar", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = ' ' }); Assert.AreEqual("foo bar", helper.CleanString("foo bar", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged }); Assert.AreEqual("foobar", helper.CleanString("foo bar", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '文' }); Assert.AreEqual("foo文bar", helper.CleanString("foo bar", CleanStringType.Alias)); }
public void CleanStringLeadingChars() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { // letters and digits are valid leading chars IsTerm = (c, leading) => char.IsLetterOrDigit(c), StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("0123foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { // only letters are valid leading chars IsTerm = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c), StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias)); Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123 foo_bar 543 nil 321", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()).WithDefaultConfig(); Assert.AreEqual("child2", helper.CleanStringForSafeAlias("1child2")); }
[TestCase("WhoIsNumber6InTheVillage", "Who Is Number6 In The Village")] // issue is fixed public void CompatibleDefaultReplacement(string input, string expected) { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()); var output = input.Length < 2 ? input : helper.SplitPascalCasing(input, ' ').ToFirstUpperInvariant(); Assert.AreEqual(expected, output); }
public void U4_4056_TryAscii() { var settings = SettingsForTests.GenerateMockSettings(); var contentMock = Mock.Get(settings.RequestHandler); contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty <IChar>()); contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); SettingsForTests.ConfigureSettings(settings); const string input1 = "ÆØÅ and æøå and 中文测试 and אודות האתר and größer БбДдЖж page"; const string input2 = "ÆØÅ and æøå and größer БбДдЖж page"; var helper = new DefaultShortStringHelper(settings).WithDefaultConfig(); // unicode Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input1)); Assert.AreEqual("æøå-and-æøå-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input2)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.UrlSegment, new DefaultShortStringHelper.Config { IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', StringType = CleanStringType.LowerCase | CleanStringType.TryAscii, // try ascii Separator = '-' }); Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", helper.CleanStringForUrlSegment(input1)); Assert.AreEqual("aeoa-and-aeoa-and-grosser-bbddzhzh-page", helper.CleanStringForUrlSegment(input2)); }
ViewContext GetViewContext() { var settings = SettingsForTests.GetDefault(); var logger = Mock.Of <ILogger>(); var umbracoContext = GetUmbracoContext( logger, settings, "/dang", 0); var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider(settings.RequestHandler) }); var routingContext = new RoutingContext( umbracoContext, Enumerable.Empty <IContentFinder>(), new FakeLastChanceFinder(), urlProvider); umbracoContext.RoutingContext = routingContext; var request = new PublishedContentRequest( new Uri("http://localhost/dang"), routingContext, settings.WebRouting, s => Enumerable.Empty <string>()); request.Culture = CultureInfo.InvariantCulture; umbracoContext.PublishedContentRequest = request; var context = new ViewContext(); context.RouteData = new RouteData(); context.RouteData.DataTokens.Add("umbraco-context", umbracoContext); return(context); }
public void Setup() { //set default config var config = SettingsForTests.GetDefault(); SettingsForTests.ConfigureSettings(config); }
public void Setup() { //init the config singleton var config = SettingsForTests.GetDefault(); SettingsForTests.ConfigureSettings(config); }
public void Setup() { var config = SettingsForTests.GetDefault(); SettingsForTests.ConfigureSettings(config); _helper = new LegacyShortStringHelper(); }
public void CleanStringAcronymOnNonUpper() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, // non-uppercase letter means cut acronym CutAcronymOnNonUpper = true, Separator = '*' }); Assert.AreEqual("foo*BAR*Rnil", helper.CleanString("foo BARRnil", CleanStringType.Alias)); Assert.AreEqual("foo*BA*Rnil", helper.CleanString("foo BARnil", CleanStringType.Alias)); Assert.AreEqual("foo*BAnil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, // non-uppercase letter means word CutAcronymOnNonUpper = false, Separator = '*' }); Assert.AreEqual("foo*BARRnil", helper.CleanString("foo BARRnil", CleanStringType.Alias)); Assert.AreEqual("foo*BARnil", helper.CleanString("foo BARnil", CleanStringType.Alias)); Assert.AreEqual("foo*BAnil", helper.CleanString("foo BAnil", CleanStringType.Alias)); Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias)); }
public void Initialize() { // NOTE: it is not possible to configure the helper once it has been assigned // to the resolver and resolution has frozen. but, obviously, it is possible // to configure filters and then to alter these filters after resolution has // frozen. beware, nothing is thread-safe in-there! // NOTE pre-filters runs _before_ Recode takes place // so there still may be utf8 chars even though you want ascii _helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.FileName, new DefaultShortStringHelper.Config { //PreFilter = ClearFileChars, // done in IsTerm IsTerm = (c, leading) => (char.IsLetterOrDigit(c) || c == '_') && DefaultShortStringHelper.IsValidFileNameChar(c), StringType = CleanStringType.LowerCase | CleanStringType.Ascii, Separator = '-' }) .WithConfig(CleanStringType.UrlSegment, new DefaultShortStringHelper.Config { PreFilter = StripQuotes, IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', StringType = CleanStringType.LowerCase | CleanStringType.Ascii, Separator = '-' }) .WithConfig(new CultureInfo("fr-FR"), CleanStringType.UrlSegment, new DefaultShortStringHelper.Config { PreFilter = FilterFrenchElisions, IsTerm = (c, leading) => leading ? char.IsLetter(c) : (char.IsLetterOrDigit(c) || c == '_'), StringType = CleanStringType.LowerCase | CleanStringType.Ascii, Separator = '-' }) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { PreFilter = StripQuotes, IsTerm = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c), StringType = CleanStringType.UmbracoCase | CleanStringType.Ascii }) .WithConfig(new CultureInfo("fr-FR"), CleanStringType.Alias, new DefaultShortStringHelper.Config { PreFilter = WhiteQuotes, IsTerm = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c), StringType = CleanStringType.UmbracoCase | CleanStringType.Ascii }) .WithConfig(CleanStringType.ConvertCase, new DefaultShortStringHelper.Config { PreFilter = null, IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', // letter, digit or underscore StringType = CleanStringType.Ascii, BreakTermsOnUpper = true }); ShortStringHelperResolver.Reset(); ShortStringHelperResolver.Current = new ShortStringHelperResolver(_helper); Resolution.Freeze(); }
public void TestSetup() { _savedCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); // make sure the dates parse correctly var settings = SettingsForTests.GetDefault(); ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(settings).WithDefaultConfig()); Resolution.Freeze(); }
public void Setup() { //we DO want cache enabled for these tests var cacheHelper = new CacheHelper( new ObjectCacheRuntimeCacheProvider(), new StaticCacheProvider(), new NullCacheProvider()); ApplicationContext.Current = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); UmbracoConfig.For.SetUmbracoSettings(SettingsForTests.GetDefault()); }
protected override void SetupApplicationContext() { var settings = SettingsForTests.GetDefault(); ApplicationContext.Current = new ApplicationContext( new DatabaseContext(Mock.Of <IDatabaseFactory>(), Logger, Mock.Of <ISqlSyntaxProvider>(), "test"), GetServiceContext(settings, Logger), CacheHelper, ProfilingLogger) { IsReady = true }; }
protected override ApplicationContext CreateApplicationContext() { var settings = SettingsForTests.GetDefault(); return(new ApplicationContext( new DatabaseContext(Mock.Of <IScopeProviderInternal>(), Logger, Mock.Of <ISqlSyntaxProvider>(), "test"), GetServiceContext(settings, Logger), CacheHelper, ProfilingLogger) { IsReady = true }); }
public void Setup() { //init the config singleton var config = SettingsForTests.GetDefault(); SettingsForTests.ConfigureSettings(config); // media fs wants this ApplicationContext.Current = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())); // start clean // because some tests will create corrupt or weird filesystems FileSystemProviderManager.ResetCurrent(); }
public void CleanStringSymbols() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("house*2", helper.CleanString("house (2)", CleanStringType.Alias)); // FIXME but for a filename we want to keep them! // FIXME and what about a url? }
public void CleanStringCasing() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = ' ' }); // BBB is an acronym // E is a word (too short to be an acronym) // FF is an acronym // FIXME "C" can't be an acronym // FIXME "DBXreview" = acronym?! Assert.AreEqual("aaa BBB CCc Ddd E FF", helper.CleanString("aaa BBB CCc Ddd E FF", CleanStringType.Alias)); // unchanged Assert.AreEqual("aaa Bbb Ccc Ddd E FF", helper.CleanString("aaa BBB CCc Ddd E FF", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("Aaa Bbb Ccc Ddd E FF", helper.CleanString("aaa BBB CCc Ddd E FF", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("aaa bbb ccc ddd e ff", helper.CleanString("aaa BBB CCc Ddd E FF", CleanStringType.Alias | CleanStringType.LowerCase)); Assert.AreEqual("AAA BBB CCC DDD E FF", helper.CleanString("aaa BBB CCc Ddd E FF", CleanStringType.Alias | CleanStringType.UpperCase)); Assert.AreEqual("aaa BBB CCc Ddd E FF", helper.CleanString("aaa BBB CCc Ddd E FF", CleanStringType.Alias | CleanStringType.UmbracoCase)); // MS rules & guidelines: // - Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier. // eg "DBRate" (pascal) or "ioHelper" (camel) - "SpecialDBRate" (pascal) or "specialIOHelper" (camel) // - Do capitalize only the first character of acronyms with three or more characters, except the first word of a camel-cased identifier. // eg "XmlWriter (pascal) or "htmlReader" (camel) - "SpecialXmlWriter" (pascal) or "specialHtmlReader" (camel) // - Do not capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier. // eg "xmlWriter" or "dbWriter" (camel) Assert.AreEqual("aaa BB Ccc", helper.CleanString("aaa BB ccc", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("aa Bb Ccc", helper.CleanString("AA bb ccc", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("aaa Bb Ccc", helper.CleanString("AAA bb ccc", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("db Rate", helper.CleanString("DB rate", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("special DB Rate", helper.CleanString("special DB rate", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("xml Writer", helper.CleanString("XML writer", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("special Xml Writer", helper.CleanString("special XML writer", CleanStringType.Alias | CleanStringType.CamelCase)); Assert.AreEqual("Aaa BB Ccc", helper.CleanString("aaa BB ccc", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("AA Bb Ccc", helper.CleanString("AA bb ccc", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("Aaa Bb Ccc", helper.CleanString("AAA bb ccc", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("DB Rate", helper.CleanString("DB rate", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("Special DB Rate", helper.CleanString("special DB rate", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("Xml Writer", helper.CleanString("XML writer", CleanStringType.Alias | CleanStringType.PascalCase)); Assert.AreEqual("Special Xml Writer", helper.CleanString("special XML writer", CleanStringType.Alias | CleanStringType.PascalCase)); }
public void CleanStringEncoding() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("中文测试", helper.CleanString("中文测试", CleanStringType.Alias)); Assert.AreEqual("léger*中文测试*ZÔRG", helper.CleanString("léger 中文测试 ZÔRG", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Ascii | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("", helper.CleanString("中文测试", CleanStringType.Alias)); Assert.AreEqual("leger*ZORG", helper.CleanString("léger 中文测试 ZÔRG", CleanStringType.Alias)); }
public void CleanStringUnderscoreInTerm() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { // underscore is accepted within terms IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("foo_bar*nil", helper.CleanString("foo_bar nil", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { // underscore is not accepted within terms IsTerm = (c, leading) => char.IsLetterOrDigit(c), StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, Separator = '*' }); Assert.AreEqual("foo*bar*nil", helper.CleanString("foo_bar nil", CleanStringType.Alias)); }
public void CleanStringTermOnUpper() { var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, // uppercase letter means new term BreakTermsOnUpper = true, Separator = '*' }); Assert.AreEqual("foo*Bar", helper.CleanString("fooBar", CleanStringType.Alias)); helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()) .WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config { StringType = CleanStringType.Utf8 | CleanStringType.Unchanged, // uppercase letter is part of term BreakTermsOnUpper = false, Separator = '*' }); Assert.AreEqual("fooBar", helper.CleanString("fooBar", CleanStringType.Alias)); }
public void Init() { var config = SettingsForTests.GetDefault(); SettingsForTests.ConfigureSettings(config); }
public virtual void TestSetup() { //normalize culture Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(SettingsForTests.GetDefault())); Resolution.Freeze(); }
public virtual void TestSetup() { UmbracoExamineSearcher.DisableInitializationCheck = true; BaseUmbracoIndexer.DisableInitializationCheck = true; ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(SettingsForTests.GetDefault())); Resolution.Freeze(); }
/// <summary> /// sets up resolvers before resolution is frozen /// </summary> protected override void FreezeResolution() { UmbracoExamineSearcher.DisableInitializationCheck = true; BaseUmbracoIndexer.DisableInitializationCheck = true; ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(SettingsForTests.GetDefault())); base.FreezeResolution(); }