Exemplo n.º 1
0
        public void MaskDataRowEnumerableAsync()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("A");
            var r = dt.NewRow();

            r["A"] = "pfdsa";
            dt.Rows.Add(r);
            //so now we got a databable with one row and column.
            DataMasker dm = new DataMasker(new MockStrategy());

            dm.MaskDataRowEnumerableAsync(dt.AsEnumerable(), "A").Wait();
            //make sure it didn't mess with my dt
            Assert.IsNotNull(dt);
            Assert.AreEqual(expected: "pfdsa", actual: dt.Rows[0]["A"]);
        }
Exemplo n.º 2
0
        private async Task ApplyMask(Dictionary <string, Tuple <MaskingOptions, string> > maskingInformation, IEnumerable <DataRow> dataRows)
        {
            Console.Out.WriteLine("Combining multiple strategies into one...");
            List <IMaskingStrategy> strats = new List <IMaskingStrategy>();

            foreach (var item in maskingInformation)
            {
                string         colName  = item.Key;
                MaskingOptions option   = item.Value.Item1;
                string         method   = item.Value.Item2;
                var            strategy = MaskingStrategyFactory.CreateStrategyFromMaskingOption(option, method);
                strategy.Initialize(dataRows.First().Table, colName); //'must call this here for aggregatre strategies
                Console.Out.WriteLine($"Applying datamask of type {option} to column {colName}");
                strats.Add(strategy);
            }
            IMaskingStrategy CombinedStrategy = MaskingStrategyFactory.CombineStrategiesIntoSingleStrategy(strats);
            DataMasker       masker           = new DataMasker(CombinedStrategy);
            await masker.MaskDataRowEnumerableAsync(dataRows, "allcols");

            Console.Out.WriteLine("Strategies executed.");
        }