Beispiel #1
0
        public void ShouldExtractHtmlTags()
        {
            //throw new NotImplementedException();
            // Arrange
            string testInputString = "https://gameofthrones.fandom.com/wiki/Jon_Snow";

            string[] testStartPageHost = new string[2];
            int      dotComPos         = testInputString.IndexOf(".com");

            testStartPageHost[0] = testInputString.Substring(0, dotComPos + 4); // https://gameofthrones.fandom.com
            testStartPageHost[1] = "/wiki/";                                    // /wiki/

            string testLink1 = "/wiki/Night%27s_Watch";

            ILinkTableRepository linkTableRepository = Substitute.For <ILinkTableRepository>();
            ParsingService       parsingService      = new ParsingService(linkTableRepository, this.testFileManager);

            // Act
            List <string> links = parsingService.ExtractLinksFromHtmlString(ref testStartPageHost, "testFilePath");

            // Assert
            if (links.Count != 1)
            {
                throw new ArgumentException("Expected one link in list");
            }
            if (links[0] != testLink1)
            {
                throw new ArgumentException("Wrong link string in list");
            }
        }
Beispiel #2
0
        public void ShouldThrowExceptionIfGotNegativeIterationID()
        {
            // Arrange
            string testLink        = "https://en.wikipedia.org/wiki/The_Mummy_Returns";
            int    testIterationId = -5;
            ILinkTableRepository linkTableRepository = Substitute.For <ILinkTableRepository>();
            ParsingService       parsingService      = new ParsingService(linkTableRepository, this.testFileManager);

            // Act
            parsingService.SaveValidation(testLink, testIterationId);

            // Assert
        }
Beispiel #3
0
        public void ShouldThrowExceptionIfCouldFindLinkInDB()
        {
            // Arrange
            string testLink = "https://en.wikipedia.org/wiki/The_Mummy_Returns";
            ILinkTableRepository linkTableRepository = Substitute.For <ILinkTableRepository>();

            linkTableRepository.ContainsByLink(Arg.Is(testLink)).Returns(true);
            ParsingService parsingService = new ParsingService(linkTableRepository, this.testFileManager);

            // Act
            parsingService.ContainsByLink(testLink);

            // Assert
        }
Beispiel #4
0
        public void ShouldSaveTagsIntoDatabase()
        {
            // Arrange
            string testLink        = "https://en.wikipedia.org/wiki/The_Mummy_Returns";
            int    testIterationId = 7;
            ILinkTableRepository linkTableRepository = Substitute.For <ILinkTableRepository>();

            linkTableRepository.ContainsByLink(Arg.Is(testLink)).Returns(false);
            ParsingService parsingService = new ParsingService(linkTableRepository, this.testFileManager);

            // Act
            parsingService.Save(testLink, testIterationId);

            // Assert
            linkTableRepository.Received(1).Add(Arg.Is <LinkEntity>(
                                                    u => u.Link == testLink &&
                                                    u.IterationId == testIterationId));
            linkTableRepository.Received(1).SaveChanges();
        }
Beispiel #5
0
        public void ShouldDownloadPage()
        {
            // Arrange
            string testLink = "https://en.wikipedia.org/wiki/The_Mummy_Returns";
            int    testId   = 5;

            ILinkTableRepository linkTableRepository = Substitute.For <ILinkTableRepository>();
            ParsingService       parsingService      = new ParsingService(linkTableRepository, this.testFileManager);

            // Act
            var downoloadPageTask = parsingService.DownloadPage(testLink, this.testHandler, testId);

            // Assert
            var finishedString = File.ReadAllText(downoloadPageTask.Result);

            File.Delete(downoloadPageTask.Result);
            if (finishedString != this.fakeFileContentsForStreamReader)
            {
                throw new ArgumentException("Wrong content");
            }
        }
Beispiel #6
0
        public void ShouldCallParsingForEachPageFromPreviousIteration()
        {
            // Arrange
            string testInputString = "https://gameofthrones.fandom.com/wiki/Jon_Snow";

            string[] testStartPageHost = new string[2];
            int      dotComPos         = testInputString.IndexOf(".com");

            testStartPageHost[0] = testInputString.Substring(0, dotComPos + 4); // https://gameofthrones.fandom.com
            testStartPageHost[1] = "/wiki/";                                    // /wiki/

            CancellationTokenSource parseCancelTokenSource = new CancellationTokenSource(15000);
            CancellationToken       parseCancellationToken = parseCancelTokenSource.Token;

            int testIterationId = 6;
            ILinkTableRepository linkTableRepository = Substitute.For <ILinkTableRepository>();

            linkTableRepository.EntityListByIterationId(Arg.Is(testIterationId)).Returns(new List <LinkEntity>
            {
                new LinkEntity()
                {
                    Id          = 7,
                    Link        = "https://en.wikipedia.org/wiki/The_Expanse_(TV_series)",
                    IterationId = testIterationId
                },
                new LinkEntity()
                {
                    Id          = 13,
                    Link        = "https://en.wikipedia.org/wiki/James_S._A._Corey",
                    IterationId = testIterationId
                }
            });
            ParsingService parsingService = new ParsingService(linkTableRepository, this.testFileManager);

            // Act
            parsingService.ParsingLinksByIterationId("teststring", testIterationId, testStartPageHost, parseCancellationToken);

            // Assert
        }
Beispiel #7
0
 public LinkService(ILinkTableRepository linkTableRepository)
 {
     this.linkTableRepository = linkTableRepository;
 }
Beispiel #8
0
 public ParsingService(ILinkTableRepository linkTableRepository, IFileManager fileManager)
 {
     this.linkTableRepository = linkTableRepository;
     this.fileManager         = fileManager;
 }
Beispiel #9
0
 public void Initialize()
 {
     linkTableRepository = Substitute.For <ILinkTableRepository>();
     linkService         = new LinkService(this.linkTableRepository);
 }
 public void Initialize()
 {
     linkTableRepository = Substitute.For <ILinkTableRepository>();
     linkService         = Substitute.For <LinkService>(this.linkTableRepository);
     dataBaseManager     = new DataBaseManager(this.linkService);
 }