Пример #1
0
        public void Ctor_ConfiguredDescriptor_DescriptorPropertiesDoNotGetOverwritten()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure        = "Dividend";
            descriptor.Path          = @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]/TBODY[0]";
            descriptor.Orientation   = SeriesOrientation.Row;
            descriptor.ValuesLocator = new StringContainsLocator {
                HeaderSeriesPosition = 7, Pattern = "Dividend in Mio"
            };
            descriptor.ValueFormat  = new FormatColumn("values", typeof(double), "00.00");
            descriptor.TimesLocator = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 0
            };
            descriptor.TimeFormat = new FormatColumn("times", typeof(int), "000");
            descriptor.Excludes.Add(1);

            var viewModel = CreateViewModel(descriptor);

            Assert.That(descriptor.Figure, Is.EqualTo("Dividend"));
            Assert.That(descriptor.Path, Is.EqualTo(@"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]"));
            Assert.That(descriptor.Orientation, Is.EqualTo(SeriesOrientation.Row));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).HeaderSeriesPosition, Is.EqualTo(7));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).Pattern, Is.EqualTo("Dividend in Mio"));
            Assert.That(descriptor.ValueFormat.Type, Is.EqualTo(typeof(double)));
            Assert.That(descriptor.ValueFormat.Format, Is.EqualTo("00.00"));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).HeaderSeriesPosition, Is.EqualTo(0));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).SeriesPosition, Is.EqualTo(0));
            Assert.That(descriptor.TimeFormat.Type, Is.EqualTo(typeof(int)));
            Assert.That(descriptor.TimeFormat.Format, Is.EqualTo("000"));
            Assert.That(descriptor.Excludes, Is.EquivalentTo(new[] { 1 }));
        }
Пример #2
0
        public void Ctor_ConfiguredDescriptor_ViewModelTakesOverValues()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure        = "Dividend";
            descriptor.Path          = @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]/TBODY[0]";
            descriptor.Orientation   = SeriesOrientation.Row;
            descriptor.ValuesLocator = new StringContainsLocator {
                HeaderSeriesPosition = 7, Pattern = "Dividend in Mio"
            };
            descriptor.ValueFormat  = new FormatColumn("values", typeof(double), "00.00");
            descriptor.TimesLocator = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 3
            };
            descriptor.TimeFormat = new FormatColumn("times", typeof(int), "000");
            descriptor.Excludes.Add(1);

            var viewModel = CreateViewModel(descriptor);

            Assert.That(viewModel.SelectedFigure, Is.EqualTo(typeof(Dividend)));
            Assert.That(viewModel.Path, Is.EqualTo(@"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]"));
            Assert.That(viewModel.SelectedOrientation, Is.EqualTo(descriptor.Orientation));
            Assert.That(viewModel.ValuesPattern, Is.EqualTo("Dividend in Mio"));
            Assert.That(viewModel.ValuesPosition, Is.EqualTo(7));
            Assert.That(viewModel.IsValid, Is.False);
            Assert.That(viewModel.ValueFormat, Is.EqualTo(descriptor.ValueFormat));
            Assert.That(viewModel.TimesPosition, Is.EqualTo(3));
            Assert.That(viewModel.TimeFormat, Is.EqualTo(descriptor.TimeFormat));
            Assert.That(viewModel.Value, Is.Null.Or.Empty);
        }
Пример #3
0
        public void DefineSeriesInHtmlTable()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure      = "Dividend";
            descriptor.Orientation = SeriesOrientation.Row;

            var doc = (HtmlDocumentAdapter)LoadDocument <IHtmlDocument>("Html", "ariva.fundamentals.DE0005190003.html");

            var viewModel = new PathSeriesDescriptorViewModel(descriptor);

            viewModel.Document = doc;

            HtmlMarkupAutomationProvider.SimulateClickOn(doc.Document, "rym_Dividend");

            Assert.That(descriptor.Path, Is.EqualTo(@"/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]"));
            // we cannot calculate the exact clicked position form descriptor (anyway does not matter for series).
            // -> we just select the first value which is not header
            Assert.That(viewModel.Value, Is.EqualTo("350,0"));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).HeaderSeriesPosition, Is.EqualTo(0));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).Pattern, Is.EqualTo("Dividendenausschüttung in Mio."));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).HeaderSeriesPosition, Is.EqualTo(0));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).SeriesPosition, Is.EqualTo(0));

            viewModel.ValueFormat.Type       = typeof(double);
            viewModel.ValueFormat.Format     = "00,0";
            viewModel.ValueFormat.InMillions = true;

            viewModel.TimesPosition = 1;

            Assert.That(viewModel.Value, Is.EqualTo((350000000d).ToString()));

            var selectedCell = doc.GetElementById("rym_Dividend");

            Assert.That(HtmlMarkupAutomationProvider.IsMarked(selectedCell), Is.True);

            // now that we have defined a FigureDescriptor lets toggle the document and check
            // that descriptor remains untouched and Html table cell gets correctly reselected

            viewModel.Document = null;

            Assert.That(HtmlMarkupAutomationProvider.IsMarked(selectedCell), Is.False);

            viewModel.Document = doc;

            //doc.Document.Title = TestContext.CurrentContext.Test.Name;
            //doc.Document.OpenDocumentInExternalBrowser();

            Assert.That(descriptor.Path, Is.EqualTo(@"/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]"));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).HeaderSeriesPosition, Is.EqualTo(0));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).Pattern, Is.EqualTo("Dividendenausschüttung in Mio."));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).HeaderSeriesPosition, Is.EqualTo(0));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).SeriesPosition, Is.EqualTo(1));

            Assert.That(descriptor.ValueFormat.InMillions, Is.True);

            Assert.That(viewModel.Value, Is.EqualTo((350000000d).ToString()));

            Assert.That(HtmlMarkupAutomationProvider.IsMarked(selectedCell), Is.True);
        }
Пример #4
0
        private static IHtmlMarker TryCreateMarker(PathSeriesDescriptor descriptor)
        {
            if (descriptor == null)
            {
                return(null);
            }

            var marker = new HtmlTableMarker();

            if (descriptor.Orientation == SeriesOrientation.Row)
            {
                marker.ExpandRow = true;

                marker.ColumnHeaderRow = descriptor.TimesLocator.HeaderSeriesPosition;
                marker.RowHeaderColumn = descriptor.ValuesLocator.HeaderSeriesPosition;

                marker.SkipColumns = descriptor.Excludes.ToArray();
                marker.SkipRows    = null;
            }
            else if (descriptor.Orientation == SeriesOrientation.Column)
            {
                marker.ExpandColumn = true;

                marker.RowHeaderColumn = descriptor.TimesLocator.HeaderSeriesPosition;
                marker.ColumnHeaderRow = descriptor.ValuesLocator.HeaderSeriesPosition;

                marker.SkipColumns = null;
                marker.SkipRows    = descriptor.Excludes.ToArray();
            }

            return(marker);
        }
Пример #5
0
        public void Path_Set_ValueIsSet()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Path = "123";

            Assert.That(descriptor.Path, Is.EqualTo("123"));
        }
Пример #6
0
        public void Ctor_WhenCalled_FiguresFetchedFromDynamics()
        {
            var descriptor = new PathSeriesDescriptor();

            var viewModel = CreateViewModel(descriptor);

            Assert.That(viewModel.Figures, Is.EquivalentTo(Dynamics.AllFigures));
        }
Пример #7
0
        public void Path_Set_ChangeIsNotified()
        {
            var descriptor = new PathSeriesDescriptor();
            var counter    = new PropertyChangedCounter(descriptor);

            descriptor.Path = "123";

            Assert.That(counter.GetCount(nameof(descriptor.Path)), Is.EqualTo(1));
        }
Пример #8
0
        public void Path_PathToSelectedElementNull_SetPathToSelectedElement()
        {
            var descriptor = new PathSeriesDescriptor();
            var viewModel  = CreateViewModel(descriptor);

            viewModel.Path = @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]/TBODY[0]/TR[1]/TD[1]";

            myMarkupBehavior.VerifySet(x => x.PathToSelectedElement = @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]");
        }
Пример #9
0
        private static IFigureDescriptor CreatePathSeriesDescriptor()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.ValueFormat = new FormatColumn("value", typeof(double), "000,000.0000");
            descriptor.TimeFormat  = new FormatColumn("time", typeof(int), "0000");

            return(descriptor);
        }
Пример #10
0
        public void Path_SetToTableCell_PathReducedToTable()
        {
            var descriptor = new PathSeriesDescriptor();
            var viewModel  = CreateViewModel(descriptor);

            viewModel.Path = @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]/TBODY[0]/TR[1]/TD[1]";

            Assert.That(viewModel.Path, Is.EqualTo(@"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]"));
            Assert.That(descriptor.Path, Is.EqualTo(@"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]"));
        }
Пример #11
0
        public void Clone_WhenCalled_AllMembersAreCloned()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Path = "123";

            var clone = FigureDescriptorFactory.Clone(descriptor);

            Assert.That(clone.Path, Is.EqualTo("123"));
        }
Пример #12
0
        public void OnDocumentChanged_WhenCalled_PathSetToMarkupBehavior()
        {
            var descriptor = new PathSeriesDescriptor();
            var viewModel  = CreateViewModel(descriptor);

            viewModel.Path = "/BODY[0]";

            viewModel.Document = HtmlDocumentExtensions.LoadHtml("<html><body/></html>");

            myMarkupBehavior.VerifySet(x => x.PathToSelectedElement = viewModel.Path);
        }
Пример #13
0
        public void Path_PathToSelectedElementNotNull_PathToSelectedElementNotChanged()
        {
            var descriptor = new PathSeriesDescriptor();
            var viewModel  = CreateViewModel(descriptor);

            myMarkupBehavior.SetupGet(x => x.PathToSelectedElement).Returns(@"/TABLE[0]/TBODY[0]/TR[1]/TD[1]");

            viewModel.Path = @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]/TBODY[0]/TR[1]/TD[1]";

            myMarkupBehavior.VerifySet(x => x.PathToSelectedElement = It.IsAny <string>(), Times.Never);
        }
Пример #14
0
        public void Path_WhenCalled_PassedToDescriptor([Values(null, @"/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]")] string path)
        {
            var descriptor = new PathSeriesDescriptor();
            var viewModel  = CreateViewModel(descriptor);

            // first set to s.th. different to ensure that really the body of the setter gets executed
            viewModel.Path = "/BODY[0]";

            viewModel.Path = path;

            Assert.That(descriptor.Path, Is.EqualTo(path));
        }
Пример #15
0
        public void Validate_IsValid_DoesNotThrows()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure        = "Equity";
            descriptor.Path          = "123";
            descriptor.ValuesLocator = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 4
            };
            descriptor.ValueFormat = new FormatColumn("values", typeof(double), "0.00");

            RecursiveValidator.Validate(descriptor);
        }
Пример #16
0
        public void OnSelectionChanged_WhenCalled_PathSet()
        {
            var descriptor = new PathSeriesDescriptor();

            var viewModel = CreateViewModel(descriptor);

            viewModel.Document = new Mock <IHtmlDocument>().Object;

            myMarkupBehavior.SetupGet(x => x.SelectedElement).Returns(new Mock <IHtmlElement>().Object);
            myMarkupBehavior.SetupGet(x => x.PathToSelectedElement).Returns("/BODY[0]/DIV[7]");

            myMarkupBehavior.Raise(x => x.SelectionChanged += null, this, EventArgs.Empty);

            Assert.That(viewModel.Path, Is.EqualTo("/BODY[0]/DIV[7]"));
        }
Пример #17
0
        public void Ctor_DescriptorsValuesPositionIsNull_MarkerGotUpdated()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure        = "Dividend";
            descriptor.Orientation   = SeriesOrientation.Row;
            descriptor.ValuesLocator = new StringContainsLocator {
                HeaderSeriesPosition = 0, Pattern = "column"
            };

            var viewModel = CreateViewModel(descriptor);

            Assert.That(viewModel.ValuesPosition, Is.EqualTo(0));
            Assert.That(myMarkupBehavior.Object.Marker.RowHeaderColumn, Is.EqualTo(0));
        }
