コード例 #1
0
        public void ShouldObfuscateDoesNotThrowExceptionForNullPropertyName(string propertyName)
        {
            var service = new ObfuscationService();

            bool result = service.ShouldObfuscate("key", "value", propertyName);

            Assert.IsFalse(result);
        }
コード例 #2
0
        public void ShouldObfuscateReturnsFalseForNullKey(string key)
        {
            var service = new ObfuscationService();

            bool result = service.ShouldObfuscate(key, "value", "propertyName");

            Assert.IsFalse(result);
        }
コード例 #3
0
        public void RegexPatternIsEvaluated(string pattern, string key, bool expectedResult)
        {
            var service = new ObfuscationService(new List <string> {
                pattern
            });

            bool result = service.ShouldObfuscate(key, null, "propertyName");

            Assert.AreEqual(expectedResult, result);
        }
コード例 #4
0
        public void NullPatternValueDoesNotThrowException(string pattern)
        {
            List <string> patterns = new List <string> {
                pattern
            };

            var service = new ObfuscationService(patterns);

            service.ShouldObfuscate("key", "value", "propertyName");
        }
コード例 #5
0
        public void ConstructorUpdatesThePatterns()
        {
            List <string> patterns = new List <string> {
                "pattern1", "pattern2", "pattern3"
            };

            var service = new ObfuscationService(patterns);

            Assert.AreEqual(JsonSerializer.Serialize(patterns), JsonSerializer.Serialize(service.GetPatterns()));
        }
コード例 #6
0
ファイル: ObfuscatorTests.cs プロジェクト: uwrit/leaf
        public void Under_Threshold_Not_Shifted()
        {
            var orig       = 5;
            var obfuscator = new ObfuscationService();
            var opts       = new DeidentificationOptions {
                Cohort = new DeidentificationOptions.CohortObfuscationOptions {
                    Enabled = true, LowCellSizeMasking = new DeidentificationOptions.CohortObfuscationOptions.LowCellSizeMaskingOptions {
                        Enabled = true, Threshold = 10
                    }
                }
            };
            var count = new PatientCount {
                Value = orig
            };
            var ctx = MockPanel.Context();

            obfuscator.Obfuscate(ref count, ctx, opts);

            Assert.NotEqual(orig, count.Value);
            Assert.Equal(count.Value, opts.Cohort.LowCellSizeMasking.Threshold);
            Assert.True(count.WithinLowCellThreshold);
        }
コード例 #7
0
ファイル: ObfuscatorTests.cs プロジェクト: uwrit/leaf
        public void Original_Value_Changed()
        {
            var orig       = 50;
            var obfuscator = new ObfuscationService();
            var opts       = new DeidentificationOptions {
                Cohort = new DeidentificationOptions.CohortObfuscationOptions {
                    Enabled = true, Noise = new DeidentificationOptions.CohortObfuscationOptions.NoiseOptions {
                        Enabled = true, LowerBound = -10, UpperBound = 10
                    }
                }
            };
            var count = new PatientCount {
                Value = orig
            };
            var ctx = MockPanel.Context();

            obfuscator.Obfuscate(ref count, ctx, opts);

            Assert.NotEqual(orig, count.Value);
            Assert.Equal(count.PlusMinus, Math.Max(opts.Cohort.Noise.LowerBound, opts.Cohort.Noise.UpperBound));
            Assert.False(count.WithinLowCellThreshold);
        }
