Exemplo n.º 1
0
		public void should_use_default_smtpclient_when_client_is_null_in_constructor()
		{
			// Arrange
			EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _settingsRepository, null);

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

			// Act + Assert
			emailTemplate.Send(userModel);
		}
Exemplo n.º 3
0
		public void send_should_use_emailclient_to_send()
		{
			// Arrange
			EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _settingsRepository, _emailClientMock);
			UserViewModel userModel = new UserViewModel();
			userModel.ExistingEmail = "someone@localhost";
			userModel.NewEmail = "someone@localhost";

			// Act
			emailTemplate.Send(userModel);

			// Assert
			Assert.That(_emailClientMock.Sent, Is.True);
		}
Exemplo n.º 4
0
		public void Send_Should_Throw_EmailException_When_PlainTextView_Is_Empty()
		{
			// Arrange
			EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _settingsRepository, _emailClientMock);
			emailTemplate.PlainTextView = "";
			UserViewModel userModel = new UserViewModel();
			userModel.ExistingEmail = "someone@localhost";
			userModel.NewEmail = "someone@localhost";

			// Act + Assert
			emailTemplate.Send(userModel);
		}
Exemplo n.º 5
0
		public void replacetokens_should_get_sitesettings_from_repository()
		{
			// Issue #229
			// Arrange
			EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _settingsRepository, _emailClientMock);
			UserViewModel userModel = new UserViewModel();

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

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

			// Assert
			Assert.That(actualSettings, Is.EqualTo(expectedSettings));
		}
Exemplo n.º 6
0
		public void replacetokens_should_replace_all_tokens_from_model()
		{
			// Arrange
			EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _settingsRepository, _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";
			_settingsRepository.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()));
		}
Exemplo n.º 7
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, _settingsRepository, _emailClientMock);

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

			// Assert
			Assert.That(actualContents, Is.EqualTo(expectedContents));
		}
Exemplo 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, _settingsRepository, _emailClientMock);

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

			// Assert
			Assert.That(actualContents, Is.EqualTo(expectedContents));
		}
Exemplo 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, _settingsRepository, _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));
		}
Exemplo n.º 10
0
		public void send_should_set_two_alternative_views_with_plaintext_and_html()
		{
			// Arrange
			EmailTemplateStub emailTemplate = new EmailTemplateStub(_applicationSettings, _settingsRepository, _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);
		}