public bool Contains(LinksHistoryEntity linksHistoryEntity) { using (MultithreadDbContext dbContext = new MultithreadDbContext()) { return(dbContext.Links.Any(f => f.Links == linksHistoryEntity.Links)); } }
//private readonly MultithreadDbContext dbContext; //public LinksHistoryRepositoroes(MultithreadDbContext dbContext) //{ // this.dbContext = dbContext; //} public void Add(LinksHistoryEntity linksHistoryEntity) { using (MultithreadDbContext dbContext = new MultithreadDbContext()) { dbContext.Links.Add(linksHistoryEntity); dbContext.SaveChanges(); } }
public void RegisterNewLinks(LinksHistoryEntity linksHistoryEntity) { if (this.linksHistoryRepositoroes.Contains(linksHistoryEntity)) { throw new ArgumentException("This links has been registered. Can't continue"); } this.linksHistoryRepositoroes.Add(linksHistoryEntity); this.linksHistoryRepositoroes.SaveChanges(); }
public void ShouldRegisterdNewLinksHistory() { var linksHistoryRepositoroes = Substitute.For <ILinksHistoryRepositoroes>(); LinksHistoryServices linksHistoryServices = new LinksHistoryServices(linksHistoryRepositoroes); LinksHistoryEntity args = new LinksHistoryEntity(); args.Links = "https://www.google.ru/webhp?source=search_app"; args.PreviousLink = "https://www.google.ru"; linksHistoryServices.ContainsLinks(args); linksHistoryRepositoroes.Contains(Arg.Is <LinksHistoryEntity>(w => w.Links == args.Links && w.PreviousLink == args.PreviousLink)).Returns(true); linksHistoryServices.ContainsLinks(args); }
public void ShouldRegisterNewLinksHistory() { var linksHistoryRepositoroes = Substitute.For <ILinksHistoryRepositoroes>(); LinksHistoryServices linksHistoryServices = new LinksHistoryServices(linksHistoryRepositoroes); LinksHistoryEntity args = new LinksHistoryEntity(); args.Links = "https://www.google.ru/webhp?source=search_app"; args.PreviousLink = "https://www.google.ru"; linksHistoryServices.RegisterNewLinks(args); linksHistoryRepositoroes.Received(1).Add(Arg.Is <LinksHistoryEntity>(w => w.Links == args.Links && w.PreviousLink == args.PreviousLink)); linksHistoryRepositoroes.Received(1).SaveChanges(); }
public void ParsingThePageCsQuery(object href) { WebClient webClient = new WebClient(); string htmlPage = webClient.DownloadString((string)href); CQ parserObject = CQ.Create(htmlPage); foreach (IDomObject obj in parserObject.Find("a[href^='/wiki/']")) { LinksHistoryEntity linksHistoryEntity = new LinksHistoryEntity() { Links = "https://en.wikipedia.org" + obj.GetAttribute("href"), PreviousLink = (string)href }; if (!linksHistoryServices.ContainsLinks(linksHistoryEntity)) { linksHistoryServices.RegisterNewLinks(linksHistoryEntity); } } }
public bool ContainsLinks(LinksHistoryEntity linksHistoryEntity) { return(this.linksHistoryRepositoroes.Contains(linksHistoryEntity)); }