Ejemplo n.º 1
0
        public void ExistingDateForSeoDataInDbNotCreateNewDataThrowException()
        {
            var downloadManager = new Mock <IDownloadManager>();
            var seoDataMapper   = new Mock <ISeoDataImportMapper>();
            var serpRepository  = new LocalRepository <SerpRanking>();

            var serpRankingInDb = new SerpRanking
            {
                Date    = DateTime.Now,
                Keyword = "Keyword",
                Url     = "url.se"
            };

            serpRepository.Add(serpRankingInDb);

            var seoPosion = "[{\"pr\":\"3\",\"url\":\"url.se\",\"kw\":\"key word\",\"region\":\"google.se\",\"language\":\"sv\",\"start\":\"0\"}]";

            downloadManager.Setup(dm => dm.FetchUrl(It.IsAny <string>())).Returns(seoPosion);

            var taskMessage = "";

            var task = new SeoDataImporter(downloadManager.Object, serpRepository, seoDataMapper.Object);

            task.PerformTask(new InsideModel.Models.Task()
            {
                Message = taskMessage
            });

            seoDataMapper.Verify(di => di.Map(It.IsAny <SearchEngineRank>(), It.IsAny <SerpRanking>()), Times.Never);
            Assert.AreEqual(1, serpRepository.All().Count());
        }
Ejemplo n.º 2
0
        public void CanAddSeoDataForDatesBetweenExistingDatesInRepository()
        {
            var downloadManager = new Mock <IDownloadManager>();
            var seoDataMapper   = new SeoDataImportMapper();
            var serpRepository  = new LocalRepository <SerpRanking>();

            var serpRankingInDb = new SerpRanking
            {
                Date    = DateTime.Now.AddDays(-1),
                Keyword = "Keyword",
                Url     = "url.com"
            };

            var serpRankingInDb2 = new SerpRanking
            {
                Date    = DateTime.Now.AddDays(1),
                Keyword = "Keyword",
                Url     = "url.com"
            };

            serpRepository.Add(serpRankingInDb);
            serpRepository.Add(serpRankingInDb2);

            var seoPosion = "[{\"pr\":\"0\",\"url\":\"url.se\",\"kw\":\"key word\",\"region\":\"google.se\",\"language\":\"sv\",\"start\":\"0\"}]";

            downloadManager.Setup(dm => dm.FetchUrl(It.IsAny <string>())).Returns(seoPosion);

            var taskMessage = "";

            var task = new SeoDataImporter(downloadManager.Object, serpRepository, seoDataMapper);

            task.PerformTask(new InsideModel.Models.Task()
            {
                Message = taskMessage
            });

            Assert.AreEqual(3, serpRepository.All().Count());

            var importedSerpRankings = serpRepository.All().Last();

            Assert.AreEqual("url.se", importedSerpRankings.Url);
            Assert.AreEqual("key word", importedSerpRankings.Keyword);
            Assert.AreEqual(0, importedSerpRankings.PageRank);
        }
        public void Map(SearchEngineRank searchPosition, SerpRanking serpRanking)
        {
            serpRanking.Keyword = searchPosition.KW;
            serpRanking.Url     = searchPosition.URL;

            try
            {
                serpRanking.PageRank = int.Parse(searchPosition.PR);
            }
            catch (Exception)
            {
                serpRanking.PageRank = null;
            }

            serpRanking.Region   = searchPosition.Region;
            serpRanking.Language = searchPosition.Language;

            try
            {
                serpRanking.Start = int.Parse(searchPosition.Start);
            }
            catch (Exception)
            {
                serpRanking.Start = null;
            }

            if (serpRanking.Start == 0)
            {
                serpRanking.Rank = null;
            }

            try
            {
                serpRanking.Rank = int.Parse(searchPosition.grank);
            }
            catch (Exception)
            {
                serpRanking.Rank = null;
            }

            if (serpRanking.Rank == 0)
            {
                serpRanking.Rank = null;
            }

            if (!string.IsNullOrEmpty(searchPosition.rankingurl) && searchPosition.rankingurl.ToLower() != "not found")
            {
                serpRanking.RankingUrl = searchPosition.rankingurl;
            }
            else
            {
                serpRanking.RankingUrl = null;
            }

            try
            {
                serpRanking.ChangeDay = int.Parse(searchPosition.day);
            }
            catch (Exception)
            {
                serpRanking.ChangeDay = null;
            }

            try
            {
                serpRanking.ChangeWeek = int.Parse(searchPosition.week);
            }
            catch (Exception)
            {
                serpRanking.ChangeWeek = null;
            }

            try
            {
                serpRanking.ChangeMonth = int.Parse(searchPosition.month);
            }
            catch (Exception)
            {
                serpRanking.ChangeMonth = null;
            }

            try
            {
                serpRanking.SearchVolume = int.Parse(searchPosition.searchvolume);
            }
            catch (Exception)
            {
                serpRanking.SearchVolume = null;
            }



            try
            {
                serpRanking.BackLinks = int.Parse(searchPosition.backlinks);
            }
            catch (Exception)
            {
                serpRanking.BackLinks = null;
            }
        }