Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Unit Testing with Dependency Injection
public class AccountCreator{
// Interface'ler tanımlıyoruz. Dolayısıyla kendi sınıflarımızı rahatlıkla kullanabiliriz.
private IAccountChecker _accountChecker;
private IAccountRepository _accountRepository;
// Dependency'lerimizi constructor method vasıtasıyla enjekte ediyoruz.
public AccountCreator(IAccountChecker accountChecker, IAccountRepository accountRepository){
_accountChecker = accountChecker;
_accountRepository = new accountRepository;
public void CreateAccount(AccountInfo accountInfo){
throw new InvalidAccountInfo("New accounts cannot have account numbers");
throw new UsernameExistsException("This username is already taken. Please use a different username");
private string SanitizeUserName(string username){
var sanitizedUsername = username.Trim().ToLower().HtmlEncode();
private bool HasAccountNumber(AccountInfo accountInfo){
return accountInfo.AccountNumber != null;
private AccountDTO GetAccountDataTransferObject(AccountInfo accountInfo){
return new AccountDTO {
FirstName = accountInfo.FirstName,
LastName = accountInfo.LastName,
UserName = accountInfo.UserName,
AccountCreated = accountInfo.AccountCreated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment