예제 #1
0
        public static string Shift(this System.Data.DataTable table, string range, string toColumn)
        {
            ArgumentGuards.GuardAgainstNullTable(table);
            ArgumentGuards.GuardAgainstNullRange(range);

            if (string.IsNullOrEmpty(toColumn))
            {
                throw new ArgumentNullException(nameof(toColumn));
            }

            var tuple = table.TranslateRange(range);

            if (!tuple.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(range), $"The data table does not contain the range {range}.");
            }

            if (!CellRange.IsSameColumn(tuple.Value))
            {
                throw new ArgumentException("A shift cannot be performed across multiple columns.", nameof(range));
            }

            return($"{toColumn}{tuple.Value.Item1.Row + 1}:{toColumn}{tuple.Value.Item2.Row + 1}");
        }
예제 #2
0
 public void It_should_return_true_when_the_range_is_for_the_same_column()
 {
     Assert.IsTrue(CellRange.IsSameColumn("A1:A20"));
 }
예제 #3
0
 public void It_should_return_false_when_the_range_is_not_for_the_same_column()
 {
     Assert.IsFalse(CellRange.IsSameColumn("A1:D1"));
 }
예제 #4
0
        public void It_should_throw_an_exception_when_the_range_parameter_is_null()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => CellRange.IsSameColumn(null));

            Assert.AreEqual($"Value cannot be null. (Parameter 'range')", exception.Message);
        }