public async Task G10_PostUpdateChangedDetectionTest() { var db = await Db.Context(); var wikiQuotePost = db.PostContents.Single(x => x.Slug == IronwoodPostInfo.WikiQuotePostContent01.Slug); var allPhotos = db.PhotoContents.ToList(); foreach (var loopPhotos in allPhotos) { wikiQuotePost.BodyContent += BracketCodePhotos.Create(loopPhotos); } wikiQuotePost.LastUpdatedBy = "Changed Html Test"; wikiQuotePost.LastUpdatedOn = DateTime.Now; var saveResult = await PostGenerator.SaveAndGenerateHtml(wikiQuotePost, null, DebugTrackers.DebugProgressTracker()); Assert.IsFalse(saveResult.generationReturn.HasError); var currentGenerationCount = db.GenerationLogs.Count(); var currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync(); await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker()); currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync(); Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(), $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}"); var relatedContentEntries = await db.GenerationRelatedContents .Where(x => x.GenerationVersion == currentGeneration.GenerationVersion).ToListAsync(); Assert.AreEqual(relatedContentEntries.Count, allPhotos.Count() + 1); Assert.AreEqual(relatedContentEntries.Select(x => x.ContentOne).Distinct().Count(), 2); Assert.AreEqual(relatedContentEntries.Select(x => x.ContentTwo).Count(), allPhotos.Count() + 1); Assert.AreEqual( relatedContentEntries.Select(x => x.ContentTwo).Except(allPhotos.Select(x => x.ContentId)).Count(), 1); Assert.AreEqual( allPhotos.Select(x => x.ContentId).Except(relatedContentEntries.Select(x => x.ContentTwo)).Count(), 0); var photoContent = UserSettingsSingleton.CurrentSettings().LocalSitePhotoDirectory() .GetFiles("*.html", SearchOption.AllDirectories).ToList().Where(x => !x.Name.Contains("Daily") && !x.Name.Contains("Roll") && !x.Name.Contains("List")).ToList(); photoContent.ForEach(x => IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion)); wikiQuotePost = db.PostContents.Single(x => x.Slug == IronwoodPostInfo.WikiQuotePostContent01.Slug); wikiQuotePost.BodyContent = wikiQuotePost.BodyContent.Replace(BracketCodePhotos.Create(allPhotos.First()), ""); wikiQuotePost.LastUpdatedBy = "Changed Html Test 02"; wikiQuotePost.LastUpdatedOn = DateTime.Now; saveResult = await PostGenerator.SaveAndGenerateHtml(wikiQuotePost, null, DebugTrackers.DebugProgressTracker()); Assert.IsFalse(saveResult.generationReturn.HasError); currentGenerationCount = db.GenerationLogs.Count(); currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync(); await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker()); currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync(); Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(), $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}"); relatedContentEntries = await db.GenerationRelatedContents .Where(x => x.GenerationVersion == currentGeneration.GenerationVersion).ToListAsync(); Assert.AreEqual(relatedContentEntries.Count, allPhotos.Count() - 1 + 1); Assert.AreEqual(relatedContentEntries.Select(x => x.ContentOne).Distinct().Count(), 2); Assert.AreEqual(relatedContentEntries.Select(x => x.ContentTwo).Count(), allPhotos.Count() - 1 + 1); Assert.AreEqual( relatedContentEntries.Select(x => x.ContentTwo).Except(allPhotos.Select(x => x.ContentId)).Count(), 1); Assert.AreEqual( allPhotos.Select(x => x.ContentId).Except(relatedContentEntries.Select(x => x.ContentTwo)).Count(), 1); photoContent = UserSettingsSingleton.CurrentSettings().LocalSitePhotoDirectory() .GetFiles("*.html", SearchOption.AllDirectories).ToList().Where(x => !x.Name.Contains("Daily") && !x.Name.Contains("Roll") && !x.Name.Contains("List")).ToList(); photoContent.ForEach(x => IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion)); wikiQuotePost = db.PostContents.Single(x => x.Slug == IronwoodPostInfo.WikiQuotePostContent01.Slug); wikiQuotePost.BodyContent += $"{Environment.NewLine}Visit Ironwood Today!"; wikiQuotePost.LastUpdatedBy = "Changed Html Test 02"; wikiQuotePost.LastUpdatedOn = DateTime.Now; saveResult = await PostGenerator.SaveAndGenerateHtml(wikiQuotePost, null, DebugTrackers.DebugProgressTracker()); Assert.IsFalse(saveResult.generationReturn.HasError); currentGenerationCount = db.GenerationLogs.Count(); currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync(); await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker()); currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync(); Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(), $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}"); relatedContentEntries = await db.GenerationRelatedContents .Where(x => x.GenerationVersion == currentGeneration.GenerationVersion).ToListAsync(); Assert.AreEqual(relatedContentEntries.Count, allPhotos.Count() - 1 + 1); Assert.AreEqual(relatedContentEntries.Select(x => x.ContentOne).Distinct().Count(), 2); Assert.AreEqual(relatedContentEntries.Select(x => x.ContentTwo).Count(), allPhotos.Count() - 1 + 1); Assert.AreEqual( relatedContentEntries.Select(x => x.ContentTwo).Except(allPhotos.Select(x => x.ContentId)).Count(), 1); Assert.AreEqual( allPhotos.Select(x => x.ContentId).Except(relatedContentEntries.Select(x => x.ContentTwo)).Count(), 1); //Todo: Check that the excluded photo is not regened }
public static async Task <(bool hasError, string errorMessage)> SaveAndGenerateHtmlFromExcelImport( ExcelContentTableImportResults contentTableImportResult, IProgress <string> progress) { var errorList = new List <string>(); var totalToUpdate = contentTableImportResult.ToUpdate.Count; var currentUpdate = 0; foreach (var loopUpdates in contentTableImportResult.ToUpdate) { currentUpdate++; progress?.Report($"Excel Import Update {currentUpdate} of {totalToUpdate}"); GenerationReturn generationResult; switch (loopUpdates.ToUpdate) { case PhotoContent photo: { generationResult = (await PhotoGenerator.SaveAndGenerateHtml(photo, UserSettingsSingleton.CurrentSettings().LocalMediaArchivePhotoContentFile(photo), false, null, progress)).generationReturn; break; } case FileContent file: { generationResult = (await FileGenerator.SaveAndGenerateHtml(file, UserSettingsSingleton.CurrentSettings().LocalMediaArchiveFileContentFile(file), false, null, progress)).generationReturn; break; } case ImageContent image: { generationResult = (await ImageGenerator.SaveAndGenerateHtml(image, UserSettingsSingleton.CurrentSettings().LocalMediaArchiveImageContentFile(image), false, null, progress)).generationReturn; break; } case PointContentDto point: { generationResult = (await PointGenerator.SaveAndGenerateHtml(point, null, progress)) .generationReturn; break; } case PostContent post: { generationResult = (await PostGenerator.SaveAndGenerateHtml(post, null, progress)) .generationReturn; break; } case NoteContent note: { generationResult = (await NoteGenerator.SaveAndGenerateHtml(note, null, progress)) .generationReturn; break; } case LinkContent link: { generationResult = (await LinkGenerator.SaveAndGenerateHtml(link, null, progress)) .generationReturn; break; } default: generationResult = await GenerationReturn.Error("Excel Import - No Content Type Generator found?"); break; } if (!generationResult.HasError) { progress?.Report( $"Updated Content Id {loopUpdates.ToUpdate.ContentId} - Title {loopUpdates.Title} - Saved"); } else { errorList.Add( $"Updating Failed: Content Id {loopUpdates} - Title {loopUpdates.Title} - Failed:{Environment.NewLine}{generationResult.GenerationNote}"); } } if (errorList.Any()) { return(true, string.Join(Environment.NewLine, errorList)); } return(false, string.Empty); }