Example #1
0
 private async Task CheckWebpage()
 {
     if (this.Webpage == null || this.Webpage.Id == null || this.Webpage.Id == Guid.Empty)
     {
         this.Webpage = WebpageService.GetFirst(s => s.WebsiteId == this.Website.Id && s.SubDomainId == this.SubDomain.Id && s.Url == this.Webpage.Url);
     }
 }
        public void ShouldReturnNullToEmptyString()
        {
            // act
            var(title, description, imageUrl) = WebpageService.ParseHtml(string.Empty);

            // assert
            Assert.Null(title);
            Assert.Null(description);
            Assert.Null(imageUrl);
        }
        public void ShouldParseHtmlWithTitleOnly()
        {
            // arrange
            var file = File.ReadAllText(
                Path.Combine(
                    Directory.GetCurrentDirectory(),
                    "Unit", "data", "page-with-title.html"));

            // act
            var(title, description, imageUrl) = WebpageService.ParseHtml(file);

            // assert
            Assert.Equal("Page with title", title);
            Assert.Null(description);
            Assert.Null(imageUrl);
        }
        public void ShouldParseHtmlWithAllFields()
        {
            // arrange
            var file = File.ReadAllText(
                Path.Combine(
                    Directory.GetCurrentDirectory(),
                    "Unit", "data", "complete-page.html"));

            // act
            var(title, description, imageUrl) = WebpageService.ParseHtml(file);

            // assert
            Assert.Equal(".NET | Free. Cross-platform. Open Source.", title);
            Assert.Equal(".NET is a developer platform with tools and libraries for" +
                         " building any type of app, including web, mobile, desktop, games, " +
                         "IoT, cloud, and microservices.", description);
            Assert.Equal("https://dotnet.microsoft.com/static/images/redesign/social/square.png", imageUrl);
        }
Example #5
0
        private async Task SaveWebpage()
        {
            var webpage = new Webpage();

            webpage.Url   = this.ParsedWebpage.Url.AbsolutePath.ToString();
            webpage.Title = this.ParsedWebpage.PageTitle;

            webpage.FullHtml = this.ParsedWebpage.OriginalDocument.DocumentNode.InnerHtml.ToString();
            webpage.BodyHtml = this.ParsedWebpage.InjectedDocument.DocumentNode.InnerHtml.ToString();


            webpage.LastAccessed = DateTime.Today.Date;

            webpage.WebsiteId = Website.Id;
            webpage.Website   = this.Website;

            webpage.SubDomainId = this.SubDomain.Id;
            webpage.SubDomain   = this.SubDomain;

            this.Webpage = await WebpageService.Add(webpage);
        }
 public void ShouldThrowExceptionIfArgumentIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => WebpageService.ParseHtml(null));
 }