public void UserFriendlyReportTest() { string expected = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "movie.txt"); if (File.Exists(expected)) { File.Delete(expected); } Movie movie1 = new Movie(); movie1.Name = "Oblivion"; movie1.PaymentForTomCruise = 2000000M; Movie movie2 = new Movie(); movie2.Name = "Edge of Tomorrow"; movie2.PaymentForTomCruise = 3000000M; CompareLogic compareLogic = new CompareLogic(); compareLogic.Config.MaxDifferences = Int32.MaxValue; ComparisonResult result = compareLogic.Compare(movie1, movie2); UserFriendlyReport friendlyReport = new UserFriendlyReport(); friendlyReport.OutputFile(result.Differences, expected); Assert.IsTrue(File.Exists(expected)); Console.WriteLine(friendlyReport.OutputString(result.Differences)); friendlyReport.LaunchApplication(expected); }
public void NegativeIntegersShouldBeNegativeOnUserFriendlyReport() { List <object> groundTruth = new List <object>(); List <object> newResult = new List <object>(); groundTruth.Add(new { boo = 1, gg = 7 }); groundTruth.Add(new { boo = -5, gg = 9 }); newResult.Add(new { boo = -6, gg = 4 }); newResult.Add(new { boo = 5, gg = 23 }); CompareLogic compareLogicObject = new CompareLogic(); compareLogicObject.Config.MaxDifferences = int.MaxValue; compareLogicObject.Config.IgnoreCollectionOrder = true; ComparisonResult assertionResult = compareLogicObject.Compare(groundTruth, newResult); Console.WriteLine("DifferencesString"); Console.WriteLine(assertionResult.DifferencesString); Console.WriteLine(); Console.WriteLine("UserFriendlyReport"); UserFriendlyReport friendlyReport = new UserFriendlyReport(); string result = friendlyReport.OutputString(assertionResult.Differences); Console.WriteLine(result); Assert.IsTrue(result.Contains("[{ boo = -5, gg = 9 }]")); }
public void DotsAndTabsShouldFormatCorrectly() { List <DotsAndTabs> groundTruth = new List <DotsAndTabs>(); List <DotsAndTabs> newResult = new List <DotsAndTabs>(); groundTruth.Add(new DotsAndTabs { boo = "hello", gg = "hello again" }); groundTruth.Add(new DotsAndTabs { boo = "scorpio \t. .\r\n11-nov", gg = "hello again2" }); newResult.Add(new DotsAndTabs { boo = "hello", gg = "hello again" }); newResult.Add(new DotsAndTabs { boo = " ..... ", gg = "hello again2" }); CompareLogic compareLogicObject = new CompareLogic(); compareLogicObject.Config.MaxDifferences = int.MaxValue; compareLogicObject.Config.IgnoreCollectionOrder = true; ComparisonResult assertionResult = compareLogicObject.Compare(groundTruth, newResult); Console.WriteLine(assertionResult.DifferencesString + "\n\n\n"); UserFriendlyReport friendlyReport = new UserFriendlyReport(); Console.WriteLine(friendlyReport.OutputString(assertionResult.Differences)); }
public void UserFriendlyReportTreeTest() { string expected = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "entityTree.txt"); if (File.Exists(expected)) { File.Delete(expected); } List <Entity> entityTree = new List <Entity>(); //Brave Sir Robin Security Company Entity top1 = new Entity(); top1.Description = "Brave Sir Robin Security Company"; top1.Parent = null; top1.EntityLevel = Level.Company; entityTree.Add(top1); Entity div1 = new Entity(); div1.Description = "Minstrils"; div1.EntityLevel = Level.Division; div1.Parent = top1; top1.Children.Add(div1); Entity div2 = new Entity(); div2.Description = "Sub Contracted Fighting"; div2.EntityLevel = Level.Division; div2.Parent = top1; top1.Children.Add(div2); Entity dep2 = new Entity(); dep2.Description = "Trojan Rabbit Department"; dep2.EntityLevel = Level.Department; dep2.Parent = div2; div2.Children.Add(dep2); //Roger the Shrubber's Fine Shrubberies Entity top1b = new Entity(); top1b.Description = "Roger the Shrubber's Fine Shrubberies"; top1b.Parent = null; top1b.EntityLevel = Level.Company; entityTree.Add(top1b); Entity div1b = new Entity(); div1b.Description = "Manufacturing"; div1b.EntityLevel = Level.Division; div1b.Parent = top1; top1b.Children.Add(div1); Entity dep1b = new Entity(); dep1b.Description = "Design Department"; dep1b.EntityLevel = Level.Department; dep1b.Parent = div1b; div1b.Children.Add(dep1b); Entity dep2b = new Entity(); dep2b.Description = "Arranging Department"; dep2b.EntityLevel = Level.Department; dep2b.Parent = div1b; div1b.Children.Add(dep2b); Entity div2b = new Entity(); div2b.Description = "Sales"; div2b.EntityLevel = Level.Division; div2b.Parent = top1; top1b.Children.Add(div2b); List <Entity> entityTreeCopy = Common.CloneWithSerialization(entityTree); entityTreeCopy[1].Children[1].Description = "Retail"; CompareLogic compareLogic = new CompareLogic(); compareLogic.Config.MaxDifferences = Int32.MaxValue; ComparisonResult result = compareLogic.Compare(entityTree, entityTreeCopy); UserFriendlyReport friendlyReport = new UserFriendlyReport(); friendlyReport.OutputFile(result.Differences, expected); Assert.IsTrue(File.Exists(expected)); Console.WriteLine(friendlyReport.OutputString(result.Differences)); friendlyReport.LaunchApplication(expected); }
public static async Task <ExcelContentTableImportResults> ImportExcelContentTable(IXLRange toProcess, IProgress <string> progress) { if (toProcess == null || toProcess.Rows().Count() < 2) { return new ExcelContentTableImportResults { HasError = true, ErrorNotes = "Nothing to process", ToUpdate = new List <ExcelImportContentUpdateSuggestion>() } } ; var headerInfo = new ExcelHeaderRow(toProcess.Row(1)); var errorNotes = new List <string>(); var updateList = new List <ExcelImportContentUpdateSuggestion>(); var db = await Db.Context(); var lastRow = toProcess.Rows().Last().RowNumber(); progress?.Report($"{lastRow} to Process"); foreach (var loopRow in toProcess.Rows().Skip(1)) { var importResult = await ImportContentFromExcelRow(headerInfo, loopRow); if (importResult.hasError) { errorNotes.Add($"Excel Row {loopRow.RowNumber()} - {importResult.errorNotes}"); continue; } try { Db.DefaultPropertyCleanup(importResult.processContent); importResult.processContent.Tags = Db.TagListCleanup(importResult.processContent.Tags); } catch { await EventLogContext.TryWriteDiagnosticMessageToLog( $"Excel Row {loopRow.RowNumber()} - Excel Import via dynamics - Tags threw an error on ContentId {importResult.processContent.ContentId ?? "New Entry"} - property probably not present", "Excel Import"); continue; } Guid contentId = importResult.processContent.ContentId; int contentDbId = importResult.processContent.Id; string differenceString; if (contentDbId > 0) { var currentDbEntry = await db.ContentFromContentId(contentId); var compareLogic = new CompareLogic { Config = { MembersToIgnore = new List <string> { "LastUpdatedBy" }, MaxDifferences= 100 } }; ComparisonResult comparisonResult = compareLogic.Compare(currentDbEntry, importResult.processContent); if (comparisonResult.AreEqual) { progress?.Report( $"Excel Row {loopRow.RowNumber()} of {lastRow} - No Changes - Title: {currentDbEntry.Title}"); continue; } var friendlyReport = new UserFriendlyReport(); differenceString = friendlyReport.OutputString(comparisonResult.Differences); importResult.processContent.LastUpdatedOn = DateTime.Now; } else { differenceString = "New Entry"; } GenerationReturn validationResult; switch (importResult.processContent) { case PhotoContent p: validationResult = await PhotoGenerator.Validate(p, UserSettingsSingleton.CurrentSettings().LocalMediaArchivePhotoContentFile(p)); break; case FileContent f: validationResult = await FileGenerator.Validate(f, UserSettingsSingleton.CurrentSettings().LocalMediaArchiveFileContentFile(f)); break; case ImageContent i: validationResult = await ImageGenerator.Validate(i, UserSettingsSingleton.CurrentSettings().LocalMediaArchiveImageContentFile(i)); break; case PointContentDto pc: validationResult = await PointGenerator.Validate(pc); break; case PostContent pc: validationResult = await PostGenerator.Validate(pc); break; case LinkContent l: validationResult = await LinkGenerator.Validate(l); break; case NoteContent n: validationResult = await NoteGenerator.Validate(n); break; default: validationResult = await GenerationReturn.Error("Excel Import - No Content Type Generator found?"); break; } if (validationResult.HasError) { errorNotes.Add($"Excel Row {loopRow.RowNumber()} - {validationResult.GenerationNote}"); progress?.Report($"Excel Row {loopRow.RowNumber()} of {lastRow} - Validation Error."); continue; } updateList.Add(new ExcelImportContentUpdateSuggestion { DifferenceNotes = differenceString, Title = importResult.processContent.Title, ToUpdate = importResult.processContent }); progress?.Report( $"Excel Row {loopRow.RowNumber()} of {lastRow} - Adding To Changed List ({updateList.Count}) - Title: {importResult.processContent.Title}"); } if (!errorNotes.Any()) { var internalContentIdDuplicates = updateList.Select(x => x.ToUpdate).GroupBy(x => x.ContentId) .Where(x => x.Count() > 1).Select(x => x.Key).Cast <Guid>().ToList(); if (internalContentIdDuplicates.Any()) { return new ExcelContentTableImportResults { HasError = true, ErrorNotes = $"Content Ids can only appear once in an update list - {string.Join(", ", internalContentIdDuplicates)}", ToUpdate = updateList } } ; var internalSlugDuplicates = updateList.Select(x => x.ToUpdate).Where(x => !(x is LinkContent)) .GroupBy(x => x.Slug).Where(x => x.Count() > 1).Select(x => x.Key).Cast <string>().ToList(); if (internalSlugDuplicates.Any()) { return new ExcelContentTableImportResults { HasError = true, ErrorNotes = $"This import appears to create duplicate slugs - {string.Join(", ", internalSlugDuplicates)}", ToUpdate = updateList } } ; } return(new ExcelContentTableImportResults { HasError = errorNotes.Any(), ErrorNotes = string.Join(Environment.NewLine, errorNotes), ToUpdate = updateList }); }