[Test] public void CascadedTemplate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			loc.Add("Report2", "Report {Plural'1}/{Plural'2}");
			Assert.AreEqual("Report Scopes/Storys", loc.Resolve("Report2'Scope'Story"));
		}
        [Test] public void ConditionalSpaceYes()
        {
            Localizer loc = new Localizer(null);

            loc.Add("A", "x {1}");
            loc.Add("B", "y");
            Assert.AreEqual("x y", loc.Resolve("A'B"));
        }
        [Test] public void BracesNest()
        {
            Localizer loc = new Localizer(null);

            loc.Add("match", "open {{{and}}} close");
            loc.Add("and", "xyz");
            Assert.AreEqual("open {xyz} close", loc.Resolve("match"));
        }
        [Test] public void MatchingDoubleBrace()
        {
            Localizer loc = new Localizer(null);

            loc.Add("match", "open {{and}} close");
            loc.Add("and", "xyz");
            Assert.AreEqual("open {and} close", loc.Resolve("match"));
        }
		[Test] public void PluralAssocTemplate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			loc.Add("Plural'AssetType", "{Plural'{1'2}'}");
			loc.Add("AssetType'Fronat", "Memo");
			Assert.AreEqual("Memos", loc.Resolve("Plural'AssetType'Fronat"));
		}
        [Test] public void AlwaysExpandCascaded()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Add'Story", "Add {Story}");
            loc.Add("Story", "Backlog Item");
            Assert.AreEqual("Add Backlog Item", loc.Resolve("Add'Story"));
        }
		[Test] public void PluralNestTemplate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			loc.Add("Plural'AssetType", "{Plural'{1'2}'x}");
			loc.Add("AssetType'Story", "Backlog Item");
			Assert.AreEqual("Backlog Items", loc.Resolve("Plural'AssetType'Story"));
		}
		[Test] public void TemplateOverride ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			loc.Add("Plural'Story", "Stories");
			Assert.AreEqual("Scopes", loc.Resolve("Plural'Scope"));
			Assert.AreEqual("Stories", loc.Resolve("Plural'Story"));
		}
        [Test] public void CascadedTemplate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            loc.Add("Report2", "Report {Plural'1}/{Plural'2}");
            Assert.AreEqual("Report Scopes/Storys", loc.Resolve("Report2'Scope'Story"));
        }
        [Test] public void DoubleBrace()
        {
            Localizer loc = new Localizer(null);

            loc.Add("open", "open {{ brace");
            loc.Add("close", "close }} brace");
            Assert.AreEqual("open { brace", loc.Resolve("open"));
            Assert.AreEqual("close } brace", loc.Resolve("close"));
        }
        [Test] public void AlwaysExpandSubstitution()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Add", "Add {1}");
            loc.Add("Story", "Backlog Item");
            loc.Add("Backlog Item", "bogus");
            Assert.AreEqual("Add Backlog Item", loc.Resolve("Add'Story"));
        }
        [Test] public void TemplateOverride()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            loc.Add("Plural'Story", "Stories");
            Assert.AreEqual("Scopes", loc.Resolve("Plural'Scope"));
            Assert.AreEqual("Stories", loc.Resolve("Plural'Story"));
        }
        [Test] public void PluralAssocTemplate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            loc.Add("Plural'AssetType", "{Plural'{1'2}'}");
            loc.Add("AssetType'Fronat", "Memo");
            Assert.AreEqual("Memos", loc.Resolve("Plural'AssetType'Fronat"));
        }
        [Test] public void PluralNestTemplate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            loc.Add("Plural'AssetType", "{Plural'{1'2}'x}");
            loc.Add("AssetType'Story", "Backlog Item");
            Assert.AreEqual("Backlog Items", loc.Resolve("Plural'AssetType'Story"));
        }
		[Test] public void ComplexTemplate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			loc.Add("Plural'Story", "Stories");
			loc.Add("Report2", "Report {Plural'1}/{Plural'2}");
			loc.Add("Scope", "Project");
			Assert.AreEqual("Report Projects/Stories", loc.Resolve("Report2'Scope'Story"));
		}
        [Test] public void ComplexTemplate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            loc.Add("Plural'Story", "Stories");
            loc.Add("Report2", "Report {Plural'1}/{Plural'2}");
            loc.Add("Scope", "Project");
            Assert.AreEqual("Report Projects/Stories", loc.Resolve("Report2'Scope'Story"));
        }
        [Test] public void AlwaysExpand()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Add'Story", "Add {Story}");
            Assert.AreEqual("Add Story", loc.Resolve("Add'Story"));
        }
        [Test] public void EmptyBraces()
        {
            Localizer loc = new Localizer(null);

            loc.Add("A", "{}");
            Assert.AreEqual("", loc.Resolve("A"));
        }
        [Test] public void PluralTemplate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            Assert.AreEqual("AssetTypes", loc.Resolve("Plural'AssetType'Story"));
        }
        [Test] public void SimpleTemplate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("Plural", "{1}s");
            Assert.AreEqual("Storys", loc.Resolve("Plural'Story"));
        }
        [Test] public void SimpleTranslate()
        {
            Localizer loc = new Localizer(null);

            loc.Add("tag1", "This is the tag 1 string");
            Assert.AreEqual("This is the tag 1 string", loc.Resolve("tag1"));
        }
        [Test] public void NoInfiniteRecursion()
        {
            Localizer loc = new Localizer(null);

            loc.Add("bogus", "recursive {0} recursive");
            Assert.AreEqual("recursive bogus recursive", loc.Resolve("bogus"));
        }
