コード例 #1
0
        public void Scrambling_ShufflesExistingValuesWithinGroups()
        {
            // ARRANGE
            var valueColumnIndex    = 0;
            var testGroupingColumn1 = AddGroupColumn_ToObfuscationOperation_AndDataSet("TestingGroup1");
            var testGroupingColumn2 = AddGroupColumn_ToObfuscationOperation_AndDataSet("TestingGroup2");
            var originalRows        = AddValues_AndGroup_ToDataSet();

            var fakeDataPersistence = A.Fake <IDataPersistence>();

            A.CallTo(() => fakeDataPersistence.GetTableData(_obfuscationOperation)).Returns(_dataSet);

            _obfuscationOperation.Origin.DataSourceType = DataSourceType.Scramble;

            // ACT
            var obfuscation = new Obfuscation {
                DataPersistence = fakeDataPersistence
            };

            obfuscation.RunOperations(new List <ObfuscationInfo> {
                _obfuscationOperation
            });

            // ASSERT
            var currentValues  = _dataSet.Tables[0].Rows.Cast <DataRow>().ToList();
            var distinctGroups = originalRows.Select(dr => new object[] { (int)dr[testGroupingColumn1.Index], (int)dr[testGroupingColumn2.Index] }).Distinct();

            foreach (var groupIndex in distinctGroups)
            {
                var originalValuesInGroup = originalRows.Where(dr => (int)dr[testGroupingColumn1.Index] == (int)groupIndex[0] && (int)dr[testGroupingColumn2.Index] == (int)groupIndex[1]).ToList();
                var currentValuesInGroup  = currentValues.Where(dr => ((string)dr[valueColumnIndex]).EndsWith($"-{(int)groupIndex[0]}-{(int)groupIndex[1]}")).Select(x => x.ItemArray).ToList();

                var allOk = true;
                if (originalValuesInGroup.Count() > 1)
                {
                    foreach (var originalValueRow in originalValuesInGroup)
                    {
                        var rowWithSameValueThanOriginal = currentValuesInGroup.FirstOrDefault(cv => cv[valueColumnIndex].Equals(originalValueRow[valueColumnIndex]));
                        var indexOnCurrentValues         = currentValuesInGroup.IndexOf(rowWithSameValueThanOriginal);

                        allOk  = indexOnCurrentValues >= 0;
                        allOk &= originalValuesInGroup.IndexOf(originalValueRow) != indexOnCurrentValues;

                        if (!allOk)
                        {
                            break;
                        }
                    }
                }

                Assert.AreEqual(originalValuesInGroup.Count(), currentValuesInGroup.Count());
                Assert.IsTrue(allOk, $"Original sequence: {string.Join(",", originalValuesInGroup.Select(ov => ov[valueColumnIndex]))}" +
                              $"  Scrambled sequence: {string.Join(",", currentValuesInGroup.Select(cv => cv[valueColumnIndex]))}");
            }
        }
コード例 #2
0
        internal void RunOperations()
        {
            var ofuscation = new Obfuscation {
                DataPersistence = new SqlDataPersistence()
            };

            ofuscation.StatusChanged += ReportProgressToConsole;
            IEnumerable <ObfuscationInfo> obfuscationOps = LoadOperations();

            ofuscation.RunOperations(obfuscationOps);
        }
コード例 #3
0
        private void BtnRunObfuscationOps_Click(object sender, EventArgs e)
        {
            var ofuscation = new Obfuscation
            {
                StatusChanged   = StatusInformationChanged,
                DataPersistence = new SqlDataPersistence(),
            };

            var obfuscationOps = GetObfuscationOps();

            ofuscation.RunOperations(obfuscationOps);
        }
コード例 #4
0
        public void DniObfuscation_ReplacesAllCurrentValues()
        {
            List <string> originalValues = AddValues_ToDataSet();

            var fakeDataPersistence = A.Fake <IDataPersistence>();

            A.CallTo(() => fakeDataPersistence.GetTableData(_obfuscationOperation)).Returns(_dataSet);

            var obfuscation = new Obfuscation {
                DataPersistence = fakeDataPersistence
            };

            obfuscation.RunOperations(new List <ObfuscationInfo> {
                _obfuscationOperation
            });

            var currentValues = _dataSet.Tables[0].Rows.Cast <DataRow>().Select(dr => dr[0].ToString());

            Assert.IsFalse(originalValues.All(ov => currentValues.Any(cv => cv == ov)));
        }
コード例 #5
0
        public void ScramblingCanBeGroupedByStringField()
        {
            // ARRANGE
            var testGroupingColumn  = AddStringGroupColumn_ToObfuscationOperation_AndDataSet("StringTestGroup");
            var originalRows        = AddValues_AndGroup_ToDataSet();
            var fakeDataPersistence = A.Fake <IDataPersistence>();

            A.CallTo(() => fakeDataPersistence.GetTableData(_obfuscationOperation)).Returns(_dataSet);
            _obfuscationOperation.Origin.DataSourceType = DataSourceType.Scramble;

            // ACT
            var obfuscation = new Obfuscation {
                DataPersistence = fakeDataPersistence
            };

            obfuscation.RunOperations(new List <ObfuscationInfo> {
                _obfuscationOperation
            });

            // ASSERT
            AssertScramblingForOneGroupColumn(testGroupingColumn, originalRows);
        }
コード例 #6
0
        public void Scrambling_ShufflesExistingValues()
        {
            List <string> originalValues = AddValues_ToDataSet();

            var fakeDataPersistence = A.Fake <IDataPersistence>();

            A.CallTo(() => fakeDataPersistence.GetTableData(_obfuscationOperation)).Returns(_dataSet);

            _obfuscationOperation.Origin.DataSourceType = DataSourceType.Scramble;

            var obfuscation = new Obfuscation {
                DataPersistence = fakeDataPersistence
            };

            obfuscation.RunOperations(new List <ObfuscationInfo> {
                _obfuscationOperation
            });

            var currentValues = _dataSet.Tables[0].Rows.Cast <DataRow>().Select(dr => dr[0].ToString()).ToList();

            Assert.IsTrue(originalValues.All(ov => currentValues.IndexOf(ov) >= 0 && (originalValues.IndexOf(ov) != currentValues.IndexOf(ov))));
        }