Пример #18
0
        public void Ctor_DescriptorsRowPositionIsNull_MarkerGotUpdated()
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure       = "Dividend";
            descriptor.Orientation  = SeriesOrientation.Row;
            descriptor.TimesLocator = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 0
            };

            var viewModel = CreateViewModel(descriptor);

            Assert.That(viewModel.TimesPosition, Is.EqualTo(0));
            Assert.That(myMarkupBehavior.Object.Marker.ColumnHeaderRow, Is.EqualTo(0));
        }
Пример #19
0
        public void Validate_InvalidPath_Throws([Values(null, "")] string path)
        {
            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure        = "Equity";
            descriptor.Path          = path;
            descriptor.ValuesLocator = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 4
            };
            descriptor.ValueFormat = new FormatColumn("values", typeof(double), "0.00");

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

            Assert.That(ex.Message, Does.Contain("The Path field is required"));
        }
Пример #20
0
        public void Ctor_EmptyDescriptor_DescriptorGetsPartiallyInitialized()
        {
            var descriptor = new PathSeriesDescriptor();

            var viewModel = CreateViewModel(descriptor);

            Assert.That(descriptor.ValuesLocator, Is.InstanceOf <StringContainsLocator>());
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).HeaderSeriesPosition, Is.EqualTo(-1));
            Assert.That(((StringContainsLocator)descriptor.ValuesLocator).Pattern, Is.Null);
            Assert.That(descriptor.Orientation, Is.EqualTo(SeriesOrientation.Row));
            Assert.That(descriptor.Figure, Is.Null);
            Assert.That(descriptor.Path, Is.Null);
            Assert.That(descriptor.TimesLocator, Is.InstanceOf <AbsolutePositionLocator>());
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).HeaderSeriesPosition, Is.EqualTo(0));
            Assert.That(((AbsolutePositionLocator)descriptor.TimesLocator).SeriesPosition, Is.EqualTo(-1));
            Assert.That(descriptor.ValueFormat.Type, Is.EqualTo(typeof(double)));
            Assert.That(descriptor.TimeFormat.Type, Is.EqualTo(typeof(int)));
        }
        public void GetSeriesAndConvertToEntities()
        {
            var doc = LoadDocument <IHtmlDocument>("Html", "ariva.fundamentals.DE0005190003.html");

            var dataSource = new DataSource();

            dataSource.Vendor  = "Ariva";
            dataSource.Name    = "Fundamentals";
            dataSource.Quality = 1;

            var descriptor = new PathSeriesDescriptor();

            descriptor.Figure        = "Dividend";
            descriptor.Path          = @"/BODY[0]/DIV[5]/DIV[0]/DIV[1]/TABLE[7]/TBODY[0]";
            descriptor.Orientation   = SeriesOrientation.Row;
            descriptor.ValuesLocator = new StringContainsLocator {
                HeaderSeriesPosition = 0, Pattern = "Dividendenausschüttung"
            };
            descriptor.ValueFormat = new FormatColumn("value", typeof(double), "00,00")
            {
                InMillions = true
            };
            descriptor.TimesLocator = new AbsolutePositionLocator {
                HeaderSeriesPosition = 0, SeriesPosition = 1
            };
            descriptor.TimeFormat = new FormatColumn("year", typeof(int), "00000000");
            descriptor.Excludes.Add(0);

            var parser = DocumentProcessingFactory.CreateParser(doc, descriptor);
            var table  = parser.ExtractTable();

            Assert.AreEqual(6, table.Rows.Count);

            Assert.AreEqual(350000000d, table.Rows[0][0]);
            Assert.AreEqual(351000000d, table.Rows[1][0]);
            Assert.AreEqual(392000000d, table.Rows[2][0]);
            Assert.AreEqual(419000000d, table.Rows[3][0]);
            Assert.AreEqual(424000000d, table.Rows[4][0]);
            Assert.AreEqual(458000000d, table.Rows[5][0]);

            Assert.AreEqual(2001, table.Rows[0][1]);
            Assert.AreEqual(2002, table.Rows[1][1]);
            Assert.AreEqual(2003, table.Rows[2][1]);
            Assert.AreEqual(2004, table.Rows[3][1]);
            Assert.AreEqual(2005, table.Rows[4][1]);
            Assert.AreEqual(2006, table.Rows[5][1]);

            var stock = new Stock {
                Isin = "DE0007664039"
            };

            stock.Company = new Company {
                Name = "Volkswagen"
            };
            stock.Company.Stocks.Add(stock);

            var converter = DocumentProcessingFactory.CreateConverter(descriptor, dataSource, Enumerable.Empty <Currency>());
            var series    = converter.Convert(table, stock).Cast <Dividend>().ToList();

            foreach (var dividend in series)
            {
                Assert.That(dividend.Company.Stocks.First().Isin, Is.EqualTo("DE0007664039"));
                Assert.That(dividend.Period, Is.InstanceOf <YearPeriod>());
                Assert.That(dividend.Source, Does.Contain("ariva").IgnoreCase.And.Contains("fundamentals").IgnoreCase);
                Assert.That(dividend.Timestamp.Date, Is.EqualTo(DateTime.Today));

                // Descriptor does not provide static currency
                Assert.That(dividend.Currency, Is.Null);
            }

            Assert.That(series[0].Period, Is.EqualTo(new YearPeriod(2001)));
            Assert.That(series[0].Value, Is.EqualTo(350000000d));
            Assert.That(series[1].Period, Is.EqualTo(new YearPeriod(2002)));
            Assert.That(series[1].Value, Is.EqualTo(351000000d));
            Assert.That(series[2].Period, Is.EqualTo(new YearPeriod(2003)));
            Assert.That(series[2].Value, Is.EqualTo(392000000d));
            Assert.That(series[3].Period, Is.EqualTo(new YearPeriod(2004)));
            Assert.That(series[3].Value, Is.EqualTo(419000000d));
            Assert.That(series[4].Period, Is.EqualTo(new YearPeriod(2005)));
            Assert.That(series[4].Value, Is.EqualTo(424000000d));
            Assert.That(series[5].Period, Is.EqualTo(new YearPeriod(2006)));
            Assert.That(series[5].Value, Is.EqualTo(458000000d));
        }