コード例 #8
0
ファイル: ObfuscatorTests.cs プロジェクト: uwrit/leaf
        public void Same_Logic_Different_Structure_Produces_Same_Shift()
        {
            var g1         = Guid.NewGuid();
            var g2         = Guid.NewGuid();
            var g3         = Guid.NewGuid();
            var orig       = 50;
            var obfuscator = new ObfuscationService();
            var opts       = new DeidentificationOptions {
                Cohort = new DeidentificationOptions.CohortObfuscationOptions {
                    Enabled = true, Noise = new DeidentificationOptions.CohortObfuscationOptions.NoiseOptions {
                        Enabled = true, LowerBound = -10, UpperBound = 10
                    }
                }
            };

            var count1 = new PatientCount {
                Value = orig
            };
            var count2 = new PatientCount {
                Value = orig
            };
            var count3 = new PatientCount {
                Value = orig
            };
            var count4 = new PatientCount {
                Value = orig
            };

            var ctx1 = MockPanel.Context();
            var ctx2 = MockPanel.Context();
            var ctx3 = MockPanel.Context();
            var ctx4 = MockPanel.Context();

            // Set context one with two panels, the first with two concepts, second with one.
            ctx1.Allowed.ElementAt(0).SubPanels.ElementAt(0).PanelItems = new List <PanelItem> {
                new PanelItem {
                    Concept = new Concept {
                        Id = g1
                    }
                }, new PanelItem {
                    Concept = new Concept {
                        Id = g2
                    }
                }
            };
            ctx1.Allowed.Append(new Panel {
                SubPanels = new List <SubPanel> {
                    new SubPanel {
                        PanelItems = new List <PanelItem> {
                            new PanelItem {
                                Concept = new Concept {
                                    Id = g3
                                }
                            }
                        }
                    }
                }
            });

            // Set context two to same as one, but with panel one concept order flipped.
            ctx2.Allowed.ElementAt(0).SubPanels.ElementAt(0).PanelItems = new List <PanelItem> {
                new PanelItem {
                    Concept = new Concept {
                        Id = g2
                    }
                }, new PanelItem {
                    Concept = new Concept {
                        Id = g1
                    }
                }
            };
            ctx2.Allowed.Append(new Panel {
                SubPanels = new List <SubPanel> {
                    new SubPanel {
                        PanelItems = new List <PanelItem> {
                            new PanelItem {
                                Concept = new Concept {
                                    Id = g3
                                }
                            }
                        }
                    }
                }
            });

            // Set context three to same as one, but with panel order flipped.
            ctx3.Allowed.ElementAt(0).SubPanels.ElementAt(0).PanelItems = new List <PanelItem> {
                new PanelItem {
                    Concept = new Concept {
                        Id = g1
                    }
                }, new PanelItem {
                    Concept = new Concept {
                        Id = g2
                    }
                }
            };
            ctx3.Allowed.Prepend(new Panel {
                SubPanels = new List <SubPanel> {
                    new SubPanel {
                        PanelItems = new List <PanelItem> {
                            new PanelItem {
                                Concept = new Concept {
                                    Id = g3
                                }
                            }
                        }
                    }
                }
            });

            // Set context four to a combination of two and three, with both concept order and panel order flipped.
            ctx4.Allowed.ElementAt(0).SubPanels.ElementAt(0).PanelItems = new List <PanelItem> {
                new PanelItem {
                    Concept = new Concept {
                        Id = g2
                    }
                }, new PanelItem {
                    Concept = new Concept {
                        Id = g1
                    }
                }
            };
            ctx4.Allowed.Prepend(new Panel {
                SubPanels = new List <SubPanel> {
                    new SubPanel {
                        PanelItems = new List <PanelItem> {
                            new PanelItem {
                                Concept = new Concept {
                                    Id = g3
                                }
                            }
                        }
                    }
                }
            });

            obfuscator.Obfuscate(ref count1, ctx1, opts);
            obfuscator.Obfuscate(ref count2, ctx2, opts);
            obfuscator.Obfuscate(ref count3, ctx3, opts);
            obfuscator.Obfuscate(ref count4, ctx4, opts);

            Assert.NotEqual(orig, count1.Value);
            Assert.NotEqual(orig, count2.Value);
            Assert.NotEqual(orig, count3.Value);
            Assert.NotEqual(orig, count4.Value);
            Assert.False(count1.WithinLowCellThreshold);
            Assert.False(count2.WithinLowCellThreshold);
            Assert.False(count3.WithinLowCellThreshold);
            Assert.False(count4.WithinLowCellThreshold);
            Assert.Equal(count1.Value, count2.Value);
            Assert.Equal(count1.Value, count3.Value);
            Assert.Equal(count1.Value, count4.Value);
        }
コード例 #9
0
 public void ConstructorThrowsExceptionForNullArgument()
 {
     var service = new ObfuscationService(null);
 }
コード例 #10
0
        public void DefaultPatternsAreUsedIfNoPatternsAreProvided()
        {
            var service = new ObfuscationService();

            Assert.AreEqual(JsonSerializer.Serialize(ObfuscationService.DefaultPatterns), JsonSerializer.Serialize(service.GetPatterns()));
        }