public void CreateStrategyFromMaskingOptionTest()
        {
            var x = MaskingStrategyFactory.CreateStrategyFromMaskingOption(MaskingOptions.Replace, "rando value");

            Assert.IsNotNull(x);
            x = null;
            x = MaskingStrategyFactory.CreateStrategyFromMaskingOption(MaskingOptions.Replace);
            Assert.IsNotNull(x);

            //not implemented yet, change these tests when relevant code paths are implemented.
            Assert.ThrowsException <NotImplementedException>(
                () => MaskingStrategyFactory.CreateStrategyFromMaskingOption(MaskingOptions.Randomize));
            Assert.ThrowsException <NotImplementedException>(
                () => MaskingStrategyFactory.CreateStrategyFromMaskingOption(MaskingOptions.Generate));
        }
Example #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.");
        }