public void It_should_group_the_data_row_groupings_by_the_specified_column_index()
        {
            _DataTable.Rows.Add("Value-1", "Value-2", "Value-3", "Value-4");
            _DataTable.Rows.Add("Value-5", "Value-2", "Value-7", "Value-8");
            _DataTable.Rows.Add("Value-5", "Value-3", "Value-10", "Value-11");

            var groupings = _DataTable.GroupBy("A1:A?").GroupBy(1).ToArray();

            var grouping1 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key("Value-2")
                            .Row("Value-1", "Value-2", "Value-3", "Value-4")
                            .Build();

            var grouping2 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key("Value-2")
                            .Row("Value-5", "Value-2", "Value-7", "Value-8")
                            .Build();

            var grouping3 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key("Value-3")
                            .Row("Value-5", "Value-3", "Value-10", "Value-11")
                            .Build();

            var expected = new[] { grouping1, grouping2, grouping3 };

            Assert.IsTrue(groupings.SequenceEqual(expected, new DataRowGroupingComparer()));
        }
        public void It_should_group_the_rows_according_to_the_values_in_the_specified_columns()
        {
            _DataTable.Rows.Add("Value-1", "Value-2", "Value-3", "Value-4");
            _DataTable.Rows.Add("Value-5", "Value-2", "Value-7", "Value-8");
            _DataTable.Rows.Add("Value-5", "Value-3", "Value-10", "Value-11");
            _DataTable.Rows.Add("Value-5", "Value-2", "Value-12", "Value-13");

            var groupings = _DataTable.GroupBy(new[] { 0, 1 });

            var grouping1 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key(new object[] { "Value-1", "Value-2" })
                            .Row("Value-1", "Value-2", "Value-3", "Value-4")
                            .Build();

            var grouping2 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key(new object[] { "Value-5", "Value-2" })
                            .Row("Value-5", "Value-2", "Value-7", "Value-8")
                            .Row("Value-5", "Value-2", "Value-12", "Value-13")
                            .Build();

            var grouping3 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key(new object[] { "Value-5", "Value-3" })
                            .Row("Value-5", "Value-3", "Value-10", "Value-11")
                            .Build();

            var expected = new[] { grouping1, grouping2, grouping3 };

            Assert.IsTrue(groupings.SequenceEqual(expected, new DataRowGroupingComparer()));
        }
コード例 #3
0
        public void It_should_return_false_when_the_keys_are_not_equal()
        {
            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row().Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-2").Row().Build();

            Assert.IsFalse(_Comparer.Equals(x, y));
        }
コード例 #4
0
        public void It_should_return_false_when_the_second_key_is_an_enumerable_and_the_first_is_not()
        {
            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row().Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key(new object[] { "key-1", "key-2" }).Row().Build();

            Assert.IsFalse(_Comparer.Equals(x, y));
        }
コード例 #5
0
        public void It_should_return_true_when_the_keys_are_not_string_and_equal()
        {
            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key(1).Row().Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key(1).Row().Build();

            Assert.IsTrue(_Comparer.Equals(x, y));
        }
コード例 #6
0
        public void It_should_return_a_different_hash_code_for_a_different_key()
        {
            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row().Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-2").Row().Build();

            Assert.AreNotEqual(_Comparer.GetHashCode(x), _Comparer.GetHashCode(y));
        }
コード例 #7
0
        public void It_should_return_true_when_both_keys_are_enumerable_and_the_same()
        {
            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key(new object[] { "key-1", "key-2" }).Row().Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key(new object[] { "key-1", "key-2" }).Row().Build();

            Assert.IsTrue(_Comparer.Equals(x, y));
        }
コード例 #8
0
        public void It_should_return_true_when_the_keys_and_data_rows_are_equal()
        {
            _DataTable.Columns.Add("Value");

            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row("Value-1").Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row("Value-1").Build();

            Assert.IsTrue(_Comparer.Equals(x, y));
        }
コード例 #9
0
        public void It_should_return_the_same_hash_code_for_the_same_key_and_values()
        {
            _DataTable.Columns.Add("Column");

            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row("Value-1").Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key-1").Row("Value-1").Build();

            Assert.AreEqual(_Comparer.GetHashCode(x), _Comparer.GetHashCode(y));
        }
コード例 #10
0
        public void It_should_return_a_different_hash_code_for_different_keys()
        {
            _DataTable.Columns.Add("Column");

            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key(new object[] { "key-1" }).Row("Value-1").Build();
            var y = DataRowGroupingBuilder.UseSchema(_DataTable).Key(new object[] { "key-2" }).Row("Value-1").Build();

            Assert.AreNotEqual(_Comparer.GetHashCode(x), _Comparer.GetHashCode(y));
        }
コード例 #11
0
        public void It_should_throw_an_exception_when_the_column_index_is_less_than_zero()
        {
            var grouping = DataRowGroupingBuilder.UseSchema(_DataTable)
                           .Key("key")
                           .Row("Value-1", 200M)
                           .Row("Value-2", 300M)
                           .Build();

            var exception = Assert.Throws <ArgumentOutOfRangeException>(() => new [] { grouping }.Max <int>(-1));

            Assert.AreEqual($"DataRow does not have a column at index -1. (Parameter 'columnIndex')", exception.Message);
        }
コード例 #12
0
        public void It_should_group_the_rows_by_column_for_the_specified_range_tuple()
        {
            _DataTable.Rows.Add("Value-1", "Value-2", "Value-3", "Value-4");
            _DataTable.Rows.Add("Value-5", "Value-6", "Value-7", "Value-8");
            _DataTable.Rows.Add("Value-5", "Value-9", "Value-10", "Value-11");

            var groupings = _DataTable.GroupBy(((0, 0), (0, 2))).ToArray();

            var grouping1 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key("Value-1")
                            .Row("Value-1", "Value-2", "Value-3", "Value-4")
                            .Build();

            var grouping2 = DataRowGroupingBuilder.UseSchema(_DataTable)
                            .Key("Value-5")
                            .Row("Value-5", "Value-6", "Value-7", "Value-8")
                            .Row("Value-5", "Value-9", "Value-10", "Value-11")
                            .Build();

            var expected = new[] { grouping1, grouping2 };

            Assert.IsTrue(groupings.SequenceEqual(expected, new DataRowGroupingComparer()));
        }
コード例 #13
0
        public void It_should_return_false_when_the_first_data_row_grouping_is_not_null_and_the_second_is_null()
        {
            var x = DataRowGroupingBuilder.UseSchema(_DataTable).Key("key").Row().Build();

            Assert.IsFalse(_Comparer.Equals(x, null));
        }