async void CompareAsync() { if (SelectedPlatforms != null && SelectedPlatforms.Count > 0) { List <IDbPlatform> list = new(); foreach (IDbPlatform platform in SelectedPlatforms) { list.Add(platform); } if (SelectedIDB.DB == LocalDB.OpenVGDB) { foreach (IDbPlatform platform in list) { Reporter.Report("Comparing " + platform.Releases.Count + " Robin " + platform.Title + " games to OVG."); await Task.Run(() => { CompareToOVGDB(platform); }); } } else { foreach (IDbPlatform idbPlatform in list) { Compares comparator = new(SelectedIDB.DB, idbPlatform); comparator.Title += "-" + ComparisonResults.Count; Reporter.Report("Comparing " + idbPlatform.Releases.Count + " Robin " + idbPlatform.Title + " games to " + Enum.GetName(typeof(LocalDB), SelectedIDB.DB) + "."); await Task.Run(() => { comparator.CompareToDB(Threshold, (SelectedIDB.HasRegions)); }); ComparisonResults.Add(comparator); } Reporter.Report("Finished"); } } }
public void ValidateFieldPopulation(StandardMapping mappingUnderTest) { long populated = 0; long different = 0; long documentsInIdxButNotInEdt = 0; long documentsInEdtButNotInIdx = 0; long idxUnfound = 0; long unexpectedErrors = 0; long matched = 0; long totalsampled = 0; //initiliase conversion service for field under test _idxToEdtConversionService = new IdxToEdtConversionService(mappingUnderTest); TestLogger.Debug($"Using EDT database column for comparison: {_idxToEdtConversionService.MappedEdtDatabaseColumn}"); //Get var edtValues = GetEdtFieldValues(mappingUnderTest); //loop thru each sample document foreach (var idxDocument in _idxSample) { totalsampled++; var idxField = GetIdxFieldValue(idxDocument, mappingUnderTest); if (!edtValues.TryGetValue(idxDocument.DocumentId, out var edtValueForIdxRecord) && !string.IsNullOrEmpty(idxField)) { documentsInIdxButNotInEdt++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxDocument.DocumentId, "Document not found in Edt's document table")); } else { if (string.IsNullOrEmpty(idxField)) { if (!string.IsNullOrEmpty(edtValueForIdxRecord)) { documentsInEdtButNotInIdx++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxDocument.DocumentId, $"Edt had value {edtValueForIdxRecord} for field {mappingUnderTest.EdtName} when Idx had no value.")); } else { idxUnfound++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxDocument.DocumentId, $"Field { mappingUnderTest.IdxName } not found in Idx for document")); } } else { try { if (!string.IsNullOrEmpty(edtValueForIdxRecord)) { populated++; } var expectedEdtValue = _idxToEdtConversionService.ConvertValueToEdtForm(idxField); if (!edtValueForIdxRecord.Equals(expectedEdtValue, StringComparison.InvariantCultureIgnoreCase)) { different++; ComparisonResults.Add(new Framework.Models.Reporting.ComparisonResult(idxDocument.DocumentId, edtValueForIdxRecord, expectedEdtValue, idxField)); } else { matched++; } } catch (Exception ex) { unexpectedErrors++; var error = $"{ex.Message}<br></br>{ex.StackTrace}"; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxDocument.DocumentId, error)); } } } } PrintStats(different, matched, documentsInIdxButNotInEdt, documentsInEdtButNotInIdx, idxUnfound, unexpectedErrors, populated, totalsampled); if (ComparisonErrors.Count() > 0 || ComparisonResults.Count() > 0) { var diffFile = PrintComparisonTables(mappingUnderTest.EdtName); TestLogger.Info($"Difference and error details written to: <a href=\"{diffFile}\">{diffFile}</a>"); } Assert.Zero(different, $"Differences were seen between expected value and actual value for this Edt field {mappingUnderTest.EdtName}"); Assert.Zero(unexpectedErrors, $"Unexpected errors experienced during processing {mappingUnderTest.EdtName}"); Assert.Zero(documentsInIdxButNotInEdt, $"Idx documents were not found in EDT."); Assert.Zero(documentsInEdtButNotInIdx, "Edt was found to have field populated for instances where Idx was null"); if (idxUnfound > 0) { TestLogger.Info($"The Idx was found to not have a value for field {mappingUnderTest.IdxName} in {idxUnfound} documents/instances."); } if (populated == 0) { TestLogger.Info($"No sampled documents had the Edt field {mappingUnderTest.EdtName} populated."); } }
public void Locations() { long idxUnpopulated = 0; long edtUnexpectedlyPopulated = 0; long errors = 0; long matched = 0; long different = 0; var allEdtLocations = EdtDocumentRepository.GetDocumentLocations(_idxDocumentIds); foreach (var idxDocument in _idxSample) { allEdtLocations.TryGetValue(idxDocument.DocumentId, out var edtLocation); if (string.IsNullOrWhiteSpace(edtLocation)) { different++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxDocument.DocumentId, "Location not present in EDT")); } string group = idxDocument.AllFields.SingleOrDefault(x => x.Key.Equals(Settings.LocationIdxFields[0])).Value; string custodian = idxDocument.AllFields.SingleOrDefault(x => x.Key.Equals(Settings.LocationIdxFields[1])).Value; string source = idxDocument.AllFields.SingleOrDefault(x => x.Key.Equals(Settings.LocationIdxFields[2])).Value; string location = $@"{group}\{custodian}\{source}"; idxDocument.AllFields.Where(c => c.Key.StartsWith(Settings.LocationIdxFields[3])).OrderBy(c => c.Key).ToList().ForEach( c => { if (!string.IsNullOrWhiteSpace(c.Value) && !c.Value.Contains(".msg:")) { location += @"\" + c.Value.Replace(":", "-"); } }); if (!location.Equals(edtLocation, StringComparison.InvariantCultureIgnoreCase)) { different++; ComparisonResults.Add(new Framework.Models.Reporting.ComparisonResult(idxDocument.DocumentId, edtLocation, location, location)); } else { matched++; } } var diffFile = PrintComparisonTables("Locations"); TestLogger.Info($"Difference and error details written to: <a href=\"{diffFile}\">Report\\{diffFile}</a>"); //print table of stats string[][] data = new string[][] { new string[] { "<b>Comparison Statistics:</b>" }, new string[] { "Statistic", "Count" }, new string[] { "Differences", different.ToString() }, new string[] { "Matched", matched.ToString() }, new string[] { "Unexpected Errors", errors.ToString() }, new string[] { "Edt document(s) incorrectly have a value when Idx is null", edtUnexpectedlyPopulated.ToString() }, new string[] { "Idx document(s) not populated for field under test (and EDt is also null)", idxUnpopulated.ToString() } }; TestLogger.Log(AventStack.ExtentReports.Status.Info, MarkupHelper.CreateTable(data)); Assert.Zero(different, $"Differences were seen between expected value and actual value"); Assert.Zero(edtUnexpectedlyPopulated, "Edt was found to have field populated for instances where Idx was null"); Assert.Zero(errors, "Expected errors encountered during processing"); }
public void Tags() { long idxUnpopulated = 0; long edtUnexpectedlyPopulated = 0; long errors = 0; long matched = 0; long different = 0; var workbookRecords = AunWorkbookReader.Read(); var allEdtTags = EdtDocumentRepository.GetDocumentTags(_idxDocumentIds); foreach (var idxRecord in _idxSample) { var aunWorkbookIds = idxRecord.AllFields.Where(x => x.Key.Equals("AUN_WORKBOOK_NUMERIC")); var foundEdtValue = allEdtTags.TryGetValue(idxRecord.DocumentId, out var relatedEdTags); if (aunWorkbookIds.Count() == 0) { idxUnpopulated++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxRecord.DocumentId, "AUN_WORKBOOK_NUMERIC field was not present for idx record")); if (relatedEdTags != null && relatedEdTags.Count() > 0) { edtUnexpectedlyPopulated++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxRecord.DocumentId, $"EDT has value(s) {string.Join(",", relatedEdTags)} when Idx record had no value")); } continue; } foreach (var aunWorkbookId in aunWorkbookIds) { var foundWorkbookName = workbookRecords.TryGetValue(aunWorkbookId.Value, out var aunWorkbookName); if (foundWorkbookName) { if (!foundEdtValue || (relatedEdTags != null && !relatedEdTags.Any(x => x != null && x.Equals(aunWorkbookName, System.StringComparison.InvariantCultureIgnoreCase)))) { different++; var edtLogValue = relatedEdTags != null?string.Join(";", relatedEdTags) : "none found"; ComparisonResults.Add(new Framework.Models.Reporting.ComparisonResult(idxRecord.DocumentId, edtLogValue, aunWorkbookName, aunWorkbookId.Value.ToString())); } else { matched++; } } else { errors++; ComparisonErrors.Add(new Framework.Models.Reporting.ComparisonError(idxRecord.DocumentId, $"Couldnt convert aun workbook id {aunWorkbookId} to name")); } } } var diffFile = PrintComparisonTables("Tags"); TestLogger.Info($"Difference and error details written to: <a href=\"{diffFile}\">{diffFile}</a>"); //print table of stats string[][] data = new string[][] { new string[] { "<b>Comparison Statistics:</b>" }, new string[] { "Statistic", "Count" }, new string[] { "Differences", different.ToString() }, new string[] { "Matched", matched.ToString() }, new string[] { "Unexpected Errors", errors.ToString() }, new string[] { "Edt document(s) incorrectly have a value when Idx is null", edtUnexpectedlyPopulated.ToString() }, new string[] { "Idx document(s) not populated for field under test (and EDt is also null)", idxUnpopulated.ToString() } }; TestLogger.Log(AventStack.ExtentReports.Status.Info, MarkupHelper.CreateTable(data)); Assert.Zero(different, $"Differences were seen between expected value and actual value"); Assert.Zero(edtUnexpectedlyPopulated, "Edt was found to have field populated for instances where Idx was null"); Assert.Zero(errors, "Expected errors encountered during processing"); if (idxUnpopulated > 0) { TestLogger.Info($"The Idx was found to not have a value for field AUN_WORKBOOK_NUMERIC in {idxUnpopulated} documents/instances."); } }
private void Compare(XmlNode nodeA, XmlNode nodeB) { ComparisonResult result = new ComparisonResult() { Node = nodeA.Name }; if ((nodeA == null && nodeB != null) || (nodeA != null && nodeB == null)) { result.AreEqual = false; _results.Add(result); return; } if (nodeA.HasChildNodes && nodeB.HasChildNodes) { Compare(nodeA.FirstChild, nodeB.FirstChild); } /* * We can only recursively call on each sibling after we are * done checking for children. */ if (nodeA.NextSibling != null && nodeB.NextSibling != null) { Compare(nodeA.NextSibling, nodeB.NextSibling); } if ((nodeA.NextSibling == null && nodeB.NextSibling != null) || (nodeA.NextSibling != null && nodeB.NextSibling == null)) { result.AreEqual = false; _results.Add(result); return; } if (!nodeA.Name.Equals(nodeB.Name)) { result.AreEqual = false; _results.Add(result); return; } if (!CompareAttributes(nodeA, nodeB, ref result)) { _results.Add(result); return; } if (nodeA.Value != null || nodeB.Value != null) { bool areTheSame = AreValuesTheSame(nodeA.Value, nodeB.Value); if (!areTheSame) { result.AreEqual = false; _results.Add(result); return; } } result.AreEqual = true; _results.Add(result); }