Last active
April 15, 2024 06:54
-
-
Save Anton92nd/9470ba3703fff29e2fd9bad6fa55e5e9 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; } | |
} | |
} |
Author
Anton92nd
commented
Apr 10, 2017
- Проведите рефакторинг следующего набора классов, используя принципы SOLID (в особенности dependecy inversion principle).
- После рефакторинга должна быть возможность протестировать все классы, содержащие какую-либо логику (а не только данные).
- Постройте диаграмму классов ДО и ПОСЛЕ рефакторинга - это результат вашей работы, исправленный код присылать не нужно.
- В диаграмму ПОСЛЕ [рефакторинга] включите mock-object-классы, которые вы бы использовали в тестах.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment