Exemplo n.º 1
0
        public async Task B21_FileMapAddingImageMapBracketCodeToBody()
        {
            var db = await Db.Context();

            var mapImage = db.ImageContents.Single(x => x.Title == IronwoodImageInfo.MapContent01.Title);

            var mapFile = db.FileContents.Single(x => x.Title == TestFileInfo.MapContent01.Title);

            mapFile.BodyContent =
                $"{BracketCodeImages.Create(mapImage)} {Environment.NewLine}{Environment.NewLine}{mapFile.BodyContent}";

            mapFile.LastUpdatedBy = "Test B21";
            mapFile.LastUpdatedOn = DateTime.Now;

            var bodyUpdateReturn = await FileGenerator.SaveAndGenerateHtml(mapFile,
                                                                           UserSettingsSingleton.CurrentSettings().LocalMediaArchiveFileContentFile(mapFile), false, null,
                                                                           DebugTrackers.DebugProgressTracker());

            Assert.False(bodyUpdateReturn.generationReturn.HasError, bodyUpdateReturn.generationReturn.GenerationNote);

            var mapFileRefresh = db.FileContents.Single(x => x.Title == TestFileInfo.MapContent01.Title);

            Assert.AreEqual(mapImage.ContentId, mapFileRefresh.MainPicture,
                            "Adding an image code to the Map File Content Body didn't result in Main Image being set.");
        }
        public async Task C10_ExcelNewPointImport()
        {
            var db = await Db.Context();

            var pointCountBeforeImport = db.PointContents.Count();

            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonPointsImport.xlsx"));

            Assert.True(testFile.Exists, "Test File Found");

            var importResult =
                await ExcelContentImports.ImportFromFile(testFile.FullName, DebugTrackers.DebugProgressTracker());

            Assert.False(importResult.HasError, "Unexpected Excel Import Failure");

            var updateSaveResult =
                await ExcelContentImports.SaveAndGenerateHtmlFromExcelImport(importResult,
                                                                             DebugTrackers.DebugProgressTracker());

            Assert.False(updateSaveResult.hasError);

            var pointCountAfterImport = db.PointContents.Count();

            var excelFile         = new XLWorkbook(testFile.FullName);
            var excelDataRowCount = excelFile.Worksheets.First().RangeUsed().RowCount() - 1;

            Assert.AreEqual(pointCountAfterImport, pointCountBeforeImport + excelDataRowCount);
        }
        public async Task Line_GpxLineFromHorseshoeMesaFileWithMeasurements()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonHorseShoeMesaEastSideLoop.gpx"));

            Assert.True(testFile.Exists, "Test File Found");

            var tracks = await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(1, tracks.Count, "Should find 1 track");

            var coordinateList = tracks.First().track;

            var metricStats   = SpatialHelpers.LineStatsInMetricFromCoordinateList(coordinateList);
            var imperialStats = SpatialHelpers.LineStatsInImperialFromMetricStats(metricStats);

            Assert.IsTrue(imperialStats.Length.IsApproximatelyEqualTo(13, .3),
                          $"ExpertGPS Length 13.03, Measured {imperialStats.Length}");
            Assert.IsTrue(imperialStats.ElevationClimb.IsApproximatelyEqualTo(9000, 100),
                          $"ExpertGPS Climb 9023, Measured {imperialStats.ElevationClimb}");
            Assert.IsTrue(imperialStats.ElevationDescent.IsApproximatelyEqualTo(8932, 100),
                          $"ExpertGPS Descent 8932, Measured {imperialStats.ElevationDescent}");
            Assert.IsTrue(imperialStats.MinimumElevation.IsApproximatelyEqualTo(3591, 30),
                          $"ExpertGPS Min Elevation 13.03, Measured {imperialStats.MinimumElevation}");
            Assert.IsTrue(imperialStats.MaximumElevation.IsApproximatelyEqualTo(7384, 30),
                          $"ExpertGPS Max Elevation 13.03, Measured {imperialStats.MaximumElevation}");
        }
        public async Task G01_GeoJsonGrandCanyonWildfireSave()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonHistoricWildfireGeoJson.geojson"));

            Assert.True(testFile.Exists, "GeoJson Test File Found");

            var geoJsonTest = new GeoJsonContent
            {
                ContentId         = Guid.NewGuid(),
                BodyContent       = "Grand Canyon Historic Wildfire GeoJson Test",
                BodyContentFormat = ContentFormatDefaults.Content.ToString(),
                CreatedOn         = DateTime.Now,
                CreatedBy         = "GC Test for GeoJson",
                Folder            = "GrandCanyon",
                Title             = "Grand Canyon Historic Wildfire Boundaries",
                Slug = "grand-canyon-historic-wildfire-boundaries",
                ShowInMainSiteFeed = true,
                Summary            = "Boundaries for Grand Canyon Wildfires",
                Tags = "grand-canyon, geojson",
                UpdateNotesFormat = ContentFormatDefaults.Content.ToString(),
                GeoJson           = await File.ReadAllTextAsync(testFile.FullName)
            };

            var result =
                await GeoJsonGenerator.SaveAndGenerateHtml(geoJsonTest, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(result.generationReturn.HasError);
        }
        public async Task Line_SanPedroTwoTrackFileLineToGeoJsonAndBack()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "TwoTrackGpxNearTheSanPedro.gpx"));

            Assert.True(testFile.Exists, "Test File Found");

            var tracks = await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(2, tracks.Count, "Should find 2 tracks");
            Assert.True(tracks.All(x => !string.IsNullOrWhiteSpace(x.description)),
                        "Found Tracks with Blank Description?");

            var shortTrack = tracks.OrderBy(x => x.track.Count).First().track;
            var geoJson    =
                await SpatialHelpers.GeoJsonWithLineStringFromCoordinateList(shortTrack, false,
                                                                             DebugTrackers.DebugProgressTracker());

            var shortTrackFromGeoJson =
                SpatialHelpers.CoordinateListFromGeoJsonFeatureCollectionWithLinestring(geoJson);

            Assert.AreEqual(shortTrack.Count, shortTrackFromGeoJson.Count, "Count of Track Points does not match");

            for (var i = 0; i < shortTrack.Count; i++)
            {
                Assert.AreEqual(shortTrack[i].X, shortTrackFromGeoJson[i].X, $"Point {i} X Values don't match");
                Assert.AreEqual(shortTrack[i].Y, shortTrackFromGeoJson[i].Y, $"Point {i} Y Values don't match");
                Assert.AreEqual(shortTrack[i].Z, shortTrackFromGeoJson[i].Z, $"Point {i} Z Values don't match");
            }
        }
        public async Task C11_ExcelNewPointImportValidationFailureOnDuplicatingExistingSlug()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonPointsImport.xlsx"));

            Assert.True(testFile.Exists, "Test File Found");

            var importResult =
                await ExcelContentImports.ImportFromFile(testFile.FullName, DebugTrackers.DebugProgressTracker());

            Assert.True(importResult.HasError,
                        "Expected a validation failure due to duplicate slug but not detected...");
        }
        public async Task C12_ExcelNewPointImportValidationFailureTryingToImportSameSlugMultipleTimes()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "HermitsRestDuplicateSlugImport.xlsx"));

            Assert.True(testFile.Exists, "Test File Found");

            var importResult =
                await ExcelContentImports.ImportFromFile(testFile.FullName, DebugTrackers.DebugProgressTracker());

            Assert.True(importResult.HasError,
                        "Expected a validation failure due to duplicate slug but not detected...");
        }
        public async Task B11_YumaPointElevationServiceTest()
        {
            var httpClient = new HttpClient();

            var elevation = await ElevationService.OpenTopoNedElevation(httpClient,
                                                                        GrandCanyonPointInfo.YumaPointContent02.Latitude, GrandCanyonPointInfo.YumaPointContent02.Longitude,
                                                                        DebugTrackers.DebugProgressTracker());

            Assert.NotNull(elevation, "Elevation returned null");

            var concreteElevation = Math.Round(elevation.Value.MetersToFeet(), 0);

            Assert.AreEqual(GrandCanyonPointInfo.YumaPointContent02.Elevation, concreteElevation,
                            "Service Elevation does not match");
        }
        public async Task Line_SanPedroTwoTrackFile()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "TwoTrackGpxNearTheSanPedro.gpx"));

            Assert.True(testFile.Exists, "Test File Found");

            var tracks = await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(2, tracks.Count, "Should find 2 tracks");
            Assert.True(tracks.All(x => !string.IsNullOrWhiteSpace(x.description)),
                        "Found Tracks with Blank Description?");

            var shortTrack = tracks.OrderBy(x => x.track.Count).First().track;

            Assert.AreEqual(214, shortTrack.Count, "Unexpected Point Count");

            var preElevationReplacementStats = SpatialHelpers.LineStatsInImperialFromCoordinateList(shortTrack);

            Assert.IsTrue(preElevationReplacementStats.Length.IsApproximatelyEqualTo(2.8, .05),
                          $"ExpertGPS Length 2.79, Measured {preElevationReplacementStats.Length}");
            Assert.IsTrue(preElevationReplacementStats.ElevationClimb.IsApproximatelyEqualTo(158, 1),
                          $"ExpertGPS Climb 158.4, Measured {preElevationReplacementStats.ElevationClimb}");
            Assert.IsTrue(preElevationReplacementStats.ElevationDescent.IsApproximatelyEqualTo(285, 1),
                          $"ExpertGPS Descent 285.6, Measured {preElevationReplacementStats.ElevationDescent}");
            Assert.IsTrue(preElevationReplacementStats.MinimumElevation.IsApproximatelyEqualTo(3795, 1),
                          $"ExpertGPS Min Elevation 3795.25, Measured {preElevationReplacementStats.MinimumElevation}");
            Assert.IsTrue(preElevationReplacementStats.MaximumElevation.IsApproximatelyEqualTo(3944, 1),
                          $"ExpertGPS Max Elevation 3944.76, Measured {preElevationReplacementStats.MaximumElevation}");

            await ElevationService.OpenTopoMapZenElevation(new HttpClient(), shortTrack,
                                                           DebugTrackers.DebugProgressTracker());

            Assert.True(shortTrack.All(x => x.Z > 0), "After Elevation replacement some 0 values found");

            var postElevationReplacementStats = SpatialHelpers.LineStatsInImperialFromCoordinateList(shortTrack);

            Assert.IsTrue(postElevationReplacementStats.Length.IsApproximatelyEqualTo(2.8, .05),
                          $"ExpertGPS Length 2.79, Measured {preElevationReplacementStats.Length}");
            Assert.IsTrue(postElevationReplacementStats.ElevationClimb.IsApproximatelyEqualTo(36.08, 1),
                          $"Expected 36.08, Measured {preElevationReplacementStats.ElevationClimb}");
            Assert.IsTrue(postElevationReplacementStats.ElevationDescent.IsApproximatelyEqualTo(187, 1),
                          $"Expected 187, Measured {preElevationReplacementStats.ElevationDescent}");
            Assert.IsTrue(postElevationReplacementStats.MinimumElevation.IsApproximatelyEqualTo(3891.07, 1),
                          $"Expected 3891, Measured {preElevationReplacementStats.MinimumElevation}");
            Assert.IsTrue(postElevationReplacementStats.MaximumElevation.IsApproximatelyEqualTo(4041.99, 1),
                          $"Expected 4041, Measured {preElevationReplacementStats.MaximumElevation}");
        }
        public async Task L01_HorseshoeMesaLineContent()
        {
            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     "GrandCanyonHorseShoeMesaEastSideLoop.gpx"));

            Assert.True(testFile.Exists, "GPX Test File Found");

            var lineTest = new LineContent
            {
                ContentId         = Guid.NewGuid(),
                BodyContent       = "Horseshoe Mesa East Side Loop",
                BodyContentFormat = ContentFormatDefaults.Content.ToString(),
                CreatedOn         = DateTime.Now,
                CreatedBy         = "GPX Import Test",
                Folder            = "GrandCanyon",
                Title             = "Horseshoe Mesa East Side Loop",
                Slug = "horseshoe-mesa-east-side-loop",
                ShowInMainSiteFeed = true,
                Summary            = "Horseshoe Mesa East Side Loop",
                Tags = "grand-canyon, horse-shoe-mesa",
                UpdateNotesFormat = ContentFormatDefaults.Content.ToString()
            };

            var track = (await SpatialHelpers.TracksFromGpxFile(testFile, DebugTrackers.DebugProgressTracker()))
                        .First();

            var stats = SpatialHelpers.LineStatsInMetricFromCoordinateList(track.track);

            lineTest.ClimbElevation   = stats.ElevationClimb;
            lineTest.DescentElevation = stats.ElevationDescent;
            lineTest.MinimumElevation = stats.MinimumElevation;
            lineTest.MaximumElevation = stats.MaximumElevation;
            lineTest.LineDistance     = stats.Length;

            lineTest.Line =
                await SpatialHelpers.GeoJsonWithLineStringFromCoordinateList(track.track, false,
                                                                             DebugTrackers.DebugProgressTracker());

            var validationResult = await LineGenerator.Validate(lineTest);

            Assert.IsFalse(validationResult.HasError);

            var saveResult =
                await LineGenerator.SaveAndGenerateHtml(lineTest, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);
        }
