public Task <StepResult> Execute(GetUniqueRowsStepParameters parameters, CancellationToken cancel) { _parameters = parameters; var primaryDataset = _datasetPool.GetDataSet(parameters.PrimaryDatasetName); var uniqueRowsDataset = new DataTable(); foreach (DataColumn column in primaryDataset.Columns) { uniqueRowsDataset.Columns.Add(column.ColumnName); } foreach (DataRow row in primaryDataset.Rows) { var matchValues = parameters.ComparisonColumns .Select(c => new MatchValue { ColumnMapping = c, SourceValue = row[c.SourceColumnName].ToString(), }) .ToList(); if (!MatchInComparisonDataset(matchValues)) { uniqueRowsDataset.Rows.Add(row.ItemArray); } } _datasetPool.InsertOrReplace(_parameters.OutputDatasetName, uniqueRowsDataset); return(Task.FromResult(new StepResult())); }
public Task <StepResult> Execute(TransformDatasetStepParameters parameters, CancellationToken cancel) { var inputDataTable = _datasetPool.GetDataSet(parameters.InputDatasetName); var outputDataTable = new DataTable(); var outputColumnNames = parameters.ColumnMappings.Select(cm => cm.DestinationColumnName); outputDataTable.Columns.AddRange(outputColumnNames.Select(c => new DataColumn(c)).ToArray()); foreach (DataRow row in inputDataTable.Rows) { var outputRow = outputDataTable.NewRow(); foreach (var columnMapping in parameters.ColumnMappings) { var sourceValue = row[columnMapping.SourceColumnName].ToString(); outputRow[columnMapping.DestinationColumnName] = sourceValue ?? string.Empty; } outputDataTable.Rows.Add(outputRow); } _datasetPool.InsertOrReplace(parameters.OutputDatasetName, outputDataTable); return(Task.FromResult(new StepResult { OutputDatasetName = parameters.OutputDatasetName })); }
public Task <StepResult> Execute(FindAndReplaceStepParameters parameters, CancellationToken cancel) { var dataset = _datasetPool.GetDataSet(parameters.DatasetName); foreach (DataRow row in dataset.Rows) { foreach (var column in parameters.SearchColumns) { var cellValue = row[column].ToString(); if (string.IsNullOrWhiteSpace(cellValue)) { continue; } if (cellValue.Contains(parameters.SearchText, StringComparison.OrdinalIgnoreCase)) { row[column] = cellValue.Replace( parameters.SearchText, parameters.ReplaceText, StringComparison.OrdinalIgnoreCase); } } } return(Task.FromResult(new StepResult())); }
public async Task Execute_EmptyDataset_DatasetIsSameAfterExecution() { _datasetPool.InsertOrReplace(TestDatasetName, MockDataset1); _ = await _sut.Execute(new FindAndReplaceStepParameters { DatasetName = TestDatasetName, SearchText = "TestSearch", ReplaceText = "TestReplace", SearchColumns = new [] { "FirstName", "LastName", "Age" }, }, CancellationToken.None); var result = _datasetPool.GetDataSet(TestDatasetName); Assert.AreEqual(3, result.Columns.Count); Assert.AreEqual(0, result.Rows.Count); }
public async Task <StepResult> Execute(GenerateCsvStepParameters parameters, CancellationToken cancel) { var dataset = _datasetPool.GetDataSet(parameters.DatasetName); await _fileProvider.WriteToCsv(parameters.FileName, dataset); return(new StepResult { OutputDatasetName = parameters.DatasetName }); }
public async Task Execute_BothInputDatasetsEmpty_EmptyDatasetReturned(ColumnMatchType columnMatchType) { _datasetPool.InsertOrReplace(TestPrimaryDatasetName, MockDatatable1); _datasetPool.InsertOrReplace(TestComparisonDatasetName, MockDatatable2); _ = await _sut.Execute(new GetUniqueRowsStepParameters { PrimaryDatasetName = TestPrimaryDatasetName, ComparisonDatasetName = TestComparisonDatasetName, OutputDatasetName = TestOutputDatasetName, ComparisonColumns = new[] { new ColumnMapping("FirstName", "FirstName"), new ColumnMapping("LastName", "Surname"), new ColumnMapping("Email", "WorkEmail"), }, ColumnMatchType = columnMatchType, }, CancellationToken.None); var result = _datasetPool.GetDataSet(TestOutputDatasetName); Assert.IsNotNull(result); Assert.AreEqual(3, result.Columns.Count); Assert.AreEqual(0, result.Rows.Count); }
public async Task Execute_ExistingValidFile_FileLoadedToDatasetPool() { var result = await _sut.Execute(new LoadCsvStepParameters { FileName = TestFileName, OutputDatasetName = TestDatasetName }, CancellationToken.None); Assert.AreEqual(TestDatasetName, result.OutputDatasetName); var loadedDataset = _datasetPool.GetDataSet(TestDatasetName); Assert.AreEqual(1, loadedDataset.Rows.Count); Assert.AreEqual(MockFirstName, loadedDataset.Rows[0][TestColumn1]); Assert.AreEqual(MockLastName, loadedDataset.Rows[0][TestColumn2]); Assert.AreEqual(MockEmail, loadedDataset.Rows[0][TestColumn3]); }