using System.Collections.Generic;
public static void Main()
new UnitTests().PerformUnitTest();
public void PerformUnitTest()
List<string> testZipCodes = new List<string>{"12345", "39205", "22122"};
var sut = new CustomerManager(testZipCodes);
var actual = sut.UpdateZip("12345");
var result = expected == actual ? "PASS" : "FAIL";
Console.WriteLine(result);
actual = sut.UpdateZip("9999");
result = expected == actual ? "PASS" : "FAIL";
Console.WriteLine(result);
public class CustomerManager
public Microsoft.AspNetCore.Http.HttpContext httpContext;
public List<string> allZipCodes;
public CustomerRepository repository;
public CustomerManager(Microsoft.AspNetCore.Http.HttpContext context)
allZipCodes = GetAllValidZipCodes();
repository = new CustomerRepository();
public CustomerManager(List<string> testZipCodes)
allZipCodes = testZipCodes;
repository = new TestCustomerRepository();
public bool UpdateZip(string newZipCode)
if (allZipCodes.Contains(newZipCode))
int? customerId = (int?)httpContext?.Items["CustomerId"] ?? 0;
repository.UpdateZip(customerId.Value, newZipCode);
private 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 CustomerRepository
public virtual void UpdateZip(int customerId, string newZipCode)
var db = new DbContext();
var customer = db.Customers.SingleOrDefault(i => i.ID == customerId);
customer.ZipCode = newZipCode;
public class TestCustomerRepository : CustomerRepository
public override void UpdateZip(int customerId, string newZipCode) {}
public List<Customer> Customers { get; set; }
public T Get<T>(string url)