using System.Collections.Generic;
public static void Main()
var service = new EntityService();
service.EnsureChildRecords(100);
service.EnsureChildRecords(200);
var childCount = service.GetChildRecords(100).Count;
Console.WriteLine(childCount == expected ? "PASS" : "FAIL, child count is " + childCount);
childCount = service.GetChildRecords(200).Count;
Console.WriteLine(childCount == expected ? "PASS" : "FAIL, child count is " + childCount);
public class EntityService
Dictionary<int, List<Child>> db = new Dictionary<int, List<Child>>();
db.Add(100, new List<Child>());
for (int a = 0; a < 7; a++)
db.Add(200, new List<Child>());
public void EnsureChildRecords(int entityId)
var existingRecords = GetChildRecords(entityId);
if (existingRecords.Count < 10)
Console.WriteLine("This current record has less than 10 children ");
Console.WriteLine("This current record has 10 or more children already");
private void CreateChildRecord(int entityId)
db[entityId].Add(new Child());
public List<Child> GetChildRecords(int entityId)