Exemplo n.º 11
0
        public async Task F11_HtmlChangedGenerationAfterPostAddedTest()
        {
            var db = await Db.Context();

            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()}");

            await FileManagement.RemoveContentDirectoriesAndFilesNotFoundInCurrentDatabase(
                DebugTrackers.DebugProgressTracker());

            IronwoodHtmlHelpers.CheckIndexHtmlAndGenerationVersion(currentGeneration.GenerationVersion);

            var tagFiles = UserSettingsSingleton.CurrentSettings().LocalSiteTagsDirectory().GetFiles("*.html").ToList();

            var changedTags =
                Db.TagListParseToSlugs(await db.PostContents.SingleAsync(x => x.Title == "First Post"), false)
                .Select(x => $"TagList-{x}").ToList();

            var notChanged = tagFiles.Where(x => !changedTags.Contains(Path.GetFileNameWithoutExtension(x.Name)))
                             .ToList();

            notChanged.ForEach(x =>
                               IronwoodHtmlHelpers.CheckGenerationVersionLessThan(x, currentGeneration.GenerationVersion));

            tagFiles.Where(x => changedTags.Contains(Path.GetFileNameWithoutExtension(x.Name))).ToList().ForEach(x =>
                                                                                                                 IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));

            var photoContent = UserSettingsSingleton.CurrentSettings().LocalSitePhotoDirectory()
                               .GetFiles("*.html", SearchOption.AllDirectories).ToList();

            photoContent.ForEach(x =>
                                 IronwoodHtmlHelpers.CheckGenerationVersionLessThan(x, currentGeneration.GenerationVersion));

            var noteContent = UserSettingsSingleton.CurrentSettings().LocalSiteNoteDirectory()
                              .GetFiles("*.html", SearchOption.AllDirectories).Where(x => !x.Name.Contains("List")).ToList();

            noteContent.ForEach(x =>
                                IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));
        }
