private static IFilter BuildFilter(CommandLineParser parser) { var filter = new Filter(); // apply filters if (!parser.NoDefaultFilters) { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[mscorlib.*]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } if (parser.Filters.Count == 0) { filter.AddFilter("+[*]*"); } else { parser.Filters.ForEach(filter.AddFilter); } filter.AddAttributeExclusionFilters(parser.AttributeExclusionFilters.ToArray()); filter.AddFileExclusionFilters(parser.FileExclusionFilters.ToArray()); filter.AddTestFileFilters(parser.TestFilters.ToArray()); return filter; }
public void AddAttributeExclusionFilters_Handles_Null_Elements() { var filter = new Filter(false); filter.AddAttributeExclusionFilters(new[] { null, "" }); Assert.Equal(1, filter.ExcludedAttributes.Count); }
public void AddFilter_ThrowsException_WhenInvalid_AssemblyClassPair( [ValueSource("_invalidAssemblyClassPairs")]string assemblyClassPair) { // arrange var filter = new Filter(); // act/assert Assert.Catch<InvalidOperationException>(() => filter.AddFilter(assemblyClassPair), "'{0}' should be invalid", assemblyClassPair); }
public void AddFilter_Adds_ValidAssemblyClassPair( [ValueSource("_assemblyClassPairs")]AssemblyClassData assemblyClassPair) { // arrange var filter = new Filter(); // act filter.AddFilter(assemblyClassPair.AssemblyClass); // assert Assert.AreEqual(1, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ? filter.InclusionFilter.Count : filter.ExclusionFilter.Count); Assert.AreEqual(assemblyClassPair.AssemblyResult, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ? filter.InclusionFilter[0].Key : filter.ExclusionFilter[0].Key); Assert.AreEqual(assemblyClassPair.ClassResult, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ? filter.InclusionFilter[0].Value : filter.ExclusionFilter[0].Value); }
private static IFilter BuildFilter(CommandLineParser parser) { var filter = new Filter(); // apply filters if (!parser.NoDefaultFilters) { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[mscorlib.*]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } if (parser.Filters.Count == 0 && string.IsNullOrEmpty(parser.FilterFile)) { filter.AddFilter("+[*]*"); } else { if (!string.IsNullOrEmpty(parser.FilterFile)) { if (!File.Exists(parser.FilterFile)) System.Console.WriteLine("FilterFile '{0}' cannot be found - have you specified your arguments correctly?", parser.FilterFile); else { var filters = File.ReadAllLines(parser.FilterFile); filters.ToList().ForEach(filter.AddFilter); } } if (parser.Filters.Count > 0) { parser.Filters.ForEach(filter.AddFilter); } } filter.AddAttributeExclusionFilters(parser.AttributeExclusionFilters.ToArray()); filter.AddFileExclusionFilters(parser.FileExclusionFilters.ToArray()); filter.AddTestFileFilters(parser.TestFilters.ToArray()); return filter; }
private static Filter BuildFilter(CommandLineParser parser) { var filter = new Filter(); // apply filters if (!parser.NoDefaultFilters) { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } if (parser.Filters.Count == 0) { filter.AddFilter("+[*]*"); } else { parser.Filters.ForEach(filter.AddFilter); } return filter; }
public void AddTestFileFilters_HandlesNull() { var filter = new Filter(); filter.AddTestFileFilters(null); Assert.AreEqual(0, filter.TestFiles.Count); }
public void AddFileExclusionFilters_Handles_Null_Elements() { var filter = new Filter(); filter.AddFileExclusionFilters(new[] { null, "" }); Assert.AreEqual(1, filter.ExcludedFiles.Count); }
public void File_Is_Excluded_If_Matches_Filter_UsingRegularExpressions() { // arrange var filter = new Filter(true); filter.AddFileExclusionFilters(new[] { @"XXX\..*" }); // act, assert Assert.IsTrue(filter.ExcludeByFile("XXX.cs")); }
public void Can_Identify_Excluded_Properties() { var sourceAssembly = AssemblyDefinition.ReadAssembly(typeof(Samples.Concrete).Assembly.Location); var type = sourceAssembly.MainModule.Types.First(x => x.FullName == typeof(Samples.Concrete).FullName); var filter = new Filter(); filter.AddAttributeExclusionFilters(new[] { "*ExcludeMethodAttribute" }); foreach (var propertyDefinition in type.Properties) { Assert.True(filter.ExcludeByAttribute(propertyDefinition)); } }
public void File_Is_Excluded_If_Matches_Filter() { var filter = new Filter(); filter.AddFileExclusionFilters(new[] { "XXX.*" }); Assert.IsTrue(filter.ExcludeByFile("XXX.cs")); }
public void File_Is_Not_Excluded_If_No_File_Not_Supplied() { var filter = new Filter(); Assert.IsFalse(filter.ExcludeByFile("")); }
public void AddTestFileFilters_Escapes_Elements_And_Matches() { var filter = new Filter(); filter.AddTestFileFilters(new[] { ".*" }); Assert.IsTrue(filter.TestFiles[0].Value.Match(".ABC").Success); }
public void CanIdentify_AutoImplementedProperties() { // arrange var sourceAssembly = AssemblyDefinition.ReadAssembly(typeof(Samples.Concrete).Assembly.Location); var type = sourceAssembly.MainModule.Types.First(x => x.FullName == typeof(Samples.DeclaredMethodClass).FullName); // act/assert var filter = new Filter(); var wasTested = false; foreach (var methodDefinition in type.Methods .Where(x => x.IsGetter || x.IsSetter).Where(x => x.Name.EndsWith("AutoProperty"))) { wasTested = true; Assert.IsTrue(filter.IsAutoImplementedProperty(methodDefinition)); } Assert.IsTrue(wasTested); wasTested = false; foreach (var methodDefinition in type.Methods .Where(x => x.IsGetter || x.IsSetter).Where(x => x.Name.EndsWith("PropertyWithBackingField"))) { wasTested = true; Assert.IsFalse(filter.IsAutoImplementedProperty(methodDefinition)); } Assert.IsTrue(wasTested); }
public void Handles_Issue117() { var filter = new Filter(); filter.AddAttributeExclusionFilters(new[] { "*ExcludeMethodAttribute" }); var mockDefinition = new Mock<IMemberDefinition>(); mockDefinition.SetupGet(x => x.HasCustomAttributes).Returns(true); mockDefinition.SetupGet(x => x.CustomAttributes).Returns(new Collection<CustomAttribute>()); mockDefinition.SetupGet(x => x.Name).Returns("<>f_ddd"); mockDefinition.SetupGet(x => x.DeclaringType).Returns(new TypeDefinition("","f_ddd", TypeAttributes.Public)); Assert.DoesNotThrow(() => filter.ExcludeByAttribute(mockDefinition.Object)); }
public void Can_Identify_Included_Anonymous_Issue99() { var sourceAssembly = AssemblyDefinition.ReadAssembly(typeof(Samples.Anonymous).Assembly.Location); var type = sourceAssembly.MainModule.Types.First(x => x.FullName == typeof(Samples.Anonymous).FullName); var filter = new Filter(); filter.AddAttributeExclusionFilters(new[] { "*ExcludeMethodAttribute" }); foreach (var methodDefinition in type.Methods.Where(x => x.Name.Contains("INCLUDE"))) { if (methodDefinition.IsSetter || methodDefinition.IsGetter || methodDefinition.IsConstructor) continue; Assert.False(filter.ExcludeByAttribute(methodDefinition), "failed to include {0}", methodDefinition.Name); } }
public void Entity_Is_Not_Excluded_If_No_Filters_Set() { var filter = new Filter(); var entity = new Mock<IMemberDefinition>(); Assert.IsFalse(filter.ExcludeByAttribute(entity.Object)); }
/// <summary> /// Create a filter entity from parser parameters /// </summary> /// <param name="parser"></param> /// <returns></returns> public static IFilter BuildFilter(CommandLineParser parser) { var filter = new Filter(parser.RegExFilters); // apply filters if (!parser.NoDefaultFilters) { if (parser.RegExFilters) { filter.AddFilter(@"-[(mscorlib)](.*)"); filter.AddFilter(@"-[(mscorlib\..*)](.*)"); filter.AddFilter(@"-[(System)](.*)"); filter.AddFilter(@"-[(System\..*)](.*)"); filter.AddFilter(@"-[(Microsoft.VisualBasic)](.*)"); } else { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[mscorlib.*]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } } if (parser.Filters.Count > 0) { parser.Filters.ForEach(filter.AddFilter); } filter.AddAttributeExclusionFilters(parser.AttributeExclusionFilters.ToArray()); filter.AddFileExclusionFilters(parser.FileExclusionFilters.ToArray()); filter.AddTestFileFilters(parser.TestFilters.ToArray()); foreach (var excludeDir in parser.ExcludeDirs) { filter.AddExcludedFolder(excludeDir); } return filter; }
public void Can_Identify_Excluded_Methods_UsingRegularExpressions() { // arrange var filter = new Filter(true); filter.AddAttributeExclusionFilters(new[] { ".*ExcludeMethodAttribute" }); // act var sourceAssembly = AssemblyDefinition.ReadAssembly(typeof(Samples.Concrete).Assembly.Location); var type = sourceAssembly.MainModule.Types.First(x => x.FullName == typeof(Samples.Concrete).FullName); // assert foreach (var methodDefinition in type.Methods.Where(methodDefinition => !methodDefinition.IsSetter && !methodDefinition.IsGetter)) { Assert.True(filter.ExcludeByAttribute(methodDefinition)); } }
public void AssemblyIsIncludedForTestMethodGatheringWhenFilterMatches() { var filter = new Filter(); filter.AddTestFileFilters(new []{"A*"}); Assert.IsTrue(filter.UseTestAssembly("ABC.dll")); Assert.IsFalse(filter.UseTestAssembly("XYZ.dll")); }
public void AddTestFileFilters_Handles_Null_Elements() { var filter = new Filter(); filter.AddTestFileFilters(new[] { null, "" }); Assert.AreEqual(1, filter.TestFiles.Count); }
public void UseAssembly_Tests( [ValueSource("_useAssemblyData")]UseAssemblyData data) { // arrange var filter = new Filter(); data.Filters.ToList().ForEach(filter.AddFilter); // act var result = filter.UseAssembly(data.Assembly); // result Assert.AreEqual(data.ExpectedResult, result, "Filter: '{0}' Assembly: {1} => Expected: {2}", string.Join(",", data.Filters), data.Assembly, data.ExpectedResult); }
public void File_Is_Not_Excluded_If_No_Filters_Set() { var filter = new Filter(); Assert.IsFalse(filter.ExcludeByFile("xyz.cs")); }
public void InstrumentClass_Tests( [ValueSource("_instrumentClassData")]InstrumentClassData data) { //// arrange var filter = new Filter(); data.Filters.ToList().ForEach(filter.AddFilter); // act var result = filter.InstrumentClass(data.Assembly, data.Class); // result Assert.AreEqual(data.ExpectedResult, result, "Filter: '{0}' Assembly: {1} Class: {2} => Expected: {3}", string.Join(",", data.Filters), data.Assembly, data.Class, data.ExpectedResult); }
public void File_Is_Not_Excluded_If_Does_Not_Match_Filter() { var filter = new Filter(); filter.AddFileExclusionFilters(new[]{"XXX.*"}); Assert.IsFalse(filter.ExcludeByFile("YYY.cs")); }
public void Entity_Is_Not_Excluded_If_No_Filters_Set() { var filter = new Filter(); var entity = new Mock<ICustomAttributeProvider>(); Assert.IsFalse(filter.ExcludeByAttribute(entity.Object)); }
public void Can_Identify_Excluded_Methods() { var sourceAssembly = AssemblyDefinition.ReadAssembly(typeof(Samples.Concrete).Assembly.Location); var type = sourceAssembly.MainModule.Types.First(x => x.FullName == typeof (Samples.Concrete).FullName); var filter = new Filter(); filter.AddAttributeExclusionFilters(new[] { "*ExcludeMethodAttribute" }); foreach (var methodDefinition in type.Methods) { if (methodDefinition.IsSetter || methodDefinition.IsGetter) continue; Assert.True(filter.ExcludeByAttribute(methodDefinition)); } }
public void AddFileExclusionFilters_HandlesNull() { var filter = new Filter(); filter.AddFileExclusionFilters(null); Assert.AreEqual(0, filter.ExcludedFiles.Count); }
public void AddAttributeExclusionFilters_Escapes_Elements_And_Matches() { var filter = new Filter(); filter.AddAttributeExclusionFilters(new[] { ".*" }); Assert.IsTrue(filter.ExcludedAttributes[0].Value.Match(".ABC").Success); }
public void ModulesInExcludedFoldersAreIdentifiedCorrectly() { // arrange var filter = new Filter(true); filter.AddExcludedFolder("ABC"); // act Assert.IsFalse(filter.UseModule(@"ABC\m.dll")); Assert.IsTrue(filter.UseModule(@"DEF\m.dll")); }