public void Using_Dictionary_Returns_Text_With_Area()
    {
        var culture    = CultureInfo.GetCultureInfo("en-US");
        var txtService = new LocalizedTextService(
            new Dictionary <CultureInfo, Lazy <IDictionary <string, IDictionary <string, string> > > >
        {
            {
                culture,
                new Lazy <IDictionary <string, IDictionary <string, string> > >(() =>
                                                                                new Dictionary <string, IDictionary <string, string> >
                {
                    { "testArea", new Dictionary <string, string> {
                          { "testKey", "testValue" }
                      } },
                })
            },
        },
            s_loggerFactory.CreateLogger <LocalizedTextService>());

        var result = txtService.Localize("testArea/testKey", culture);

        Assert.AreEqual("testValue", result);
    }
        public void Using_Dictionary_Returns_Default_Text_When_Not_Found_Without_Area()
        {
            var culture    = CultureInfo.GetCultureInfo("en-US");
            var txtService = new LocalizedTextService(
                new Dictionary <CultureInfo, Lazy <IDictionary <string, IDictionary <string, string> > > >
            {
                {
                    culture, new Lazy <IDictionary <string, IDictionary <string, string> > >(() => new Dictionary <string, IDictionary <string, string> >
                    {
                        {
                            "testArea", new Dictionary <string, string>
                            {
                                { "testKey", "testValue" }
                            }
                        }
                    })
                }
            }, s_loggerFactory.CreateLogger <LocalizedTextService>());

            string result = txtService.Localize("doNotFind", culture);

            Assert.AreEqual("[doNotFind]", result);
        }
예제 #3
0
        public void Using_Dictionary_Returns_Text_Without_Area()
        {
            var culture    = CultureInfo.GetCultureInfo("en-US");
            var txtService = new LocalizedTextService(
                new Dictionary <CultureInfo, IDictionary <string, IDictionary <string, string> > >
            {
                {
                    culture, new Dictionary <string, IDictionary <string, string> >
                    {
                        {
                            "testArea", new Dictionary <string, string>
                            {
                                { "testKey", "testValue" }
                            }
                        }
                    }
                }
            }, Mock.Of <ILogger>());

            var result = txtService.Localize("testKey", culture);

            Assert.AreEqual("testValue", result);
        }
예제 #4
0
    /// <summary>
    ///     The actual health check method.
    /// </summary>
    protected async Task <HealthCheckStatus> CheckForHeader()
    {
        string message;
        var    success = false;

        // Access the site home page and check for the click-jack protection header or meta tag
        var url = _hostingEnvironment.ApplicationMainUrl?.GetLeftPart(UriPartial.Authority);

        try
        {
            using HttpResponseMessage response = await HttpClient.GetAsync(url);

            // Check first for header
            success = HasMatchingHeader(response.Headers.Select(x => x.Key));

            // If not found, and available, check for meta-tag
            if (success == false && _metaTagOptionAvailable)
            {
                success = await DoMetaTagsContainKeyForHeader(response);
            }

            message = success
                ? LocalizedTextService.Localize("healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
                : LocalizedTextService.Localize("healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
        }
        catch (Exception ex)
        {
            message = LocalizedTextService.Localize("healthcheck", "healthCheckInvalidUrl", new[] { url, ex.Message });
        }

        return
            (new HealthCheckStatus(message)
        {
            ResultType = success ? StatusResultType.Success : StatusResultType.Error,
            ReadMoreLink = success ? null : ReadMoreLink,
        });
    }
    public void Using_Dictionary_Returns_Default_Text_When_Not_Found_With_Area()
    {
        var culture    = CultureInfo.GetCultureInfo("en-US");
        var txtService = new LocalizedTextService(
            new Dictionary <CultureInfo, Lazy <IDictionary <string, IDictionary <string, string> > > >
        {
            {
                culture,
                new Lazy <IDictionary <string, IDictionary <string, string> > >(() =>
                                                                                new Dictionary <string, IDictionary <string, string> >
                {
                    { "testArea", new Dictionary <string, string> {
                          { "testKey", "testValue" }
                      } },
                })
            },
        },
            s_loggerFactory.CreateLogger <LocalizedTextService>());

        var result = txtService.Localize("testArea/doNotFind", culture);

        // NOTE: Based on how legacy works, the default text does not contain the area, just the key
        Assert.AreEqual("[doNotFind]", result);
    }
        protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();

            if (id == Constants.System.RootString)
            {
                nodes.Add(
                        CreateTreeNode(Constants.Conventions.MemberTypes.AllMembersListId, id, queryStrings, LocalizedTextService.Localize("member","allMembers"), Constants.Icons.MemberType, true,
                            queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + Constants.Conventions.MemberTypes.AllMembersListId));

                nodes.AddRange(_memberTypeService.GetAll()
                        .Select(memberType =>
                            CreateTreeNode(memberType.Alias, id, queryStrings, memberType.Name, memberType.Icon.IfNullOrWhiteSpace(Constants.Icons.Member), true,
                                queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + memberType.Alias)));
            }

            //There is no menu for any of these nodes
            nodes.ForEach(x => x.MenuUrl = null);
            //All nodes are containers
            nodes.ForEach(x => x.AdditionalData.Add("isContainer", true));

            return nodes;
        }
예제 #7
0
        protected override ActionResult <MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
        {
            var menu = _menuItemCollectionFactory.Create();

            if (id == Constants.System.RootString)
            {
                // set the default to create
                menu.DefaultMenuAlias = ActionNew.ActionAlias;

                // root actions
                menu.Items.Add <ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
                menu.Items.Add(new RefreshNode(LocalizedTextService));
                return(menu);
            }

            var container = _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.MediaTypeContainer);

            if (container != null)
            {
                // set the default to create
                menu.DefaultMenuAlias = ActionNew.ActionAlias;

                menu.Items.Add <ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);

                menu.Items.Add(new MenuItem("rename", LocalizedTextService.Localize("actions", "rename"))
                {
                    Icon          = "icon-edit",
                    UseLegacyIcon = false
                });

                if (container.HasChildren == false)
                {
                    // can delete doc type
                    menu.Items.Add <ActionDelete>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
                }
                menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            }
            else
            {
                var ct     = _mediaTypeService.Get(int.Parse(id, CultureInfo.InvariantCulture));
                var parent = ct == null ? null : _mediaTypeService.Get(ct.ParentId);

                menu.Items.Add <ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);

                // no move action if this is a child doc type
                if (parent == null)
                {
                    menu.Items.Add <ActionMove>(LocalizedTextService, true, opensDialog: true, useLegacyIcon: false);
                }

                menu.Items.Add <ActionCopy>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
                if (ct?.IsSystemMediaType() == false)
                {
                    menu.Items.Add <ActionDelete>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
                }

                menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            }

            return(menu);
        }