Beispiel #23
0
        public void Test005()
        {
            // Arrange
            var headerKey = "alert-heading";
            var localizer = new Localizer()
            {
                CultureCode = "Yoda"
            };

            localizer.Add(headerKey, "Time to focus on Blazor it is.");

            // Act
            var cut = RenderComponent <Alert>(
                (nameof(Alert.Header), headerKey),
                CascadingValue(localizer)
                );

            // Assert
            var expected = cut.Find(".alert-heading").TextContent;

            Assert.Equal(localizer[headerKey], expected);

            var expectedMarkup = $@"<h4 class=""alert-heading"">{localizer[headerKey]}</h4>";

            cut.Find(".alert-heading").MarkupMatches(expectedMarkup);
        }
        [Test] public void ValueWithSpecialCharacter()
        {
            const string tag         = "solution";
            const string translation = "løsningsforslag";
            var          loc         = new Localizer(null);

            loc.Add(tag, translation);
            Assert.AreEqual(translation, loc.Resolve(tag));
        }
        public void SignaturesAreUniqueBasedOnKeysAndValues()
        {
            Localizer loc = new Localizer(null);

            loc.Add("tag1", "This is the tag 1 string");
            Localizer loc2 = new Localizer(null);

            loc2.Add("tag1This is the tag 1 string", "");
            Assert.AreNotEqual(loc.Signature, loc2.Signature);
        }
        public void SignaturesAreStable()
        {
            Localizer loc = new Localizer(null);

            loc.Add("tag1", "This is the tag 1 string");
            Localizer loc2 = new Localizer(null);

            loc2.Add("tag1", "This is the tag 1 string");
            Assert.AreEqual(loc.Signature, loc2.Signature);
        }
        public void LocalizersWithDifferentFallbacksHaveUniqueSignatures()
        {
            Localizer fallback = new Localizer(null);

            fallback.Add("fallback", "fallback string");
            Localizer loc = new Localizer(fallback);

            loc.Add("tag1", "This is the tag 1 string");

            Localizer fallback2 = new Localizer(null);

            fallback2.Add("fallback2", "fallback2 string");
            Localizer loc2 = new Localizer(null);

            loc2.Add("tag1", "This is the tag 1 string");
            Assert.AreNotEqual(loc.Signature, loc2.Signature);
        }
		[Test] public void ConditionalSpaceYes ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("A", "x {1}");
			loc.Add("B", "y");
			Assert.AreEqual("x y", loc.Resolve("A'B"));
		}
		[Test] public void AlwaysExpandCascaded ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Add'Story", "Add {Story}");
			loc.Add("Story", "Backlog Item");
			Assert.AreEqual("Add Backlog Item", loc.Resolve("Add'Story"));
		}
		[Test] public void AlwaysExpand ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Add'Story", "Add {Story}");
			Assert.AreEqual("Add Story", loc.Resolve("Add'Story"));
		}
		[Test] public void AlwaysExpandSubstitution ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Add", "Add {1}");
			loc.Add("Story", "Backlog Item");
			loc.Add("Backlog Item", "bogus");
			Assert.AreEqual("Add Backlog Item", loc.Resolve("Add'Story"));
		}
		[Test] public void NoInfiniteRecursion ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("bogus", "recursive {0} recursive");
			Assert.AreEqual("recursive bogus recursive", loc.Resolve("bogus"));
		}
		[Test] public void SimpleTranslate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("tag1", "This is the tag 1 string");
			Assert.AreEqual("This is the tag 1 string", loc.Resolve("tag1"));
		}
		[Test] public void PluralTemplate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			Assert.AreEqual("AssetTypes", loc.Resolve("Plural'AssetType'Story"));
		}
		[Test] public void SimpleTemplate ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("Plural", "{1}s");
			Assert.AreEqual("Storys", loc.Resolve("Plural'Story"));
		}
		[Test] public void ValueWithSpecialCharacter()
		{
			const string tag = "solution";
			const string translation = "løsningsforslag";
			var loc = new Localizer(null);
			loc.Add(tag, translation);
			Assert.AreEqual(translation, loc.Resolve(tag));
		}
		[Test] public void EmptyBraces()
		{
			Localizer loc = new Localizer(null);
			loc.Add("A", "{}");
			Assert.AreEqual("", loc.Resolve("A"));
		}
		[Test] public void BracesNest ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("match", "open {{{and}}} close");
			loc.Add("and", "xyz");
			Assert.AreEqual("open {xyz} close", loc.Resolve("match"));
		}
		[Test] public void MatchingDoubleBrace ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("match", "open {{and}} close");
			loc.Add("and", "xyz");
			Assert.AreEqual("open {and} close", loc.Resolve("match"));
		}
		[Test] public void DoubleBrace ()
		{
			Localizer loc = new Localizer(null);
			loc.Add("open", "open {{ brace");
			loc.Add("close", "close }} brace");
			Assert.AreEqual("open { brace", loc.Resolve("open"));
			Assert.AreEqual("close } brace", loc.Resolve("close"));
		}