//[Test] public static void MasterDetailTest() { List <object> expected = new List <object> { new KeyValuePair <Recipe, RecipeLineItem>(new Recipe { Id = 1704, Name = "Birthday cake" }, new RecipeLineItem { Index = 1, Amount = 25 }), new KeyValuePair <Recipe, RecipeLineItem>(new Recipe { Id = 1704, Name = "Birthday cake" }, new RecipeLineItem { Index = 2, Amount = 25 }), new KeyValuePair <Recipe, RecipeLineItem>(new Recipe { Id = 1704, Name = "Birthday cake" }, new RecipeLineItem { Index = 3 }), new KeyValuePair <Recipe, RecipeLineItem>(new Recipe { Id = 1804, Name = "Wedding cake" }, new RecipeLineItem { Index = 1, Amount = 25 }), new KeyValuePair <Recipe, RecipeLineItem>(new Recipe { Id = 1804, Name = "Wedding cake" }, new RecipeLineItem { Index = 2, Amount = 25 }), new KeyValuePair <Recipe, RecipeLineItem>(new Recipe { Id = 1804, Name = "Wedding cake" }, new RecipeLineItem { Index = 3, Amount = 50 }), }; List <object> actual = new List <object>(); using (var parser = new ChoManifoldReader(FileNameMasterDetailTXT) .WithCustomRecordSelector((v) => { string l = v as string; if (l.SplitNTrim(';')[0].CastTo <int>() > 1700) { return(typeof(Recipe)); } else { return(typeof(RecipeLineItem)); } }) ) { foreach (var r in parser.ToMasterDetail <Recipe, RecipeLineItem>()) { actual.Add(r); } } CollectionAssert.AreEqual(expected, actual); }
static void MasterDetailTest() { using (var parser = new ChoManifoldReader("MasterDetail.txt") .WithCustomRecordSelector((l) => { if (l.SplitNTrim(';')[0].CastTo <int>() > 1700) { return(typeof(Recipe)); } else { return(typeof(RecipeLineItem)); } }) ) { foreach (var r in parser.ToMasterDetail <Recipe, RecipeLineItem>()) { Console.WriteLine(r.ToStringEx()); } } }