Exemplo n.º 1
0
        [TestCase("WhoIsNumber6InTheVillage", "Who Is Number6 In The Village")] // issue is fixed
        public void CompatibleDefaultReplacement(string input, string expected)
        {
            var helper = new DefaultShortStringHelper(SettingsForTests.GetDefaultUmbracoSettings());
            var output = input.Length < 2 ? input : helper.SplitPascalCasing(input, ' ').ToFirstUpperInvariant();

            Assert.AreEqual(expected, output);
        }
        public void SetUp()
        {
            Current.Reset();

            // FIXME: now UrlProvider depends on EntityService for GetUrl(guid) - this is bad
            // should not depend on more than IdkMap maybe - fix this!
            var entityService = new Mock <IEntityService>();

            entityService.Setup(x => x.GetId(It.IsAny <Guid>(), It.IsAny <UmbracoObjectTypes>())).Returns(Attempt <int> .Fail());
            var serviceContext = ServiceContext.CreatePartial(entityService: entityService.Object);

            // FIXME: bad in a unit test - but Udi has a static ctor that wants it?!
            var factory = new Mock <IFactory>();

            factory.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns(
                new TypeLoader(NoAppCache.Instance, IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>())));
            factory.Setup(x => x.GetInstance(typeof(ServiceContext))).Returns(serviceContext);

            var settings = SettingsForTests.GetDefaultUmbracoSettings();

            factory.Setup(x => x.GetInstance(typeof(IUmbracoSettingsSection))).Returns(settings);

            Current.Factory = factory.Object;

            Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();

            Udi.ResetUdiTypes();
        }
Exemplo n.º 3
0
        protected UmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable <IUrlProvider> urlProviders = null)
        {
            // ensure we have a PublishedSnapshotService
            var service = PublishedSnapshotService as PublishedSnapshotService;

            var httpContext = GetHttpContextFactory(url, routeData).HttpContext;

            var globalSettings = TestObjects.GetGlobalSettings();
            var umbracoContext = new UmbracoContext(
                httpContext,
                service,
                new WebSecurity(httpContext, Current.Services.UserService, globalSettings),
                umbracoSettings ?? SettingsForTests.GetDefaultUmbracoSettings(),
                urlProviders ?? Enumerable.Empty <IUrlProvider>(),
                Enumerable.Empty <IMediaUrlProvider>(),
                globalSettings,
                new TestVariationContextAccessor());

            if (setSingleton)
            {
                Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
            }

            return(umbracoContext);
        }
Exemplo n.º 4
0
            public void Compose(Composition composition)
            {
                composition.Register(factory => SettingsForTests.GetDefaultUmbracoSettings());
                composition.RegisterUnique <IExamineManager, TestExamineManager>();
                composition.Components().Append <TestComponent>();

                Composed = true;
            }
Exemplo n.º 5
0
        ViewContext GetViewContext()
        {
            var settings       = SettingsForTests.GetDefaultUmbracoSettings();
            var logger         = Mock.Of <ILogger>();
            var umbracoContext = GetUmbracoContext(
                logger, settings,
                "/dang", 0);

            var publishedRouter = BaseWebTest.CreatePublishedRouter(TestObjects.GetUmbracoSettings().WebRouting);
            var frequest        = publishedRouter.CreateRequest(umbracoContext, new Uri("http://localhost/dang"));

            frequest.Culture = CultureInfo.InvariantCulture;
            umbracoContext.PublishedRequest = frequest;

            var context = new ViewContext();

            context.RouteData = new RouteData();
            context.RouteData.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbracoContext);

            return(context);
        }
        protected override void Compose()
        {
            base.Compose();

            // set the default RenderMvcController
            Current.DefaultRenderMvcControllerType = typeof(RenderMvcController); // FIXME: Wrong!

            var surfaceControllerTypes = new SurfaceControllerTypeCollection(Composition.TypeLoader.GetSurfaceControllers());

            Composition.RegisterUnique(surfaceControllerTypes);

            var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(Composition.TypeLoader.GetUmbracoApiControllers());

            Composition.RegisterUnique(umbracoApiControllerTypes);

            Composition.RegisterUnique <IShortStringHelper>(_ => new DefaultShortStringHelper(SettingsForTests.GetDefaultUmbracoSettings()));
        }