Exemplo n.º 12
0
        public async Task A00_CreateTestSite()
        {
            var outSettings = await UserSettingsUtilities.SetupNewSite(
                $"TrailNotesTestSite-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}", DebugTrackers.DebugProgressTracker());

            TestSiteSettings                  = outSettings;
            TestSiteSettings.SiteName         = TestSiteName;
            TestSiteSettings.DefaultCreatedBy = TestDefaultCreatedBy;
            TestSiteSettings.SiteAuthors      = TestSiteAuthors;
            TestSiteSettings.SiteEmailTo      = TestSiteEmailTo;
            TestSiteSettings.SiteKeywords     = TestSiteKeywords;
            TestSiteSettings.SiteSummary      = TestSummary;
            TestSiteSettings.SiteUrl          = "localhost";
            await TestSiteSettings.EnsureDbIsPresent(DebugTrackers.DebugProgressTracker());

            await TestSiteSettings.WriteSettings();

            UserSettingsSingleton.CurrentSettings().InjectFrom(TestSiteSettings);
        }
Exemplo n.º 13
0
        public async Task A23_PhotoDeleteAndRestoreTest()
        {
            var db = await Db.Context();

            var treePhoto = db.PhotoContents.Single(x =>
                                                    x.Title == IronwoodPhotoInfo.IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.Title);

            var preDeleteTreePhotoHistoricEntryCount =
                db.HistoricPhotoContents.Count(x => x.ContentId == treePhoto.ContentId);

            await Db.DeletePhotoContent(treePhoto.ContentId, DebugTrackers.DebugProgressTracker());

            var postDeleteTreePhotoHistoricEntryCount =
                db.HistoricPhotoContents.Count(x => x.ContentId == treePhoto.ContentId);

            Assert.AreEqual(preDeleteTreePhotoHistoricEntryCount + 1, postDeleteTreePhotoHistoricEntryCount,
                            "After deleting the historic entry count should have increased by one but " +
                            $"found {preDeleteTreePhotoHistoricEntryCount} entries before and {postDeleteTreePhotoHistoricEntryCount} entries after?");

            Assert.IsEmpty(db.PhotoContents.Where(x => x.ContentId == treePhoto.ContentId).ToList(),
                           $"Photo Content Id {treePhoto.ContentId} still" + "found in DB after delete.");

            var deletedItem = await Db.DeletedPhotoContent();

            Assert.AreEqual(1, deletedItem.Count,
                            $"There should be one deleted content return - found {deletedItem.Count}");
            Assert.AreEqual(treePhoto.ContentId, deletedItem.First().ContentId,
                            "Deleted Item doesn't have the correct Content Id");

            var latestHistoricEntry = db.HistoricPhotoContents.Where(x => x.ContentId == treePhoto.ContentId)
                                      .OrderByDescending(x => x.ContentVersion).First();

            Assert.AreEqual(latestHistoricEntry.Id, latestHistoricEntry.Id,
                            "Deleted Item doesn't match the Id of the last historic entry?");

            var saveAgainResult = await PhotoGenerator.SaveAndGenerateHtml(treePhoto,
                                                                           UserSettingsSingleton.CurrentSettings().LocalMediaArchivePhotoContentFile(treePhoto), true, null,
                                                                           DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveAgainResult.generationReturn.HasError,
                           $"Error Saving after Deleting? {saveAgainResult.generationReturn.GenerationNote}");
        }
        public async Task ElevationService_MultiPointNedTest()
        {
            var client = new HttpClient();

            var testData = GrandCanyonPointsWithNed10Elevations()
                           .Select(x => new CoordinateZ(x.Longitude, x.Latitude, 0)).ToList();

            await ElevationService.OpenTopoNedElevation(client, testData, DebugTrackers.DebugProgressTracker());

            Assert.IsTrue(testData.All(x => x.Z > 0), "Not all point have an elevation greater than zero.");

            var referenceData = GrandCanyonPointsWithNed10Elevations();

            foreach (var loopTestData in testData)
            {
                var referenceItem =
                    referenceData.Single(x => x.Latitude == loopTestData.Y && x.Longitude == loopTestData.X);
                Assert.AreEqual(Math.Round(referenceItem.RoundedElevationInMeters, 2), Math.Round(loopTestData.Z, 2),
                                $"{referenceItem.Name} didn't match expected");
            }
        }
        public async Task Z10_GenerateAllHtml()
        {
            var db = await Db.Context();

            var forIndex = await db.PointContents.OrderByDescending(x => x.ContentId).Take(4).ToListAsync();

            forIndex.ForEach(x => x.ShowInMainSiteFeed = true);
            await db.SaveChangesAsync(true);

            var currentGenerationCount = db.GenerationLogs.Count();

            await HtmlGenerationGroups.GenerateAllHtml(DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(),
                            $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}");

            var currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            await FileManagement.RemoveContentDirectoriesAndFilesNotFoundInCurrentDatabase(
                DebugTrackers.DebugProgressTracker());

            IronwoodHtmlHelpers.CheckIndexHtmlAndGenerationVersion(currentGeneration.GenerationVersion);
        }
        public async Task ElevationService_SinglePointNedTest()
        {
            var client = new HttpClient();

            var testData = GrandCanyonPointsWithNed10Elevations();

            foreach (var loopTests in testData)
            {
                var result = await ElevationService.OpenTopoNedElevation(client, loopTests.Latitude,
                                                                         loopTests.Longitude, DebugTrackers.DebugProgressTracker());

                Assert.NotNull(result, $"Null result from {loopTests.Name}");
                Assert.AreEqual(loopTests.RoundedElevationInMeters, Math.Round(result.Value, 2), $"{loopTests.Name}");
            }
        }
        public async Task M01_GenerateMap()
        {
            var newMap = new MapComponent
            {
                ContentId         = Guid.NewGuid(),
                CreatedBy         = "Map Test D01",
                CreatedOn         = DateTime.Now,
                Title             = "Grand Canyon Map",
                Summary           = "Grand Canyon Test Grouping",
                UpdateNotesFormat = ContentFormatDefaults.Content.ToString()
            };

            var db = await Db.Context();

            var piutePoint = await db.PointContents.SingleAsync(x => x.Title == "Piute Point");

            var pointsNearPiutePoint = await db.PointContents.Where(x =>
                                                                    Math.Abs(x.Longitude - piutePoint.Longitude) < .1 && Math.Abs(x.Latitude - piutePoint.Latitude) < .1 &&
                                                                    x.Title.EndsWith("Point")).ToListAsync();

            var pointElements = new List <MapElement>();

            foreach (var loopPoints in pointsNearPiutePoint)
            {
                pointElements.Add(new MapElement
                {
                    ElementContentId      = loopPoints.ContentId,
                    ShowDetailsDefault    = false,
                    IncludeInDefaultView  = true,
                    MapComponentContentId = newMap.ContentId,
                    IsFeaturedElement     = true
                });
            }

            var lineElement = await db.LineContents.FirstAsync();

            pointElements.Add(new MapElement
            {
                ElementContentId      = lineElement.ContentId,
                ShowDetailsDefault    = false,
                IncludeInDefaultView  = true,
                MapComponentContentId = newMap.ContentId,
                IsFeaturedElement     = true
            });

            var grandCanyonFireGeoJson = await db.GeoJsonContents.FirstAsync();

            pointElements.Add(new MapElement
            {
                ElementContentId      = grandCanyonFireGeoJson.ContentId,
                ShowDetailsDefault    = false,
                IncludeInDefaultView  = true,
                MapComponentContentId = newMap.ContentId,
                IsFeaturedElement     = true
            });


            pointElements.First().ShowDetailsDefault = true;

            var newMapDto = new MapComponentDto(newMap, pointElements);

            var validationResult = await MapComponentGenerator.Validate(newMapDto);

            Assert.IsFalse(validationResult.HasError);

            var saveResult =
                await MapComponentGenerator.SaveAndGenerateData(newMapDto, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);
        }
