protected string GetExplanationText(LookupViolationCollection violations, RowViolationState state) { string Pluralize(int x) => x > 1 ? "s" : string.Empty; string Verbalize(int x) => x > 1 ? "are" : "is"; string PluralizeVerb(int x) => x > 1 ? string.Empty : "s"; string This(int x) => x > 1 ? $"These {x} distinct" : $"This"; string Textify(RowViolationState s, int x) { switch (s) { case RowViolationState.Missing: return($"missing. It means {This(x).ToLower()} key{Pluralize(x)} {Verbalize(x)} not available in the system-under-test but {Verbalize(x)} found in the result-set defined in the assertion"); case RowViolationState.Unexpected: return($"unexpected. It means {This(x).ToLower()} key{Pluralize(x)} {Verbalize(x)} available in the system-under-test but {Verbalize(x)} not found in the result-set defined in the assertion"); case RowViolationState.Mismatch: return($"non-matching. It means the values associated to {This(x).ToLower()} key{Pluralize(x)} {Verbalize(x)} not equal in the candidate and reference tables"); default: throw new ArgumentOutOfRangeException(); } } string GetText(int x, int y) => $"{x} distinct key{Pluralize(x)} found in the candidate table {Verbalize(x)} {Textify(state, x)}. {This(x)} key{Pluralize(x)} appear{PluralizeVerb(x)} in {y} row{Pluralize(y)} of the candidate table."; var count = violations.Where(x => x.Value.State == state).Count(); var countRow = violations.Where(x => x.Value.State == state).Sum(x => x.Value.Rows.Count()); return(GetText(count, countRow)); }
protected override void RenderAnalysis(LookupViolationCollection violations, IEnumerable <ColumnMetadata> metadata, ISampler <DataRow> sampler, ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings, JsonWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("missing"); var rows = violations.Values.Where(x => x is LookupExistsViolationInformation) .Cast <LookupExistsViolationInformation>() .SelectMany(x => x.CandidateRows); sampler.Build(rows); var tableHelper = new StandardTableHelperJson(rows, metadata, sampler); tableHelper.Render(writer); writer.WriteEndObject(); }
protected override void RenderAnalysis(LookupViolationCollection violations, IEnumerable <ColumnMetadata> metadata, ISampler <DataRow> sampler, ColumnMappingCollection keyMappings, ColumnMappingCollection valueMappings, MarkdownContainer container) { container.Append("Analysis".ToMarkdownHeader()); var state = violations.Values.Select(x => x.State).First(); container.Append(GetExplanationText(violations, state).ToMarkdownParagraph()); var rows = violations.Values.Where(x => x is LookupExistsViolationInformation) .Cast <LookupExistsViolationInformation>() .SelectMany(x => x.CandidateRows); sampler.Build(rows); var tableHelper = new StandardTableHelperMarkdown(rows, metadata, sampler); tableHelper.Render(container); }