Ejemplo n.º 1
0
        public void ReadTemplateFile_Should_Read_CultureUI_Textfile_Contents()
        {
            // Arrange
            _applicationSettings.EmailTemplateFolder = AppDomain.CurrentDomain.BaseDirectory;
            string expectedContents = DateTime.UtcNow.ToString();
            string cultureDir       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fr-FR");

            if (!Directory.Exists(cultureDir))
            {
                Directory.CreateDirectory(cultureDir);
            }

            string cultureFilePath = Path.Combine(cultureDir, "emailtemplate.txt");

            Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

            File.WriteAllText(cultureFilePath, expectedContents);
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);

            // Act
            string actualContents = emailTemplate.ReadTemplateFile("emailtemplate.txt");

            // Assert
            Assert.That(actualContents, Is.EqualTo(expectedContents));
        }
Ejemplo n.º 2
0
        public void Should_Use_Default_SmtpClient_When_Client_Is_Null_In_Constructor()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, null);

            // Act +  Assert
            Assert.That(emailTemplate.GetEmailClient(), Is.TypeOf <EmailClient>());
        }
Ejemplo n.º 3
0
        public void Send_Should_Throw_EmailException_When_Model_Is_Null()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);
            UserViewModel     userModel     = null;

            // Act + Assert
            emailTemplate.Send(userModel);
        }
Ejemplo n.º 4
0
        public void Send_Should_Throw_EmailException_When_Model_Email_And_NewEmail_Is_Empty()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _repository, _emailClientMock);
            UserViewModel     userModel     = new UserViewModel();

            userModel.ExistingEmail = null;
            userModel.NewEmail      = "";

            // Act + Assert
            emailTemplate.Send(userModel);
        }
Ejemplo n.º 5
0
        public void Send_Should_Throw_EmailException_When_PlainTextView_Is_Empty()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);

            emailTemplate.PlainTextView = "";
            UserViewModel userModel = new UserViewModel();

            userModel.ExistingEmail = "someone@localhost";
            userModel.NewEmail      = "someone@localhost";

            // Act + Assert
            emailTemplate.Send(userModel);
        }
Ejemplo n.º 6
0
        public void ReplaceTokens_Should_Replace_All_Tokens_From_Model()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _repository, _emailClientMock);
            UserViewModel     userModel     = new UserViewModel();

            userModel.ActivationKey    = "key";
            userModel.ExistingUsername = "******";
            userModel.Firstname        = "firstname";
            userModel.Id               = Guid.NewGuid();
            userModel.Lastname         = "lastname";
            userModel.NewEmail         = "NewEmail";
            userModel.PasswordResetKey = "resetkey";

            SiteSettings siteSettings = new SiteSettings();

            siteSettings.SiteName = "MySite";
            siteSettings.SiteUrl  = "http://www.roadkillwiki.iz.de.biz";
            _repository.SaveSiteSettings(siteSettings);

            StringBuilder templateBuilder = new StringBuilder();

            templateBuilder.AppendLine("{FIRSTNAME}");
            templateBuilder.AppendLine("{LASTNAME}");
            templateBuilder.AppendLine("{EMAIL}");
            templateBuilder.AppendLine("{USERNAME}");
            templateBuilder.AppendLine("{ACTIVATIONKEY}");
            templateBuilder.AppendLine("{RESETKEY}");
            templateBuilder.AppendLine("{USERID}");
            templateBuilder.AppendLine("{SITENAME}");
            templateBuilder.AppendLine("{SITEURL}");

            StringBuilder expectedContent = new StringBuilder();

            expectedContent.AppendLine(userModel.Firstname);
            expectedContent.AppendLine(userModel.Lastname);
            expectedContent.AppendLine(userModel.NewEmail);
            expectedContent.AppendLine(userModel.NewUsername);
            expectedContent.AppendLine(userModel.ActivationKey);
            expectedContent.AppendLine(userModel.PasswordResetKey);
            expectedContent.AppendLine(userModel.Id.ToString());
            expectedContent.AppendLine(siteSettings.SiteName);
            expectedContent.AppendLine(siteSettings.SiteUrl);

            // Act
            string actualTemplate = emailTemplate.ReplaceTokens(userModel, templateBuilder.ToString());

            // Assert
            Assert.That(actualTemplate, Is.EqualTo(expectedContent.ToString()));
        }
Ejemplo n.º 7
0
        public void Send_Should_Use_EmailClient_To_Send()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);
            UserViewModel     userModel     = new UserViewModel();

            userModel.ExistingEmail = "someone@localhost";
            userModel.NewEmail      = "someone@localhost";

            // Act
            emailTemplate.Send(userModel);

            // Assert
            Assert.That(_emailClientMock.Sent, Is.True);
        }
Ejemplo n.º 8
0
        public void ReadTemplateFile_Should_Read_Textfile_Contents()
        {
            // Arrange
            _applicationSettings.EmailTemplateFolder = AppDomain.CurrentDomain.BaseDirectory;
            string expectedContents = DateTime.UtcNow.ToString();
            string path             = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "emailtemplate.txt");

            File.WriteAllText(path, expectedContents);
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);

            // Act
            string actualContents = emailTemplate.ReadTemplateFile("emailtemplate.txt");

            // Assert
            Assert.That(actualContents, Is.EqualTo(expectedContents));
        }
Ejemplo n.º 9
0
        public void Send_Should_Change_PickupDirectory_To_AppDomainRoot_When_Starting_With_VirtualPath_And_DeliveryType_Is_PickupLocation()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);

            _emailClientMock.PickupDirectoryLocation = "~/App_Data/EmailDrop";
            _emailClientMock.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;

            UserViewModel userModel = new UserViewModel();

            userModel.ExistingEmail = "someone@localhost";
            userModel.NewEmail      = "someone@localhost";

            // Act
            emailTemplate.Send(userModel);

            // Assert
            Assert.That(_emailClientMock.PickupDirectoryLocation, Is.StringStarting(AppDomain.CurrentDomain.BaseDirectory));
        }
Ejemplo n.º 10
0
        public void ReplaceTokens_Should_Get_SiteSettings_From_Repository()
        {
            // Issue #229
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _repository, _emailClientMock);
            UserViewModel     userModel     = new UserViewModel();

            SiteSettings expectedSettings = new SiteSettings();

            expectedSettings.SiteName = "MySite";
            expectedSettings.SiteUrl  = "http://www.roadkillwiki.iz.de.biz";
            _repository.SaveSiteSettings(expectedSettings);

            // Act
            emailTemplate.ReplaceTokens(userModel, "not used");
            SiteSettings actualSettings = emailTemplate.GetSiteSettings();

            // Assert
            Assert.That(actualSettings, Is.EqualTo(expectedSettings));
        }
Ejemplo n.º 11
0
        public void Send_Should_Set_Two_Alternative_Views_With_PlainText_And_Html()
        {
            // Arrange
            EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _siteSettings, _emailClientMock);
            UserViewModel     userModel     = new UserViewModel();

            userModel.ExistingEmail = "someone@localhost";
            userModel.NewEmail      = "someone@localhost";

            // Act
            emailTemplate.Send(userModel);

            // Assert
            MailMessage message = _emailClientMock.Message;

            Assert.That(message.AlternateViews.Count, Is.EqualTo(2));

            AlternateView plainView = message.AlternateViews.FirstOrDefault(x => x.ContentType.MediaType == "text/plain");
            AlternateView htmlView  = message.AlternateViews.FirstOrDefault(x => x.ContentType.MediaType == "text/html");

            Assert.That(plainView, Is.Not.Null);
            Assert.That(htmlView, Is.Not.Null);
        }