Esempio n. 1
0
        public void LookUp_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            this.mockDataSource.Setup((ctx) => ctx.GetHeaders()).Returns(new string[] { "col1", "col2" });

            DataCell cell1 = new DataCell(new Column()
            {
                Name = "col1"
            }, "", "val1");
            DataCell cell2 = new DataCell(new Column()
            {
                Name = "col2"
            }, "", "val2");

            DataCell cell3 = new DataCell(new Column()
            {
                Name = "col1"
            }, "", "val3");
            DataCell cell4 = new DataCell(new Column()
            {
                Name = "col2"
            }, "", "val4");

            DataCellCollection row1 = new DataCellCollection
            {
                Cells = new List <DataCell> {
                    cell1, cell2
                }
            };
            DataCellCollection row2 = new DataCellCollection
            {
                Cells = new List <DataCell> {
                    cell3, cell4
                }
            };
            List <DataCellCollection> rows = new List <DataCellCollection>()
            {
                row1, row2
            };

            this.mockDataSource.Setup((ctx) => ctx.GetDataRowEntries()).Returns(rows);

            DataLookUpCollection dataLookUpCollection = this.CreateDataLookUpCollection();
            string keyColumn   = "col1";
            string valueColumn = "col2";
            string key         = "val1";

            // Act
            string result = dataLookUpCollection.LookUp(
                keyColumn,
                valueColumn,
                key);

            // Assert
            Assert.IsTrue(result == "val2");
        }
Esempio n. 2
0
        public bool InitializePrepocessing()
        {
            try
            {
                string sourceDataFolder = string.IsNullOrEmpty(this._runtimeSettings.SourceDataFolder) ? Directory.GetCurrentDirectory() : this._runtimeSettings.SourceDataFolder;

                string[] sources = this._diskIOHandler.DirectoryGetFiles(Path.GetDirectoryName(sourceDataFolder), this._runtimeSettings.LookUpFilePattern, SearchOption.AllDirectories);
                foreach (string item in sources)
                {
                    using (IDataSource dataSource = this._dataSourceFactory.GetDataSource(item))
                    {
                        IDataLookUpCollection lookUpCollection = new DataLookUpCollection(dataSource, this._logger);
                        string key = Path.GetFileName(item);
                        this._toSinkDataChainBuilder.LookUps.Add(key, new HashSet <string>(dataSource.GetHeaders()));
                        this._dataMapHandler.AddNewDataLookUp(key, lookUpCollection);
                    }
                }
                foreach (IDataMapper item in this._dataMapHandler.GetAllMappers())
                {
                    this._toSinkDataChainBuilder.LookUps.Add(item.Name, item.GetAssociatedColumns());
                }
                using (IDataSource dataSource = this._dataSourceFactory.GetDataSource(this._runtimeSettings.DataSourceFileName))
                {
                    this._toSinkDataChainBuilder.AddSourceColumns(dataSource.GetHeaders());
                }
                using (IDataSink dataSink = this._dataSinkFactory.GetDataSink(this._runtimeSettings.DataSinkFileName, this._runtimeSettings.OutConfigFileName))
                {
                    this._toSinkDataChainBuilder.AddSinkColumns(dataSink.Columns);
                }
                Dictionary <string, List <string> > mappingRules = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(this._diskIOHandler.FileReadAllText(this._runtimeSettings.MappingRulesSourcePath));
                foreach (KeyValuePair <string, List <string> > item in mappingRules)
                {
                    this._dataMapHandler.AddNewMappingRule(item.Key, item.Value);
                }

                this._toSinkDataChainBuilder.BuildChain();
                return(true);
            }
            catch (Exception ex)
            {
                this._logger.Log("Initialization Failed : see logs for mor information", EventLevel.Error, ex);
            }
            return(false);
        }