Beispiel #1
0
        /// <summary>
        /// Returns <see cref="InputTable{TRow}"/> with inferred columns and rows specified by <paramref name="items"/> collection.
        /// </summary>
        /// <param name="items">Table rows.</param>
        /// <returns>Table</returns>
        public static InputTable <TRow> For <TRow>(params TRow[] items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }
            var columns = TableColumnProvider.InferColumns(items).Select(InputTableColumn.FromColumnInfo);

            return(new InputTable <TRow>(columns, items));
        }
Beispiel #2
0
        /// <summary>
        /// Returns <see cref="InputTable{TRow}"/> with inferred columns and rows specified by <paramref name="items"/> collection.
        /// </summary>
        /// <param name="items">Table rows.</param>
        /// <returns>Table</returns>
        public static InputTable <KeyValuePair <TKey, TValue> > ToTable <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> items)
        {
            var rows         = items.OrderBy(x => x.Key).ToArray();
            var values       = rows.Select(x => x.Value).ToArray();
            var valueColumns = TableColumnProvider.InferColumns(values).Select(i => new InputTableColumn(i.Name,
                                                                                                         pair => i.GetValue(((KeyValuePair <TKey, TValue>)pair).Value)));
            var columns = new[] { new InputTableColumn("Key", x => ColumnValue.From(((KeyValuePair <TKey, TValue>)x).Key)) }
            .Concat(valueColumns);

            return(new InputTable <KeyValuePair <TKey, TValue> >(columns, rows));
        }
Beispiel #3
0
        /// <summary>
        /// Returns <see cref="VerifiableDataTableBuilder{TRow}"/> with inferred columns and rows specified by <paramref name="items"/> collection.<br/>
        ///
        /// The created table will use Key column to compare rows.<br/>
        /// All columns will use equality expression for verifying values.
        /// </summary>
        /// <param name="items">Table rows.</param>
        /// <returns>Verifiable table</returns>
        public static VerifiableDataTable <KeyValuePair <TKey, TValue> > ToVerifiableDataTable <TKey, TValue>(this IReadOnlyDictionary <TKey, TValue> items)
        {
            var rows         = items.OrderBy(x => x.Key).ToArray();
            var values       = rows.Select(x => x.Value).ToArray();
            var valueColumns = TableColumnProvider.InferColumns(values).Select(i => new VerifiableTableColumn(i.Name,
                                                                                                              false,
                                                                                                              pair => i.GetValue(((KeyValuePair <TKey, TValue>)pair).Value), Expect.To.Equal));
            var columns = new[]
            {
                new VerifiableTableColumn("Key", true, x => ColumnValue.From(((KeyValuePair <TKey, TValue>)x).Key),
                                          Expect.To.Equal)
            }
            .Concat(valueColumns);

            return(new VerifiableDataTable <KeyValuePair <TKey, TValue> >(columns, rows));
        }
Beispiel #4
0
        /// <summary>
        /// Returns <see cref="VerifiableDataTable{TRow}"/> with inferred columns and rows specified by <paramref name="items"/> collection.<br/>
        ///
        /// The created table will have no key columns (the row verification will be index based).<br/>
        /// All columns will use equality expression for verifying values.
        /// </summary>
        /// <param name="items">Table rows.</param>
        /// <returns>Verifiable table</returns>
        public static VerifiableDataTable <TRow> ExpectData <TRow>(params TRow[] items)
        {
            var columns = TableColumnProvider.InferColumns(items, true).Select(VerifiableTableColumn.FromColumnInfo);

            return(new VerifiableDataTable <TRow>(columns, items));
        }