public void testComputeComplement_allAndNothing() { var map1 = new Dictionary <string, SortedSet <string> > { { "fixedLine", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "mobile", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "tollFree", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "premiumRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "sharedCost", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "personalNumber", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "voip", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "pager", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "uan", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "emergency", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "voicemail", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "shortCode", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "standardRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "carrierSpecific", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "smsServices", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "noInternationalDialling", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "preferredInternationalPrefix", new SortedSet <string>() }, { "nationalPrefix", new SortedSet <string>() }, { "preferredExtnPrefix", new SortedSet <string>() }, { "nationalPrefixTransformRule", new SortedSet <string>() }, { "sameMobileAndFixedLinePattern", new SortedSet <string>() }, { "mainCountryForCode", new SortedSet <string>() }, { "leadingZeroPossible", new SortedSet <string>() }, { "mobileNumberPortableRegion", new SortedSet <string>() } }; var map2 = new Dictionary <string, SortedSet <string> >(); Assert.Equal(MetadataFilter.ComputeComplement(map1), map2); Assert.Equal(MetadataFilter.ComputeComplement(map2), map1); }
public void TestShouldDrop() { var blacklist = new Dictionary <string, SortedSet <string> > { { "fixedLine", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "mobile", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "tollFree", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "premiumRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "emergency", new SortedSet <string> { "nationalNumberPattern" } }, { "voicemail", new SortedSet <string>(new List <string> { "possibleLength", "exampleNumber" }) }, { "shortCode", new SortedSet <string> { "exampleNumber" } }, { "standardRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "carrierSpecific", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "smsServices", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "noInternationalDialling", new SortedSet <string>(MetadataFilter.ExcludableChildFields) }, { "nationalPrefixTransformRule", new SortedSet <string>() }, { "sameMobileAndFixedLinePattern", new SortedSet <string>() }, { "mainCountryForCode", new SortedSet <string>() }, { "leadingZeroPossible", new SortedSet <string>() }, { "mobileNumberPortableRegion", new SortedSet <string>() } }; var filter = new MetadataFilter(blacklist); Assert.True(filter.ShouldDrop("fixedLine", "exampleNumber")); Assert.False(filter.ShouldDrop("sharedCost", "exampleNumber")); Assert.False(filter.ShouldDrop("emergency", "exampleNumber")); Assert.True(filter.ShouldDrop("emergency", "nationalNumberPattern")); Assert.False(filter.ShouldDrop("preferredInternationalPrefix")); Assert.True(filter.ShouldDrop("mobileNumberPortableRegion")); Assert.True(filter.ShouldDrop("smsServices", "nationalNumberPattern")); // Integration tests starting with flag values. Assert.True(BuildMetadataFromXml.GetMetadataFilter(true, false) .ShouldDrop("fixedLine", "exampleNumber")); // Integration tests starting with blacklist strings. Assert.True(new MetadataFilter(MetadataFilter.ParseFieldMapFromString("fixedLine")) .ShouldDrop("fixedLine", "exampleNumber")); Assert.False(new MetadataFilter(MetadataFilter.ParseFieldMapFromString("uan")) .ShouldDrop("fixedLine", "exampleNumber")); // Integration tests starting with whitelist strings. Assert.False(new MetadataFilter(MetadataFilter.ComputeComplement( MetadataFilter.ParseFieldMapFromString("exampleNumber"))) .ShouldDrop("fixedLine", "exampleNumber")); Assert.True(new MetadataFilter(MetadataFilter.ComputeComplement( MetadataFilter.ParseFieldMapFromString("uan"))).ShouldDrop("fixedLine", "exampleNumber")); // Integration tests with an empty blacklist. Assert.False(new MetadataFilter(new Dictionary <string, SortedSet <string> >()) .ShouldDrop("fixedLine", "exampleNumber")); }