public void GetItemsAppliesIndexAliasTranslation() { List <KeyValuePair <string, string> > metadataPairs = new List <KeyValuePair <string, string> >(); metadataPairs.Add(new KeyValuePair <string, string>("Foo", "Bar")); IDataSet dataSet = Mocks.StrictMock <IDataSet>(); using (Mocks.Record()) { SetupResult.For(dataSet.ColumnCount).Return(3); Expect.Call(dataSet.GetItems(null, true)).IgnoreArguments().Do((GetItemsDelegate) delegate(ICollection <DataBinding> bindings, bool includeDynamicItems) { Assert.IsTrue(includeDynamicItems); List <IDataItem> items = new List <IDataItem>(); items.Add(new ListDataItem <object>(new object[] { "abc", "def", "ghi" }, metadataPairs, true)); List <DataBinding> bindingList = new List <DataBinding>(bindings); Assert.AreEqual("translatedPath", bindingList[0].Path); Assert.AreEqual(2, bindingList[0].Index); Assert.AreEqual("untranslatedPath", bindingList[1].Path); Assert.AreEqual(1, bindingList[1].Index); return(items); }); } using (Mocks.Playback()) { DataSource source = new DataSource("theName"); source.AddIndexAlias("translatedPath", 2); source.AddDataSet(dataSet); DataBinding[] bindings = new DataBinding[] { new DataBinding(5, "translatedPath"), new DataBinding(1, "untranslatedPath") }; List <IDataItem> items = new List <IDataItem>(source.GetItems(bindings, true)); Assert.Count(1, items); PropertyBag map = DataItemUtils.GetMetadata(items[0]); Assert.Count(1, map); Assert.AreEqual("Bar", map.GetValue("Foo")); Assert.Throws <ArgumentNullException>(delegate { items[0].GetValue(null); }); Assert.AreEqual("ghi", items[0].GetValue(bindings[0])); Assert.AreEqual("def", items[0].GetValue(bindings[1])); // Should throw ArgumentNullException when binding list is null. Assert.Throws <ArgumentNullException>(delegate { items[0].GetValue(null); }); } }
private static IEnumerable <IDataItem> ProcessDataSet(object value, ICollection <DataBinding> bindings) { IDataSet dataSet = value as IDataSet; if (dataSet == null) { throw new DataBindingException("Expected the factory to produce a data set."); } return(dataSet.GetItems(bindings, true)); }