コード例 #1
0
        public void Validate_InvalidRow_Throws()
        {
            var descriptor = new PathCellDescriptor();

            descriptor.Figure = "Price";
            descriptor.Path   = "123";
            descriptor.Column = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 23
            };
            descriptor.Row         = new AbsolutePositionLocator();
            descriptor.ValueFormat = new ValueFormat(typeof(double), "0.00");

            var ex = Assert.Throws <ValidationException>(() => RecursiveValidator.Validate(descriptor));

            Assert.That(ex.Message, Does.Contain("HeaderSeriesPosition must be between 0 and " + int.MaxValue));
        }
コード例 #2
0
        public void Validate_InvalidValueFormat_Throws()
        {
            var descriptor = new PathCellDescriptor();

            descriptor.Figure = "Price";
            descriptor.Path   = "123";
            descriptor.Column = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 23
            };
            descriptor.Row         = new AbsolutePositionLocator();
            descriptor.ValueFormat = new ValueFormat();

            var ex = Assert.Throws <ValidationException>(() => RecursiveValidator.Validate(descriptor));

            Assert.That(ex.Message, Does.Contain("Type field is required"));
        }
コード例 #3
0
        public void Validate_IsValid_DoesNotThrows()
        {
            var descriptor = new PathCellDescriptor();

            descriptor.Figure = "Price";
            descriptor.Path   = "123";
            descriptor.Column = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 4
            };
            descriptor.Row = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 23
            };
            descriptor.ValueFormat = new ValueFormat(typeof(double), "0.00");

            RecursiveValidator.Validate(descriptor);
        }
コード例 #4
0
        public void Ctor_EmptyDescriptor_DescriptorGetsPartiallyInitialized()
        {
            var descriptor = new PathCellDescriptor();

            var viewModel = CreateViewModel(descriptor);

            Assert.That(descriptor.Column, Is.InstanceOf <StringContainsLocator>());
            Assert.That((( StringContainsLocator )descriptor.Column).HeaderSeriesPosition, Is.EqualTo(-1));
            Assert.That((( StringContainsLocator )descriptor.Column).Pattern, Is.Null);
            Assert.That(descriptor.Currency, Is.Null);
            Assert.That(descriptor.Figure, Is.Null);
            Assert.That(descriptor.Path, Is.Null);
            Assert.That(descriptor.Row, Is.InstanceOf <StringContainsLocator>());
            Assert.That((( StringContainsLocator )descriptor.Row).HeaderSeriesPosition, Is.EqualTo(-1));
            Assert.That((( StringContainsLocator )descriptor.Row).Pattern, Is.Null);
            Assert.That(descriptor.ValueFormat.Type, Is.EqualTo(typeof(double)));
        }
コード例 #5
0
        public void Validate_InvalidPath_Throws([Values(null, "")] string path)
        {
            var descriptor = new PathCellDescriptor();

            descriptor.Figure = "Price";
            descriptor.Path   = path;
            descriptor.Column = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 4
            };
            descriptor.Row = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 23
            };
            descriptor.ValueFormat = new ValueFormat(typeof(double), "0.00");

            var ex = Assert.Throws <ValidationException>(() => RecursiveValidator.Validate(descriptor));

            Assert.That(ex.Message, Does.Contain("The Path field is required"));
        }
コード例 #6
0
 private PathCellDescriptorViewModel CreateViewModel(PathCellDescriptor descriptor)
 {
     return(new PathCellDescriptorViewModel(myLutService.Object, descriptor, myMarkupBehavior.Object));
 }
コード例 #7
0
        private static IHtmlElement TryFindElementByDescriptor(IHtmlDocument document, PathCellDescriptor descriptor)
        {
            if (string.IsNullOrEmpty(descriptor.Path))
            {
                return(null);
            }

            var table = HtmlTable.GetByPath(document, HtmlPath.Parse(descriptor.Path));

            if (table == null)
            {
                return(null);
            }

            int rowToScan = descriptor.Column.HeaderSeriesPosition;

            if (0 > rowToScan || rowToScan >= table.Rows.Count)
            {
                return(null);
            }

            var colIdx = descriptor.Column.FindIndex(table.GetRow(rowToScan).Select(item => item.InnerText));

            if (colIdx == -1)
            {
                return(null);
            }

            var colToScan = descriptor.Row.HeaderSeriesPosition;

            if (0 > colToScan || colToScan >= table.GetRow(0).Count())
            {
                return(null);
            }

            var rowIdx = descriptor.Row.FindIndex(table.GetColumn(colToScan).Select(item => item.InnerText));

            if (rowIdx == -1)
            {
                return(null);
            }

            return(table.GetCell(rowIdx, colIdx));
        }