Exemplo n.º 18
0
        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
        }
Exemplo n.º 19
0
        public async Task A22_PhotoExcelUpdate()
        {
            var db = await Db.Context();

            var podPhoto  = db.PhotoContents.Single(x => x.Title == IronwoodPhotoInfo.IronwoodPodContent01.Title);
            var treePhoto = db.PhotoContents.Single(x => x.Title == IronwoodPhotoInfo.IronwoodTreeContent01.Title);

            var items = new List <object> {
                podPhoto, treePhoto
            };

            var excelFileExport = ExcelHelpers.ContentToExcelFileAsTable(items, "IronwoodTestExport01", false);

            var workbook  = new XLWorkbook(excelFileExport.FullName);
            var worksheet = workbook.Worksheets.First();
            var headerRow = worksheet.RangeUsed().Rows(1, 1);

            var contentIdSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "ContentId").WorksheetColumn()
                                       .ColumnNumber();
            var slugSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "Slug").WorksheetColumn()
                                  .ColumnNumber();
            var titleSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "Title").WorksheetColumn()
                                   .ColumnNumber();
            var summarySheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "Summary").WorksheetColumn()
                                     .ColumnNumber();
            var tagsSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "Tags").WorksheetColumn()
                                  .ColumnNumber();
            var updateNotesSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "UpdateNotes")
                                         .WorksheetColumn().ColumnNumber();
            var updatedBySheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "LastUpdatedBy")
                                       .WorksheetColumn().ColumnNumber();
            var lensSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "Lens").WorksheetColumn()
                                  .ColumnNumber();
            var cameraModelSheetColumn = headerRow.Cells().First(x => x.Value.ToString() == "CameraModel")
                                         .WorksheetColumn().ColumnNumber();

            var idColumn = worksheet.Column(contentIdSheetColumn).Intersection(worksheet.RangeUsed()).AsRange();

            var treeSheetPossibleRow =
                idColumn.Cells().FirstOrDefault(x => x.Value.ToString() == treePhoto.ContentId.ToString());

            Assert.NotNull(treeSheetPossibleRow, "No Row found for the tree photo in the Excel Import?");

            var treeSheetRow = treeSheetPossibleRow.WorksheetRow().RowNumber();

            worksheet.Cell(treeSheetRow, slugSheetColumn).Value =
                IronwoodPhotoInfo.IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.Slug;

            worksheet.Cell(treeSheetRow, titleSheetColumn).Value = IronwoodPhotoInfo
                                                                   .IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.Title;

            worksheet.Cell(treeSheetRow, summarySheetColumn).Value = IronwoodPhotoInfo
                                                                     .IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.Summary;

            worksheet.Cell(treeSheetRow, tagsSheetColumn).Value =
                IronwoodPhotoInfo.IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.Tags;

            worksheet.Cell(treeSheetRow, updateNotesSheetColumn).Value = IronwoodPhotoInfo
                                                                         .IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.UpdateNotes;

            worksheet.Cell(treeSheetRow, updatedBySheetColumn).Value = IronwoodPhotoInfo
                                                                       .IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.LastUpdatedBy;

            var podSheetRow = idColumn.Cells().First(x => x.Value.ToString() == podPhoto.ContentId.ToString())
                              .WorksheetRow().RowNumber();

            worksheet.Cell(podSheetRow, cameraModelSheetColumn).Value =
                IronwoodPhotoInfo.IronwoodPodContent02_CamerModelLensSummary.CameraModel;

            worksheet.Cell(podSheetRow, lensSheetColumn).Value =
                IronwoodPhotoInfo.IronwoodPodContent02_CamerModelLensSummary.Lens;

            worksheet.Cell(podSheetRow, summarySheetColumn).Value =
                IronwoodPhotoInfo.IronwoodPodContent02_CamerModelLensSummary.Summary;

            worksheet.Cell(podSheetRow, updatedBySheetColumn).Value =
                IronwoodPhotoInfo.IronwoodPodContent02_CamerModelLensSummary.LastUpdatedBy;

            workbook.Save();

            var importResult =
                await ExcelContentImports.ImportFromFile(excelFileExport.FullName,
                                                         DebugTrackers.DebugProgressTracker());

            Assert.False(importResult.HasError, "Unexpected Excel Import Failure");
            Assert.AreEqual(2, importResult.ToUpdate.Count, "Unexpected number of rows to update");

            var updateSaveResult =
                await ExcelContentImports.SaveAndGenerateHtmlFromExcelImport(importResult,
                                                                             DebugTrackers.DebugProgressTracker());

            Assert.False(updateSaveResult.hasError);

            var updatedPodPhoto = db.PhotoContents.Single(x =>
                                                          x.Title == IronwoodPhotoInfo.IronwoodPodContent02_CamerModelLensSummary.Title);
            var updatedTreePhoto = db.PhotoContents.Single(x =>
                                                           x.Title == IronwoodPhotoInfo.IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy.Title);

            var podReference = IronwoodPhotoInfo.IronwoodPodContent02_CamerModelLensSummary;

            podReference.LastUpdatedOn = updatedPodPhoto.LastUpdatedOn;

            var updatedPodComparison = IronwoodPhotoInfo.CompareContent(podReference, updatedPodPhoto);

            Assert.True(updatedPodComparison.areEqual,
                        $"Excel Pod Picture Update Issues: {updatedPodComparison.comparisonNotes}");

            var treeReference = IronwoodPhotoInfo.IronwoodTreeContent02_SlugTitleSummaryTagsUpdateNotesUpdatedBy;

            treeReference.LastUpdatedOn = updatedTreePhoto.LastUpdatedOn;

            var updatedTreeComparison = IronwoodPhotoInfo.CompareContent(treeReference, updatedTreePhoto);

            Assert.True(updatedTreeComparison.areEqual,
                        $"Excel Tree Picture Update Issues: {updatedPodComparison.comparisonNotes}");
        }
