private void CheckFactory(IEnumerable source, FactoryKind factoryKind, int columnCount, bool hasMetadata) { FactoryDataSet dataSet = new FactoryDataSet(delegate { return(source); }, factoryKind, columnCount); DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null), new DataBinding(1, null) }; List <IDataItem> items = new List <IDataItem>(dataSet.GetItems(bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.AreEqual(3, items[2].GetValue(bindings[0])); if (columnCount >= 2) { Assert.AreEqual("a", items[0].GetValue(bindings[1])); Assert.AreEqual("b", items[1].GetValue(bindings[1])); Assert.AreEqual("c", items[2].GetValue(bindings[1])); } if (hasMetadata) { Assert.AreEqual("1a", DataItemUtils.GetMetadata(items[0]).GetValue("Id")); Assert.AreEqual("2b", DataItemUtils.GetMetadata(items[1]).GetValue("Id")); Assert.AreEqual("3c", DataItemUtils.GetMetadata(items[2]).GetValue("Id")); } }
public void WithObject(FactoryKind factoryKind) { CheckFactory(new object[] { 1, 2, 3 }, factoryKind, 1, false); }
public void WithObjectArray(FactoryKind factoryKind) { CheckFactory(new object[][] { new object[] { 1, "a" }, new object[] { 2, "b" }, new object[] { 3, "c" } }, factoryKind, 2, false); }
public void WithDataItem(FactoryKind factoryKind) { CheckFactory(new IDataItem[] { new DataRow(1, "a").WithMetadata("Id", "1a"), new DataRow(2, "b").WithMetadata("Id", "2b"), new DataRow(3, "c").WithMetadata("Id", "3c") }, factoryKind, 2, true); }
/// <summary> /// Creates a factory data set. /// </summary> /// <param name="factory">The factory delegate.</param> /// <param name="factoryKind">The kind of factory.</param> /// <param name="columnCount">The number of columns in the data items produced /// by the factory or 0 if unknown.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="factory"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="factoryKind"/> /// is invalid or if <paramref name="columnCount"/> is less than 0.</exception> public FactoryDataSet(Func<IEnumerable> factory, FactoryKind factoryKind, int columnCount) { if (factory == null) throw new ArgumentNullException("factory"); if (! Enum.IsDefined(typeof(FactoryKind), factoryKind)) throw new ArgumentOutOfRangeException("factoryKind", factoryKind, "Invalid factory kind."); if (columnCount < 0) throw new ArgumentOutOfRangeException("columnCount", columnCount, "Column count must be non-negative."); this.factory = factory; this.factoryKind = factoryKind; this.columnCount = columnCount; }
/// <summary> /// Creates a factory data set. /// </summary> /// <param name="factory">The factory delegate.</param> /// <param name="factoryKind">The kind of factory.</param> /// <param name="columnCount">The number of columns in the data items produced /// by the factory or 0 if unknown.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="factory"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="factoryKind"/> /// is invalid or if <paramref name="columnCount"/> is less than 0.</exception> public FactoryDataSet(Func <IEnumerable> factory, FactoryKind factoryKind, int columnCount) { if (factory == null) { throw new ArgumentNullException("factory"); } if (!Enum.IsDefined(typeof(FactoryKind), factoryKind)) { throw new ArgumentOutOfRangeException("factoryKind", factoryKind, "Invalid factory kind."); } if (columnCount < 0) { throw new ArgumentOutOfRangeException("columnCount", columnCount, "Column count must be non-negative."); } this.factory = factory; this.factoryKind = factoryKind; this.columnCount = columnCount; }
private void CheckFactory(IEnumerable source, FactoryKind factoryKind, int columnCount, bool hasMetadata) { FactoryDataSet dataSet = new FactoryDataSet(delegate { return source; }, factoryKind, columnCount); DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null), new DataBinding(1, null) }; List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.AreEqual(3, items[2].GetValue(bindings[0])); if (columnCount >= 2) { Assert.AreEqual("a", items[0].GetValue(bindings[1])); Assert.AreEqual("b", items[1].GetValue(bindings[1])); Assert.AreEqual("c", items[2].GetValue(bindings[1])); } if (hasMetadata) { Assert.AreEqual("1a", DataItemUtils.GetMetadata(items[0]).GetValue("Id")); Assert.AreEqual("2b", DataItemUtils.GetMetadata(items[1]).GetValue("Id")); Assert.AreEqual("3c", DataItemUtils.GetMetadata(items[2]).GetValue("Id")); } }
private static IEnumerable <IDataItem> ProcessElement(object element, ICollection <DataBinding> bindings, FactoryKind factoryKind) { switch (factoryKind) { case FactoryKind.DataItem: return(ProcessDataItem(element)); case FactoryKind.DataSet: return(ProcessDataSet(element, bindings)); case FactoryKind.ObjectArray: return(ProcessObjectArray(element)); case FactoryKind.Object: return(ProcessObject(element)); case FactoryKind.Auto: return(ProcessAuto(element, bindings)); default: throw new NotSupportedException("Unreachable code."); } }
private static IEnumerable<IDataItem> ProcessElement(object element, ICollection<DataBinding> bindings, FactoryKind factoryKind) { switch (factoryKind) { case FactoryKind.DataItem: return ProcessDataItem(element); case FactoryKind.DataSet: return ProcessDataSet(element, bindings); case FactoryKind.ObjectArray: return ProcessObjectArray(element); case FactoryKind.Object: return ProcessObject(element); case FactoryKind.Auto: return ProcessAuto(element, bindings); default: throw new NotSupportedException("Unreachable code."); } }