private static IReadOnlyCollection <RowMatchingResult> ListDataMismatches <TRowType>( TableRows expectedRows, IEnumerable <TRowType> actualRows, Func <TRowType, string, object> getCellValue) { var firstColumnName = expectedRows.First().Keys.First(); var expectedRowsWithIndexAndKey = expectedRows.Select((row, index) => new { row, index, key = row[0] }).AsImmutable(); var actualRowsWithKey = actualRows.Select((row, index) => new { row, index, key = getCellValue(row, firstColumnName).ToString() }).AsImmutable(); var mismatchedAndMissingRows = from expectedRow in expectedRowsWithIndexAndKey join actualRow in actualRowsWithKey on expectedRow.key equals actualRow.key into matchedActualRows from matchedActualRow in matchedActualRows.DefaultIfEmpty() let rowMatchingResult = matchedActualRow != null ? MatchRows(expectedRow.row, matchedActualRow.row, expectedRow.index, getCellValue) : new MissingRow(expectedRow.key, expectedRow.index) where rowMatchingResult != null select rowMatchingResult; var unnecessaryRows = from actualRow in actualRowsWithKey where expectedRowsWithIndexAndKey.All(row => row.key != actualRow.key) select new UnnecessaryRow(actualRow.key); return(mismatchedAndMissingRows.Concat(unnecessaryRows).AsImmutable()); }
public static IEnumerable<MatchInformation> ConvertToMatchInformationList(TableRows row) { var qry = row.Select(it => new MatchInformation { Id = it.ConvertToInt("Id"), LeagueName = it.GetString("LeagueName"), Status = it.GetString("Status"), BeginDate = it.ConvertToDateTime("BeginDate"), CompletedDate = it.ConvertToNullableDateTime("CompletedDate"), StartedDate = it.ConvertToNullableDateTime("StartedDate"), CalculatedDate = it.ConvertToNullableDateTime("CalculatedDate"), TeamAway = new TeamInformation { Id = it.ConvertToInt("TeamAway.Id"), Name = it.GetString("TeamAway.Name"), CurrentScore = it.ConvertToInt("TeamAway.CurrentScore"), IsSelected = it.ConvertToBoolean("TeamAway.IsSelected"), CurrentPredictionPoints = it.ConvertToInt("TeamAway.CurrentPredictionPoints"), WinningPredictionPoints = it.ConvertToInt("TeamAway.WinningPredictionPoints") }, TeamHome = new TeamInformation { Id = it.ConvertToInt("TeamHome.Id"), Name = it.GetString("TeamHome.Name"), CurrentScore = it.ConvertToInt("TeamHome.CurrentScore"), IsSelected = it.ConvertToBoolean("TeamHome.IsSelected"), CurrentPredictionPoints = it.ConvertToInt("TeamHome.CurrentPredictionPoints"), WinningPredictionPoints = it.ConvertToInt("TeamHome.WinningPredictionPoints") }, }).ToList(); return qry; }