Exemplo n.º 20
0
        public async Task B01_NewFile()
        {
            ThreadSwitcher.PinnedDispatcher        = Dispatcher.CurrentDispatcher;
            DataNotifications.SuspendNotifications = false;
            DataNotifications.NewDataNotificationChannel().MessageReceived += DebugTrackers.DataNotificationDiagnostic;

            var testFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                     TestFileInfo.TrailInfoGrandviewFilename));

            var newFileContext = await FileContentEditorContext.CreateInstance(null, testFile);

            //Starting State
            Assert.False(newFileContext.SelectedFileHasValidationIssues);
            Assert.True(newFileContext.SelectedFileHasPathOrNameChanges);

            //Simulate no file
            newFileContext.SelectedFile = null;

            Assert.That(() => newFileContext.SelectedFileHasValidationIssues, Is.True.After(4000));
            Assert.False(newFileContext.SelectedFileHasPathOrNameChanges);

            //To make clean URLs Files have a restricted set of allowed characters
            var illegalCharacterTestFile = new FileInfo(Path.Combine(Directory.GetCurrentDirectory(), "TestMedia",
                                                                     "GrandviewTrail'sIllegalName.pdf"));

            newFileContext.SelectedFile = illegalCharacterTestFile;

            Assert.That(() => newFileContext.SelectedFileHasValidationIssues, Is.True.After(1000));
            Assert.True(newFileContext.SelectedFileHasPathOrNameChanges);


            //Back to Valid File
            newFileContext.SelectedFile = testFile;

            Assert.That(() => newFileContext.SelectedFileHasValidationIssues, Is.False.After(1000));
            Assert.True(newFileContext.SelectedFileHasPathOrNameChanges);


            //Blank Title is the only validation issue

            //Initial State is blank and invalid
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.TitleEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.TitleEntry.HasChanges);

            //Spaces detected as blank
            newFileContext.TitleSummarySlugFolder.TitleEntry.UserValue = "             ";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.TitleEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.TitleEntry.HasChanges);

            //Null detected as blank
            newFileContext.TitleSummarySlugFolder.TitleEntry.UserValue = null;
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.TitleEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.TitleEntry.HasChanges);

            //Empty String detected as blank
            newFileContext.TitleSummarySlugFolder.TitleEntry.UserValue = string.Empty;
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.TitleEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.TitleEntry.HasChanges);

            //Valid Title
            newFileContext.TitleSummarySlugFolder.TitleEntry.UserValue = TestFileInfo.GrandviewContent01.Title;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.TitleEntry.HasValidationIssues);
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.TitleEntry.HasChanges);


            //Slug Tests
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            newFileContext.TitleSummarySlugFolder.TitleToSlug();
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Lowercase only
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = TestFileInfo.GrandviewContent01.Slug.ToUpper();
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Can't check every excluded character so just check a few - ( is not legal
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = $"({TestFileInfo.GrandviewContent01.Slug}(";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Can't check every excluded character so just check a few - , is not legal
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue =
                $"{TestFileInfo.GrandviewContent01.Slug},{TestFileInfo.GrandviewContent01.Slug}";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Can't check every excluded character so just check a few - [whitespace] is not legal
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue =
                $"{TestFileInfo.GrandviewContent01.Slug}   {TestFileInfo.GrandviewContent01.Slug}";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Check that - and _ are allowed
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue =
                $"----____{TestFileInfo.GrandviewContent01.Slug}---____";
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Check that 100 characters are allowed but 101 fails
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = $"{new string('-', 100)}";
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue = $"{new string('-', 101)}";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);

            //Valid Slug Entry
            newFileContext.TitleSummarySlugFolder.TitleToSlug();
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SlugEntry.HasValidationIssues);
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SlugEntry.HasChanges);


            //Folder Tests
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);

            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = TestFileInfo.GrandviewContent01.Folder;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasChanges);

            //Upper Case permitted
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue =
                TestFileInfo.GrandviewContent01.Slug.ToUpper();
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);

            //Spaces not permitted
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = "Test With Space";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);

            //Absolute File Path not permitted
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = "C:\\TestFolder";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);

            //Rel File Path not permitted
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = "\\TestFolder";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);

            //Comma not permitted
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = "Test,Folder";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = TestFileInfo.GrandviewContent01.Slug;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);

            //Valid Entry for Folder
            newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue = TestFileInfo.GrandviewContent01.Folder;
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.FolderEntry.HasValidationIssues);
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.FolderEntry.HasChanges);


            //Summary Tests

            //Blank is not valid and is starting condition
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasChanges);

            //Valid Entry
            newFileContext.TitleSummarySlugFolder.SummaryEntry.UserValue = "Simple Summary";
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasValidationIssues);
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasChanges);

            //Blank not permitted
            newFileContext.TitleSummarySlugFolder.SummaryEntry.UserValue = "";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasChanges);

            //Null not permitted and handled ok
            newFileContext.TitleSummarySlugFolder.SummaryEntry.UserValue = null;
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasChanges);

            //All spaces detected as blank
            newFileContext.TitleSummarySlugFolder.SummaryEntry.UserValue = "              ";
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasValidationIssues);
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasChanges);

            //Valid Summary
            newFileContext.TitleSummarySlugFolder.SummaryEntry.UserValue = "Simple Summary";
            Assert.IsFalse(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasValidationIssues);
            Assert.IsTrue(newFileContext.TitleSummarySlugFolder.SummaryEntry.HasChanges);


            //Tags

            //Invalid initial blank state
            Assert.IsTrue(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsFalse(newFileContext.TagEdit.HasChanges);

            //Single valid tag
            newFileContext.TagEdit.Tags = "simple test";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);

            //Blanks as nothing
            newFileContext.TagEdit.Tags = "    ";
            Assert.IsTrue(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsFalse(newFileContext.TagEdit.HasChanges);

            //Null as nothing
            newFileContext.TagEdit.Tags = null;
            Assert.IsTrue(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsFalse(newFileContext.TagEdit.HasChanges);

            //Reset to good state
            newFileContext.TagEdit.Tags = "simple test";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);

            //Test invalid symbol is removed in processing
            newFileContext.TagEdit.Tags = "simple test; another ";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);
            Assert.AreEqual("simple test another ", newFileContext.TagEdit.Tags);

            //Capitals removed
            newFileContext.TagEdit.Tags = "  SIMPLE TEST ";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);
            Assert.AreEqual("  simple test ", newFileContext.TagEdit.Tags);

            //Hyphens Valid - 3 tags
            newFileContext.TagEdit.Tags = "test-one, test--two, test---three";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);
            Assert.AreEqual(3, newFileContext.TagEdit.TagList().Count);

            //New Line not Valid
            newFileContext.TagEdit.Tags = "test-1, test--2, \r\n test---3";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);
            Assert.AreEqual("test-1, test--2,  test---3", newFileContext.TagEdit.Tags);

            //Hyphens Valid - 3 tags
            newFileContext.TagEdit.Tags = "test-1, test--2, test---3";
            Assert.IsFalse(newFileContext.TagEdit.HasValidationIssues);
            Assert.IsTrue(newFileContext.TagEdit.HasChanges);
            Assert.AreEqual(3, newFileContext.TagEdit.TagList().Count);


            //Created/Updated By

            Assert.AreEqual("Trail Notes Ghost Writer", newFileContext.CreatedUpdatedDisplay.CreatedByEntry.UserValue);
            Assert.True(newFileContext.CreatedUpdatedDisplay.HasChanges);
            Assert.False(newFileContext.CreatedUpdatedDisplay.HasValidationIssues);

            newFileContext.CreatedUpdatedDisplay.CreatedByEntry.UserValue = "   ";
            Assert.False(newFileContext.CreatedUpdatedDisplay.HasChanges);
            Assert.True(newFileContext.CreatedUpdatedDisplay.HasValidationIssues);

            newFileContext.CreatedUpdatedDisplay.CreatedByEntry.UserValue = "Trail Notes Ghost Writer";
            Assert.True(newFileContext.CreatedUpdatedDisplay.HasChanges);
            Assert.False(newFileContext.CreatedUpdatedDisplay.HasValidationIssues);


            //Body Text
            Assert.False(newFileContext.BodyContent.HasChanges);
            newFileContext.BodyContent.BodyContent =
                "UI Context Testing File with Bad Content Id {{postlink c3c63473-6b60-4531-97f7-2d201d84e2be; Cocopa and Yuma Points, Grand Canyon - 9/30-10/1/2020}}";
            Assert.True(newFileContext.BodyContent.HasChanges);

            //Update Text
            Assert.False(newFileContext.UpdateNotes.HasChanges);
            newFileContext.UpdateNotes.UpdateNotes =
                "UI Context Testing File with Bad Content Id {{postlink c3c63473-6b60-4531-97f7-2d201d84e2be; text Bad Content Id Text ;Cocopa and Yuma Points, Grand Canyon - 9/30-10/1/2020}}";
            Assert.True(newFileContext.UpdateNotes.HasChanges);

            var validationResult = await FileGenerator.Validate(newFileContext.CurrentStateToFileContent(),
                                                                newFileContext.SelectedFile);

            Assert.True(validationResult.HasError);


            //Body Text
            newFileContext.BodyContent.BodyContent = "UI Context Testing File";
            Assert.True(newFileContext.BodyContent.HasChanges);

            validationResult = await FileGenerator.Validate(newFileContext.CurrentStateToFileContent(),
                                                            newFileContext.SelectedFile);

            Assert.True(validationResult.HasError);

            //Update Text
            newFileContext.UpdateNotes.UpdateNotes = "UI Context Testing File Update";
            Assert.True(newFileContext.UpdateNotes.HasChanges);

            validationResult = await FileGenerator.Validate(newFileContext.CurrentStateToFileContent(),
                                                            newFileContext.SelectedFile);

            Assert.False(validationResult.HasError);

            var saveResult = await FileGenerator.SaveAndGenerateHtml(newFileContext.CurrentStateToFileContent(),
                                                                     newFileContext.SelectedFile, false, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);

            var db = await Db.Context();

            Assert.AreEqual(1, db.FileContents.Count());

            var dbContent = await db.FileContents.FirstOrDefaultAsync();

            Assert.True(dbContent.OriginalFileName == newFileContext.SelectedFile.Name);
            Assert.True(dbContent.Title == newFileContext.TitleSummarySlugFolder.TitleEntry.UserValue);
            Assert.True(dbContent.Slug == newFileContext.TitleSummarySlugFolder.SlugEntry.UserValue);
            Assert.True(dbContent.Folder == newFileContext.TitleSummarySlugFolder.FolderEntry.UserValue);
            Assert.True(dbContent.Summary == newFileContext.TitleSummarySlugFolder.SummaryEntry.UserValue);
            Assert.True(dbContent.Tags == newFileContext.TagEdit.TagListString());
            Assert.True(dbContent.CreatedBy == newFileContext.CreatedUpdatedDisplay.CreatedByEntry.UserValue);
            Assert.True(dbContent.BodyContent == newFileContext.BodyContent.BodyContent);
            Assert.True(dbContent.UpdateNotes == newFileContext.UpdateNotes.UpdateNotes);
        }
