Ejemplo n.º 1
0
        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.");
            }
        }