public void PlaceholderReplacer_ReplacePlaceholders_Should_ReplaceOnePlaceholder()
        {
            const string contentWithPlaceholder         = "Some random text with {{placeholder}} in it.";
            const string expectedPlaceholderValue       = "new value";
            var          placeholderReplacer            = new PlaceholdersReplacer();
            var          contentWithReplacedPlaceholder = placeholderReplacer.ReplacePlaceholders(contentWithPlaceholder, new Dictionary <string, string> {
                { "placeholder", expectedPlaceholderValue }
            });

            Assert.IsNotNull(contentWithReplacedPlaceholder);
            Assert.IsTrue(contentWithReplacedPlaceholder.IndexOf("{{placeholder}}", StringComparison.Ordinal) == -1);
            Assert.IsTrue(contentWithReplacedPlaceholder.IndexOf(expectedPlaceholderValue, StringComparison.Ordinal) > -1);
        }
예제 #2
0
        public void MessageBodyCreator_Create_Should_CreateResetPasswordMessage()
        {
            var          config                 = new Config();
            const string templateName           = "reset-password";
            const string placeholderValue       = "https://thenewlink.com";
            var          messageTemplateReader  = new MessageTemplateReader(config.MessagesTemplatesRootDirectory);
            var          messageSignatureReader = new MessageSignatureReader(messageTemplateReader);
            var          placeholdersReplacer   = new PlaceholdersReplacer();
            var          messageBodyCreator     = new MessageBodyCreator(messageTemplateReader, messageSignatureReader, placeholdersReplacer);
            var          placeholdersWithValues = new Dictionary <string, string> {
                { "link", placeholderValue }
            };
            var messageBody = messageBodyCreator.Create(templateName, placeholdersWithValues);

            Assert.IsNotNull(messageBody);
            Assert.IsTrue(messageBody.IndexOf("reset your password", StringComparison.Ordinal) > -1);
        }
        public void PlaceholderReplacer_ReplacePlaceholders_Should_ReplaceMultiplePlaceholders()
        {
            const string contentWithPlaceholder = "Another random text with placeholders. My name is {{firstname}} {{lastname}} and I am a web developer.";
            const string expectedFirstnameValue = "Miro";
            const string expectedLastnameValue  = "Grenda";

            var placeholdersWithValues = new Dictionary <string, string>
            {
                { "firstname", expectedFirstnameValue },
                { "lastname", expectedLastnameValue }
            };

            var placeholderReplacer            = new PlaceholdersReplacer();
            var contentWithReplacedPlaceholder = placeholderReplacer.ReplacePlaceholders(contentWithPlaceholder, placeholdersWithValues);

            Assert.IsNotNull(contentWithReplacedPlaceholder);
            Assert.IsTrue(contentWithReplacedPlaceholder.IndexOf("{{firstname}}", StringComparison.Ordinal) == -1);
            Assert.IsTrue(contentWithReplacedPlaceholder.IndexOf("{{lastname}}", StringComparison.Ordinal) == -1);
            Assert.IsTrue(contentWithReplacedPlaceholder.IndexOf(expectedFirstnameValue, StringComparison.Ordinal) > -1);
            Assert.IsTrue(contentWithReplacedPlaceholder.IndexOf(expectedLastnameValue, StringComparison.Ordinal) > -1);
        }