Exemplo n.º 21
0
        public async Task D10_FirstGeneration()
        {
            var db = await Db.Context();

            Assert.True(!db.GenerationLogs.Any(), "Unexpected Content in Generation Logs");

            await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker());

            Assert.AreEqual(1, db.GenerationLogs.Count(),
                            $"Expected 1 generation log - found {db.GenerationLogs.Count()}");

            var currentGeneration = await db.GenerationLogs.FirstAsync();

            //Index File

            IronwoodHtmlHelpers.CheckIndexHtmlAndGenerationVersion(currentGeneration.GenerationVersion);

            //Tags

            var tags = await Db.TagSlugsAndContentList(true, false, DebugTrackers.DebugProgressTracker());

            var tagFiles = UserSettingsSingleton.CurrentSettings().LocalSiteTagsDirectory().GetFiles("*.html").ToList();

            Assert.AreEqual(tagFiles.Count - 1, tags.Select(x => x.tag).Count(),
                            "Did not find the expected number of Tag Files after generation.");

            foreach (var loopDbTags in tags.Select(x => x.tag).ToList())
            {
                Assert.True(tagFiles.Exists(x => x.Name == $"TagList-{loopDbTags}.html"),
                            $"Didn't find a file for Tag {loopDbTags}");
            }


            //DailyPhotos

            var photoRecords = await db.PhotoContents.ToListAsync();

            var photoDates = photoRecords.GroupBy(x => x.PhotoCreatedOn.Date).Select(x => x.Key).ToList();

            var dailyPhotoFiles = UserSettingsSingleton.CurrentSettings().LocalSiteDailyPhotoGalleryDirectory()
                                  .GetFiles("*.html").ToList();

            Assert.AreEqual(photoDates.Count, dailyPhotoFiles.Count,
                            "Didn't find the expected number of Daily Photo Files");

            foreach (var loopPhotoDates in photoDates)
            {
                Assert.True(dailyPhotoFiles.Exists(x => x.Name == $"DailyPhotos-{loopPhotoDates:yyyy-MM-dd}.html"),
                            $"Didn't find a file for Daily Photos {loopPhotoDates:yyyy-MM-dd}");
            }


            //Camera Roll
            var cameraRollFile = UserSettingsSingleton.CurrentSettings().LocalSiteCameraRollPhotoGalleryFileInfo();

            Assert.True(cameraRollFile.Exists, "Camera Roll File not found");

            var cameraRollDocument = IronwoodHtmlHelpers.DocumentFromFile(cameraRollFile);

            var cameraRollGenerationVersionAttributeString = cameraRollDocument.Head.Attributes
                                                             .Single(x => x.Name == "data-generationversion").Value;

            Assert.AreEqual(currentGeneration.GenerationVersion.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff"),
                            cameraRollGenerationVersionAttributeString,
                            "Generation Version of Camera Roll Does not match expected Log");

            //Note Check
            var noteContent = UserSettingsSingleton.CurrentSettings().LocalSiteNoteDirectory()
                              .GetFiles("*.html", SearchOption.AllDirectories).ToList();

            noteContent.ForEach(x =>
                                IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));
        }