public void UrlHistoryAdminService_Delete_ShouldRemoveAPassedHistoryFromTheDb() { var urlHistory = new UrlHistory(); Session.Transact(session => session.Save(urlHistory)); _urlHistoryAdminService.Delete(urlHistory); Session.QueryOver<UrlHistory>().List().Should().NotContain(urlHistory); }
public void UnAssigningAUrlHistoryRemoveTheItemFromTheWebpageUrlList() { var urlHistory = new UrlHistory {UrlSegment = "test"}; var basicMappedWebpage = new BasicMappedWebpage {Urls = new List<UrlHistory> {urlHistory}}; urlHistory.Webpage = basicMappedWebpage; Session.Transact(session => session.Save(urlHistory)); basicMappedWebpage.Urls.Should().HaveCount(1); _updateUrlHistoryService.SetUrlHistory(new DocumentImportDTO {UrlHistory = new List<string>()}, basicMappedWebpage); basicMappedWebpage.Urls.Should().HaveCount(0); }
public void UnAssigningAUrlHistoryShouldSetTheWebpageToNull() { var urlHistory = new UrlHistory {UrlSegment = "test"}; var basicMappedWebpage = new BasicMappedWebpage {Urls = new List<UrlHistory> {urlHistory}}; urlHistory.Webpage = basicMappedWebpage; Session.Transact(session => session.Save(urlHistory)); GetAllHistories().Should().HaveCount(1); _updateUrlHistoryService.SetUrlHistory(new DocumentImportDTO {UrlHistory = new List<string>()}, basicMappedWebpage); GetAllHistories().ElementAt(0).Webpage.Should().BeNull(); }
private void AddUrls(Webpage webpage, List<string> urlsToAdd, ISession session) { foreach (string item in urlsToAdd) { UrlHistory history = _session.Query<UrlHistory>().FirstOrDefault(urlHistory => urlHistory.UrlSegment == item); bool isNew = history == null; if (isNew) { history = new UrlHistory {UrlSegment = item, Webpage = webpage}; session.Save(history); } else history.Webpage = webpage; if (!webpage.Urls.Contains(history)) webpage.Urls.Add(history); session.Update(history); } }
public void MovesTheUrlHistoryBetweenPagesIfTheyAreChanged() { var urlHistory = new UrlHistory {UrlSegment = "test"}; var basicMappedWebpage1 = new BasicMappedWebpage {Urls = new List<UrlHistory> {urlHistory}}; urlHistory.Webpage = basicMappedWebpage1; var basicMappedWebpage2 = new BasicMappedWebpage {Urls = new List<UrlHistory>()}; Session.Transact(session => session.Save(urlHistory)); Session.Transact(session => session.Save(basicMappedWebpage1)); Session.Transact(session => session.Save(basicMappedWebpage2)); basicMappedWebpage1.Urls.Should().HaveCount(1); basicMappedWebpage2.Urls.Should().HaveCount(0); _updateUrlHistoryService.SetUrlHistory(new DocumentImportDTO {UrlHistory = new List<string>()}, basicMappedWebpage1); _updateUrlHistoryService.SetUrlHistory(new DocumentImportDTO {UrlHistory = new List<string> {"test"}}, basicMappedWebpage2); basicMappedWebpage1.Urls.Should().HaveCount(0); basicMappedWebpage2.Urls.Should().HaveCount(1); }
public void ImportUrlHistory(ProductImportDataTransferObject productDto, Product product) { List<string> urlsToAdd = productDto.UrlHistory.Where( s => !product.Urls.Select(history => history.UrlSegment) .Contains(s, StringComparer.InvariantCultureIgnoreCase)).ToList(); //List<UrlHistory> urlsToRemove = // product.Urls.Where( // history => // !productDto.UrlHistory.Contains(history.UrlSegment, StringComparer.InvariantCultureIgnoreCase)) // .ToList(); foreach (string item in urlsToAdd) { UrlHistory history = _session.Query<UrlHistory>().FirstOrDefault(urlHistory => urlHistory.UrlSegment == item); bool isNew = history == null; if (isNew) { history = new UrlHistory { UrlSegment = item, Webpage = product }; _session.Transact(session => session.Save(history)); } else history.Webpage = product; if (!product.Urls.Contains(history)) product.Urls.Add(history); _session.Transact(session => session.Update(history)); } //foreach (UrlHistory history in urlsToRemove) //{ // product.Urls.Remove(history); // history.Webpage = null; // UrlHistory closureHistory = history; // _session.Transact(session => session.Update(closureHistory)); //} }
public void ShouldNotCreateNewUrlHistoryWhileMovingUrls() { var urlHistory = new UrlHistory {UrlSegment = "test"}; var basicMappedWebpage1 = new BasicMappedWebpage {Urls = new List<UrlHistory> {urlHistory}}; urlHistory.Webpage = basicMappedWebpage1; var basicMappedWebpage2 = new BasicMappedWebpage {Urls = new List<UrlHistory>()}; Session.Transact(session => session.Save(urlHistory)); Session.Transact(session => session.Save(basicMappedWebpage1)); Session.Transact(session => session.Save(basicMappedWebpage2)); GetAllHistories().Should().HaveCount(1); _updateUrlHistoryService.SetUrlHistory(new DocumentImportDTO {UrlHistory = new List<string>()}, basicMappedWebpage1); _updateUrlHistoryService.SetUrlHistory(new DocumentImportDTO {UrlHistory = new List<string> {"test"}}, basicMappedWebpage2); GetAllHistories().Should().HaveCount(1); }
public void Delete(UrlHistory urlHistory) { if (urlHistory.Webpage != null) urlHistory.Webpage.Urls.Remove(urlHistory); _session.Transact(session => _session.Delete(urlHistory)); }
public void Add(UrlHistory urlHistory) { if (urlHistory.Webpage != null) urlHistory.Webpage.Urls.Add(urlHistory); _session.Transact(session => session.Save(urlHistory)); }
public ActionResult Add(UrlHistory history) { _urlHistoryAdminService.Add(history); return RedirectToAction("Edit", "Webpage", new { id = history.Webpage.Id }); }
public ActionResult Delete_Get(UrlHistory history) { return View(history); }