Пример #22
0
        private static IHtmlElement TryFindElementByDescriptor(IHtmlDocument document, PathSeriesDescriptor descriptor)
        {
            if (string.IsNullOrEmpty(descriptor.Path))
            {
                return(null);
            }

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

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

            if (descriptor.Orientation == SeriesOrientation.Column)
            {
                int rowToScan = descriptor.ValuesLocator.HeaderSeriesPosition;
                if (0 > rowToScan || rowToScan >= table.Rows.Count)
                {
                    return(null);
                }

                var colIdx = descriptor.ValuesLocator.FindIndex(table.GetRow(rowToScan).Select(item => item.InnerText));
                if (colIdx == -1)
                {
                    return(null);
                }

                int rowIdx = 0;
                if (rowIdx == descriptor.ValuesLocator.HeaderSeriesPosition && rowIdx < table.Rows.Count)
                {
                    rowIdx++;
                }

                return(table.GetCell(rowIdx, colIdx));
            }
            else if (descriptor.Orientation == SeriesOrientation.Row)
            {
                var colToScan = descriptor.ValuesLocator.HeaderSeriesPosition;
                if (0 > colToScan || colToScan >= table.GetRow(0).Count())
                {
                    return(null);
                }

                var rowIdx = descriptor.ValuesLocator.FindIndex(table.GetColumn(colToScan).Select(item => item.InnerText));
                if (rowIdx == -1)
                {
                    return(null);
                }

                int colIdx = 0;
                if (colIdx == descriptor.ValuesLocator.HeaderSeriesPosition && colIdx < table.GetRow(rowIdx).Count)
                {
                    colIdx++;
                }

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

            throw new NotSupportedException("Unknown orientation: " + descriptor.Orientation);
        }
Пример #23
0
 private PathSeriesDescriptorViewModel CreateViewModel(PathSeriesDescriptor descriptor)
 {
     return(new PathSeriesDescriptorViewModel(descriptor, myMarkupBehavior.Object));
 }