Exemplo n.º 7
0
        public virtual void TestSetup()
        {
            //normalize culture
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            var register    = RegisterFactory.Create();
            var composition = new Composition(register, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run));

            register.Register <IShortStringHelper>(_
                                                   => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())));

            Current.Factory = composition.CreateFactory();
        }
        public void CleanStringCasing()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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 CleanStringUnderscoreInTerm()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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 CleanStringSymbols()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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 CleanStringSeparator()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
            {
                StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
                Separator  = '*'
            }));

            Assert.AreEqual("foo*bar", helper.CleanString("foo bar", CleanStringType.Alias));

            helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
            {
                StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
                Separator  = ' '
            }));
            Assert.AreEqual("foo bar", helper.CleanString("foo bar", CleanStringType.Alias));

            helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
            {
                StringType = CleanStringType.Utf8 | CleanStringType.Unchanged
            }));
            Assert.AreEqual("foobar", helper.CleanString("foo bar", CleanStringType.Alias));

            helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
            {
                StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
                Separator  = '文'
            }));
            Assert.AreEqual("foo文bar", helper.CleanString("foo bar", CleanStringType.Alias));
        }
        public void CleanStringGreedyAcronyms()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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 override void SetUp()
        {
            base.SetUp();

            // NOTE pre-filters runs _before_ Recode takes place
            // so there still may be utf8 chars even though you want ascii

            _helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                   .WithConfig(CleanStringType.FileName, new DefaultShortStringHelperConfig.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 DefaultShortStringHelperConfig.Config
            {
                PreFilter  = StripQuotes,
                IsTerm     = (c, leading) => char.IsLetterOrDigit(c) || c == '_',
                StringType = CleanStringType.LowerCase | CleanStringType.Ascii,
                Separator  = '-'
            })
                                                   .WithConfig("fr-FR", CleanStringType.UrlSegment, new DefaultShortStringHelperConfig.Config
            {
                PreFilter  = FilterFrenchElisions,
                IsTerm     = (c, leading) => leading ? char.IsLetter(c) : (char.IsLetterOrDigit(c) || c == '_'),
                StringType = CleanStringType.LowerCase | CleanStringType.Ascii,
                Separator  = '-'
            })
                                                   .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
            {
                PreFilter  = StripQuotes,
                IsTerm     = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c),
                StringType = CleanStringType.UmbracoCase | CleanStringType.Ascii
            })
                                                   .WithConfig("fr-FR", CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
            {
                PreFilter  = WhiteQuotes,
                IsTerm     = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c),
                StringType = CleanStringType.UmbracoCase | CleanStringType.Ascii
            })
                                                   .WithConfig(CleanStringType.ConvertCase, new DefaultShortStringHelperConfig.Config
            {
                PreFilter         = null,
                IsTerm            = (c, leading) => char.IsLetterOrDigit(c) || c == '_', // letter, digit or underscore
                StringType        = CleanStringType.Ascii,
                BreakTermsOnUpper = true
            }));

            // fixme - move to a "compose" thing?
            Composition.RegisterUnique <IShortStringHelper>(f => _helper);
        }
        public void CleanStringTermOnUpper()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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 CleanStringLeadingChars()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings()));
            Assert.AreEqual("child2", helper.CleanStringForSafeAlias("1child2"));
        }
        public void CleanStringEncoding()
        {
            var helper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                      .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings())
                                                  .WithConfig(CleanStringType.Alias, new DefaultShortStringHelperConfig.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));
        }
Exemplo n.º 17
0
        /// <summary>
        /// sets up resolvers before resolution is frozen
        /// </summary>
        protected override void Compose()
        {
            base.Compose();

            Composition.RegisterUnique <IShortStringHelper>(_ => new DefaultShortStringHelper(SettingsForTests.GetDefaultUmbracoSettings()));
        }