public void Delete_PageTemplateNotFound_ThrowsException() { const int pageTemplateId = 99999999; Assert.That(() => _pageTemplateService.Delete(pageTemplateId), Throws.Exception.TypeOf <ArgumentException>() .With.Message.EqualTo(string.Format(Messages.PageTemplateNotFound, pageTemplateId))); }
public void Delete(int id, bool commit = true) { if (id < 1) { throw new ArgumentException("id"); } var sectionTemplateDbSet = _unitOfWork.Context.GetDbSet <SectionTemplate>(); var sectionTemplate = sectionTemplateDbSet.Include(x => x.PageTemplates).FirstOrDefault(x => x.Id == id); if (sectionTemplate == null) { throw new ArgumentException(string.Format(Messages.SectionTemplateNotFound, id)); } if (sectionTemplate.PageTemplates != null && sectionTemplate.PageTemplates.Any()) { foreach (var pageTemplate in sectionTemplate.PageTemplates.ToList()) { _pageTemplateService.Delete(pageTemplate, false); } } sectionTemplateDbSet.Remove(sectionTemplate); if (commit) { _unitOfWork.Commit(); } }
private void RemovePageTemplatesWithNoExistingAction(IEnumerable <PageTemplate> pageTemplates) { if (pageTemplates == null || !pageTemplates.Any()) { return; } foreach (var pageTemplate in pageTemplates.ToList()) { _pageTemplateService.Delete(pageTemplate.Id, false); } }