示例#1
0
        public void Load_With_Invalid_Url_Should_Throw_Argument_Exception_Test()
        {
            string url = "www.invalidUrl.com";

            HtmlDocument result = _htmlLoader.Load(url);

            result.Should().BeNull();
        }
示例#2
0
        public static void LoadHtmlFile(
            System.IO.TextReader reader,
            DomDocument document,
            string baseUrl)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            HTMLDocument htmlDoc = new HTMLDocument();
            string       html    = reader.ReadToEnd();

            htmlDoc.LoadHTML(html);
            if (string.IsNullOrEmpty(baseUrl) == false)
            {
                htmlDoc.BaseURL = baseUrl;
            }
            HtmlLoader loader = new HtmlLoader();

            loader.Load(htmlDoc, document);
            document.AfterLoad(FileFormat.Html);
        }
示例#3
0
        public void Should_ParseCatalogContent()
        {
            // Arrange
            const string host = "http://www.pluralsight.com/";

            var nodeSelector = new PluralsightNodeSelector();
            var nodeParser   = new PluralsightNodeParser(host, nodeSelector);

            var sut = new PluralsightCatalogParser(nodeSelector, nodeParser);

            // add category reference for each course
            foreach (var expectedCategory in ExpectedCategoriesDictionary.Values)
            {
                foreach (var expectedCourse in expectedCategory.Courses)
                {
                    expectedCourse.Category = expectedCategory;
                }
            }

            const string catalogPath = "./../../TestData/PluralsighCatalogTestData.html";
            var          loader      = new HtmlLoader <HtmlAgilityPackHtmlContainer>();
            var          catalog     = loader.Load(catalogPath, LocationType.Local);


            // Act
            var result = sut.Parse(catalog);

            // Assert

            // Authors
            var resultAuthors = result.AuthorsParseResult.AuthorsExceptWhoseUrlNullContainer.Values
                                .OrderBy(x => x.UrlName);

            var expectedAuthors = ExpectedAuthorsDictionary.Values
                                  .Where(x => x.UrlName != null)
                                  .OrderBy(x => x.UrlName);

            Assert.Equal(expectedAuthors, resultAuthors, PluralsightAuthor.PropertiesComparer);

            // Courses
            var resultCourses   = result.CoursesParseResult.CourseContainer.Values;
            var expectedCourses = ExpectedCoursesDictionary.Values;

            CheckCoursesEquality(expectedCourses, resultCourses);

            // Categories
            var resultCategories   = result.CategoriesParseResult.CategoryContainer.Values;
            var expectedCategories = ExpectedCategoriesDictionary.Values;

            Assert.Equal(expectedCategories.Count, resultCategories.Count);
            foreach (var resultCategory in resultCategories)
            {
                var expectedCategory = expectedCategories
                                       .Single(x => x.UrlName == resultCategory.UrlName);

                Assert.Equal(expectedCategory, resultCategory, PluralsightCategory.PropertiesComparer);

                CheckCoursesEquality(expectedCategory.Courses, resultCategory.Courses, resultCategory);
            }
        }
示例#4
0
        public static void LoadHtmlFile(
            string url,
            DomDocument document)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            HTMLDocument htmlDoc = new HTMLDocument();

            htmlDoc.LoadUrl(url);
            document.BaseUrl = htmlDoc.BaseURL;
            HtmlLoader loader = new HtmlLoader();

            loader.Load(htmlDoc, document);
            document.AfterLoad(FileFormat.Html);
        }
示例#5
0
        public static void LoadHtmlFile(
            System.IO.Stream stream,
            DomDocument document,
            string baseUrl)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            HTMLDocument htmlDoc = new HTMLDocument();

            htmlDoc.Load(stream);
            htmlDoc.BaseURL = baseUrl;
            HtmlLoader loader = new HtmlLoader();

            loader.Load(htmlDoc, document);
            document.AfterLoad(FileFormat.Html);
        }
示例#6
0
        public MainWindow()
        {
            InitializeComponent();

            Dispatcher.UnhandledException += OnDispatcherUnhandledException;
            HospitalLogger.AddLoggingTarget(new FileLoggingTarget());

            try
            {
                HtmlLoader templateLoader = Factory.BuildHtmlLoader();
                templateLoader.Load();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                HospitalLogger.LogError("Unexpected errror occurred: \"{0}\" in {1}", ex.Message,
                                        ex.TargetSite);
                Environment.Exit(-1);
            }

            Switcher.PageSwitcher = this;
            Switcher.Switch(new StartPage());
        }