using System.Collections.Generic;
public static void Main()
new UnitTests().PerformUnitTest();
public class TestCustomerRepository : ICustomerRepository
public Customer GetCustomer(int customerId)
return new Customer() {ID = 1, ZipCode = "20001" };
public class TestZipcodeService : IZipcodeService
private string testZipcode;
public TestZipcodeService(string zipcode)
public List<string> GetAllValidZipCodes()
return new List<string>() {testZipcode};
public class TestUser : IUser
public void PerformUnitTest()
var sut = new CustomerValidator(new TestCustomerRepository(), new TestZipcodeService("20001"), new TestUser());
var actual = sut.GetCustomerAndValidateZip();
var result = expected == actual ? "PASS" : "FAIL";
Console.WriteLine(result);
sut = new CustomerValidator(new TestCustomerRepository(), new TestZipcodeService("00001"), new TestUser());
actual = sut.GetCustomerAndValidateZip();
result = expected == actual ? "PASS" : "FAIL";
Console.WriteLine(result);
public interface ICustomerValidator
bool GetCustomerAndValidateZip();
public class CustomerValidator : ICustomerValidator
private ICustomerRepository repository;
private IZipcodeService zipcodeService;
private readonly IUser user;
public CustomerValidator()
repository= new CustomerRepository();
zipcodeService = new ZipcodeService();
public CustomerValidator(ICustomerRepository c, IZipcodeService z, IUser u)
public bool GetCustomerAndValidateZip()
int customerId = user.CustomerId();
var customer = repository.GetCustomer(customerId);
var allZipCodes = zipcodeService.GetAllValidZipCodes();
return allZipCodes.Contains(customer.ZipCode);
public interface IZipcodeService
List<string> GetAllValidZipCodes();
public class ZipcodeService: IZipcodeService
public List<string> GetAllValidZipCodes()
var httpClient = new HttpClient();
return httpClient.Get<List<string>>("http://somezipcodeapi.com/GetAll");
public int ID { get; set; }
public string ZipCode { get; set; }
public class User : IUser
return (int)HttpContext.Current.Profile.GetPropertyValue("CustomerId");
public interface ICustomerRepository
Customer GetCustomer(int customerId);
public class CustomerRepository : ICustomerRepository
public Customer GetCustomer(int customerId)
var db = new DbContext();
return db.Customers.SingleOrDefault(i => i.ID == customerId);
public List<Customer> Customers { get; set; }
public T Get<T>(string url)