Exemplo n.º 1
0
        public void ConstructorAllowsTemplateToBeNull()
        {
            var target = new StringReplaceTemplateProcessor <object>(
                template: null,
                placeholderProcessors: new Dictionary <string, Func <object, string> >());

            var result = target.Process(new object());

            Assert.Null(result);
        }
Exemplo n.º 2
0
        public void ReplacesPlaceholders(string template, string placeholder, string substitution, string expectedResult)
        {
            var target = new StringReplaceTemplateProcessor <object>(template, new Dictionary <string, Func <object, string> > {
                { placeholder, _ => substitution }
            });

            var result = target.Process(input: null);

            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 3
0
        public void CallsThePlaceholderProcessor(string template)
        {
            var  inputObject = new object();
            bool called      = false;

            var target = new StringReplaceTemplateProcessor <object>(
                template: template,
                placeholderProcessors: new Dictionary <string, Func <object, string> >
            {
                { "ph", data => { Assert.Same(inputObject, data); called = true; return("123"); } }
            });

            target.Process(inputObject);

            Assert.True(called);
        }
Exemplo n.º 4
0
        public void ReplacesMultiplePlaceholders(int number)
        {
            string template       = "Start";
            string expectedResult = template;
            var    processors     = new Dictionary <string, Func <object, string> >();

            for (var index = 0; index < number; ++index)
            {
                var placeholder = GeneratePlaceholder(index);
                template += placeholder;
                var value = index.ToString();
                processors.Add(placeholder, _ => value);
                expectedResult += value;
            }

            var target = new StringReplaceTemplateProcessor <object>(template, processors);
            var result = target.Process(null);

            Assert.Equal(expectedResult, result);
        }