Esempio n. 1
0
        public void TestTimingSM()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            var sb = new StringManipulator();

            for (int x = 0; x < 1000; x++)
            {
                sb.Append("Hello ");
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Insert("World", 50);
            }

            for (int x = 0; x < 1000; x++)
            {
                sb.Replace("Hello ", "Hey ");
            }
            sw.Stop();

            Assert.IsFalse(true, $"{sw.ElapsedMilliseconds}");
        }
Esempio n. 2
0
        public void Test_StringManipulator_ReplaceMany()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Replace("l", "L");

            Assert.AreEqual("heLLo crueL worLd", m.ToString());
        }
Esempio n. 3
0
        public void Test_StringManipulator_ReplaceSingle()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello cruel world");
            m.Replace("cruel", "big");

            Assert.AreEqual("hello big world", m.ToString());
        }
Esempio n. 4
0
        public void Test_StringManipulator_RemoveWholeFirstSectionAndReplace()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello ");
            m.Append("world");
            m.Replace("hello ", "bonjour ");

            Assert.AreEqual("bonjour world", m.ToString());
        }
Esempio n. 5
0
        public void ShouldReplace()
        {
            string inStr     = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}";
            string expected1 = "PARM1=PARM1, PARM2=${PARM2}, PARM3=${PARM3}";
            string expected2 = "PARM1=PARM1, PARM2=PARM2, PARM3=${PARM3}";
            string expected3 = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3";

            Assert.True(StringManipulator.Replace(inStr, "PARM1", "PARM1") == expected1);
            Assert.True(StringManipulator.Replace(expected1, "PARM2", "PARM2") == expected2);
            Assert.True(StringManipulator.Replace(expected2, "PARM3", "PARM3") == expected3);
        }
Esempio n. 6
0
        public void Test_StringManipulator_RemoveWholeLastSectionAndReplace()
        {
            StringManipulator m = new StringManipulator();

            m.Append("hello ");
            m.Append("cruel ");
            m.Append("world");
            m.Replace("world", "suzy");

            Assert.AreEqual("hello cruel suzy", m.ToString());
        }
Esempio n. 7
0
        public void ShouldReplaceDictionary()
        {
            Dictionary <string, string> data = new Dictionary <string, string>()
            {
                { "PARM1", "PARM1" },
                { "PARM2", "PARM2" },
                { "PARM3", "PARM3" }
            };
            string inStr    = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}";
            string expected = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3";
            string result   = StringManipulator.Replace(inStr, data);

            Assert.True(result == expected);
        }
        private Email ParseTemplate(EmailTemplate emailTemplate, Dictionary <string, string> keyValues)
        {
            if (!keyValues.ContainsKey(ENVIRONMENT_VARIABLE))
            {
                keyValues.Add(ENVIRONMENT_VARIABLE, this.environment.IsProduction() ? string.Empty : this.environment.EnvironmentName);
            }

            Email email = new Email();

            email.From       = emailTemplate.From;
            email.Priority   = emailTemplate.Priority;
            email.Subject    = StringManipulator.Replace(emailTemplate.Subject, keyValues);
            email.Body       = StringManipulator.Replace(emailTemplate.Body, keyValues);
            email.FormatCode = emailTemplate.FormatCode;
            return(email);
        }
Esempio n. 9
0
        private Email ParseTemplate(EmailTemplate emailTemplate, Dictionary <string, string> keyValues)
        {
            if (!keyValues.ContainsKey(EmailTemplateVariable.Environment))
            {
                keyValues.Add(EmailTemplateVariable.Environment, this.environment.IsProduction() ? string.Empty : this.environment.EnvironmentName);
            }

            return(new Email()
            {
                From = emailTemplate.From,
                Priority = emailTemplate.Priority,
                Subject = StringManipulator.Replace(emailTemplate.Subject, keyValues),
                Body = StringManipulator.Replace(emailTemplate.Body, keyValues),
                FormatCode = emailTemplate.FormatCode,
            });
        }
Esempio n. 10
0
        public void ShouldNullReturnNull()
        {
            string result = StringManipulator.Replace(null, "KEY", "VALUE");

            Assert.True(result is null);
        }