Exemplo n.º 1
0
        public void TestTagShouldReturnValue()
        {
            var service = new StringParserService();
            var result  = service.Parse("${" + StringParserService.TestTag + "}");

            Assert.AreEqual(StringParserService.TestTagResult, result);
        }
Exemplo n.º 2
0
        public void ShouldReturnTagWhenUnknown()
        {
            var    service = new StringParserService();
            string text    = "${l:Enum_ThisIsADummyEnumThatDoesntExist_Auto}";
            var    result  = service.Parse(text);

            Assert.AreEqual(text, result);
        }
Exemplo n.º 3
0
        public void ParseWithSubstitutionsOnlyTag()
        {
            var    service       = new StringParserService();
            string content1      = "${Tag1}";
            var    substitutions = new Dictionary <string, string> {
                { "Tag1", "Replacement1" }
            };
            var result1 = service.Parse(content1, substitutions);

            Assert.AreEqual("Replacement1", result1);
        }
Exemplo n.º 4
0
        public void ParseWithSubstitutionsOtherContent()
        {
            var    service       = new StringParserService();
            string content1      = "This is ${Tag1} some text.";
            var    substitutions = new Dictionary <string, string> {
                { "Tag1", "Replacement1" }
            };
            var result1 = service.Parse(content1, substitutions);

            Assert.AreEqual("This is Replacement1 some text.", result1);
        }
Exemplo n.º 5
0
        public void ParseMultipleSubstitutionsWithMultipleTags()
        {
            var    service       = new StringParserService();
            string content1      = "${Tag1} ${Tag2} ${Tag3}";
            var    substitutions = new Dictionary <string, string>
            {
                { "Tag1", "Replacement1" },
                { "Tag2", "Replacement2" },
                { "Tag3", "Replacement3" }
            };
            var result1 = service.Parse(content1, substitutions);

            Assert.AreEqual("Replacement1 Replacement2 Replacement3", result1);
        }
Exemplo n.º 6
0
        public void ConverterShouldReturnValue()
        {
            var    service   = new StringParserService();
            string tagValue  = "Foo";
            var    converter = new MockConverter(tagValue);

            const string tagName = nameof(StringParserServiceTests);

            service.RegisterConverter(tagName, converter);
            string tag           = $"${{" + tagName + $"}}";
            string format        = $"This '{{0}}' should be replaced by '" + tagValue + "'.";
            var    stringToParse = string.Format(format, tag);
            var    result        = service.Parse(stringToParse);

            var expectedResult = string.Format(format, tagValue);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 7
0
        public void ArgsShouldBePassedToConverter()
        {
            var    service   = new StringParserService();
            string tagValue  = "Foo";
            var    converter = new MockConverter(tagValue);

            string arg = "Bah";

            const string tagName = nameof(StringParserServiceTests);

            service.RegisterConverter(tagName, converter);
            string tag           = $"${{" + tagName + $":{arg}}}";
            string format        = $"This '{{0}}' should be replaced by '" + tagValue + "'.";
            var    stringToParse = string.Format(format, tag);
            var    result        = service.Parse(stringToParse);

            var expectedResult = string.Format(format, tagValue);

            Assert.AreEqual(expectedResult, result);

            Assert.AreEqual(arg, converter.Args,
                            "Tag argument was not correctly passed to converter.");
        }