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 == null || existingRecords.Count < 10)
if(existingRecords != null && existingRecords.Count != 0 )
recordsToAdd = 10 - existingRecords.Count;
for(int i=0; i<recordsToAdd; i++)
CreateChildRecord(entityId);
private void CreateChildRecord(int entityId)
db[entityId].Add(new Child());
public List<Child> GetChildRecords(int entityId)