-
-
Save Lurunchik/d737270b65bfe93b0e583ff92367d486 to your computer and use it in GitHub Desktop.
Домашнее задание по тестированию.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Hometask | |
{ | |
public class UserRegistrationService | |
{ | |
public void RegisterUser(string emailAddress) | |
{ | |
if(client.CheckUserExists(emailAddress)) | |
throw new Exception(string.Format("User with e-mail '{0}' already exists", emailAddress)); | |
client.CreateUser(emailAddress); | |
var userInfo = client.GetUserInfo(emailAddress); | |
emailSendingService.SendEmail(emailBuilder.BuildAuthenticationEmailInfo(userInfo)); | |
} | |
private readonly MySqlDatabaseClient client = new MySqlDatabaseClient(); | |
private readonly EmailMessageBuilder emailBuilder = new EmailMessageBuilder(); | |
private readonly EmailSendingService emailSendingService = new EmailSendingService(); | |
} | |
internal class EmailMessageBuilder | |
{ | |
public EmailMessageInfo BuildAuthenticationEmailInfo(UserInfo userInfo) | |
{ | |
return new EmailMessageInfo | |
{ | |
EmailAddress = userInfo.Login, | |
Subject = "You have been registered on ZZZ.com", | |
Body = string.Format("Login: {0}\nPassword: {1}", userInfo.Login, userInfo.Password), | |
}; | |
} | |
} | |
internal class EmailSendingService | |
{ | |
//Этот класс посылает электронные письма | |
public void SendEmail(EmailMessageInfo emailMessageInfo) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
internal class MySqlDatabaseClient | |
{ | |
//Этот класс инкапсулирует запросы к реальной базе данных | |
public bool CheckUserExists(string login) | |
{ | |
throw new NotImplementedException(); | |
} | |
public void CreateUser(string login) | |
{ | |
throw new NotImplementedException(); | |
} | |
public UserInfo GetUserInfo(string login) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
internal class UserInfo | |
{ | |
public string Login { get; set; } | |
public string Password { get; set; } | |
} | |
internal class EmailMessageInfo | |
{ | |
public string EmailAddress { get; set; } | |
public string Subject { get; set; } | |
public string Body { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment