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)); }
private string Textify(RowViolationState s) { switch (s) { case RowViolationState.Missing: return("Missing"); case RowViolationState.Unexpected: return("Unexpected"); case RowViolationState.Mismatch: return("Non-matching"); default: throw new ArgumentOutOfRangeException(); } }
public IEnumerable <DataRow> GetRows(RowViolationState state) { if (Count > 0 && !isBuilt) { var firstRow = this.ElementAt(0).Value.Rows.ElementAt(0); foreach (var keyMapping in KeyMappings.Reverse()) { var column = keyMapping.CandidateColumn.GetColumn(firstRow.Table); column.ExtendedProperties["NBi::Role"] = ColumnRole.Key; column.ExtendedProperties["NBi::Lookup"] = keyMapping.ReferenceColumn.Label; } } isBuilt = true; foreach (var violation in this.Where(x => x.Value.State == state)) { foreach (var row in violation.Value.Rows) { yield return(row); } } }
protected virtual LookupViolationInformation Register(RowViolationState state, NBiRs.KeyCollection key, DataRow candidateRow) { if (ContainsKey(key)) { var info = this[key]; if (info.State != state) { throw new ArgumentException("Can't change the state of lookup violation", nameof(state)); } info.AddCandidateRow(candidateRow); return(info); } else { LookupViolationInformation info = state == RowViolationState.Mismatch ? (LookupViolationInformation) new LookupMatchesViolationInformation(state) : new LookupExistsViolationInformation(state); info.AddCandidateRow(candidateRow); Add(key, info); return(info); } }
public LookupMatchesViolationInformation(RowViolationState state) : base(state) { }
public LookupExistsViolationInformation(RowViolationState state) : base(state) { }
public LookupViolationInformation(RowViolationState state) => State = state;