private static MethodFilter FilterFromMethod(MethodInfo methodInfo) { var match = FilterRegex.Match(methodInfo.Name); var filterMatch = match.Groups["filter"]; var selectorMatch = match.Groups["selector"]; var propertyMatch = match.Groups["property"]; var filterMap = new MethodFilter(); if (filterMatch.Success && !string.IsNullOrEmpty(filterMatch.Value)) { filterMap.Filter = (Filter)Enum.Parse(typeof(Filter), filterMatch.Value); } else { filterMap.Filter = Filter.FirstOrDefault; } if (selectorMatch.Success && !string.IsNullOrEmpty(selectorMatch.Value)) { filterMap.Selector = (Selector)Enum.Parse(typeof(Selector), selectorMatch.Value); } else { filterMap.Selector = Selector.By; } if (propertyMatch.Success) { //TODO implement property match } return(filterMap); }
private static bool CanApply(IMethodSymbol symbol, MethodFilter filter, Dictionary <string, List <MethodFilter> > rules) { if (filter.All) { return(true); } if (!CanApply(symbol, filter)) { return(false); } if (filter.ReturnsVoid.HasValue && filter.ReturnsVoid.Value != symbol.ReturnsVoid) { return(false); } if (!string.IsNullOrEmpty(filter.Rule)) { if (!rules.TryGetValue(filter.Rule, out var rule)) { throw new InvalidOperationException($"Method rule {filter.Rule} do not exist"); } if (!rule.Any(o => CanApply(symbol, o, rules))) { return(false); } } return(true); }
private string BuildExceptionMessage() { StringBuilder sb = new StringBuilder() .Append("No matching method found in the type ") .Append(_targetType) .Append(" for signature ") .Append(_returnType).Append(" ") .Append(_methodName).Append("("); if (_parameterTypes.Length > 0) { foreach (Type parameter in _parameterTypes) { sb.Append(parameter).Append(", "); } sb.Length -= 2; } sb.Append(") with binding flags: ").Append(_bindingAttr); if (MethodFilter != null) { sb.Append(" with filter ").Append(MethodFilterMessage ?? MethodFilter.ToString()); } sb.Append("."); return(sb.ToString()); }
public Convention() { Classes = new ClassFilter().Where(type => !type.IsSubclassOf(typeof(Convention))); Cases = new MethodFilter().Where(m => !m.IsDispose()); CaseExecution = new CaseBehaviorBuilder(); InstanceExecution = new InstanceBehaviorBuilder(); ClassExecution = new TypeBehaviorBuilder().CreateInstancePerCase(); }
public DefaultConvention() { Classes .NameEndsWith("Tests"); Cases = new MethodFilter() .Where(method => method.Void() || method.Async()) .ZeroParameters(); }
public Convention() { Classes = new ClassFilter().Where(type => !type.IsSubclassOf(typeof(Convention))); Methods = new MethodFilter().Where(m => !m.IsDispose()); CaseExecution = new CaseBehaviorBuilder(); InstanceExecution = new InstanceBehaviorBuilder(); ClassExecution = new TypeBehaviorBuilder().CreateInstancePerCase(); methodCallParameterBuilder = method => new object[][] { }; }
public SelfTestConvention() { Classes .Where(testClass => testClass.IsNestedPrivate) .NameEndsWith("TestClass"); Cases = new MethodFilter() .Where(method => method.Void() || method.Async()) .ZeroParameters(); }
public CustomConvention() { //In this example, the description of test classes is so inclusive that this convention //class itself could be mistaken for a test class. Since convention classes are //automatically excluded, though, ShouldNotBeCalled() will not be called. Classes .Where(type => type.IsInNamespace(GetType().Namespace)); Cases = new MethodFilter() .Where(method => method.Void()) .ZeroParameters(); }
public CustomConvention() { container = InitContainerForIntegrationTests(); Classes .Where(type => type.IsInNamespace(GetType().Namespace)) .NameEndsWith("Tests"); Cases = new MethodFilter() .Where(method => method.Void()) .ZeroParameters(); ClassExecution .CreateInstancePerTestClass(UsingContainer); }
public CustomConvention() { Classes .Where(x => factMethods.Filter(x).Any()); Cases = new MethodFilter() .HasOrInherits <FactAttribute>(); ClassExecution .CreateInstancePerCase() .SetUpTearDown(PrepareFixtureData, DisposeFixtureData); InstanceExecution .SetUpTearDown(InjectFixtureData, fixture => { }); }
public CustomConvention() { Classes .Where(x => factMethods.Filter(x).Any()); Cases = new MethodFilter() .HasOrInherits<FactAttribute>(); ClassExecution .CreateInstancePerCase() .SetUpTearDown(PrepareFixtureData, DisposeFixtureData); InstanceExecution .SetUpTearDown(InjectFixtureData, fixture => { }); }
public CustomConvention() { Classes .HasOrInherits <TestFixtureAttribute>(); Cases = new MethodFilter() .HasOrInherits <TestAttribute>(); ClassExecution .CreateInstancePerTestClass(); InstanceExecution .SetUpTearDown <TestFixtureSetUpAttribute, TestFixtureTearDownAttribute>(); CaseExecution .SetUpTearDown <SetUpAttribute, TearDownAttribute>(); }
private string BuildExceptionMessage() { StringBuilder sb = new StringBuilder() .Append("No matching method found in the type ") .Append(_targetType) .Append(" for signature ") .Append(_returnType).Append(" ") .Append(_methodName).Append("("); sb.AppendArrayCommaSeparated(_parameterTypes); sb.Append(") with binding flags: ").Append(_bindingAttr); if (MethodFilter != null) { sb.Append(" with filter ").Append(MethodFilterMessage ?? MethodFilter.ToString()); } sb.Append("."); return(sb.ToString()); }
public CustomConvention(RunContext runContext) { Classes .Where(type => type.IsInNamespace(GetType().Namespace)) .NameEndsWith("Tests"); Cases = new MethodFilter() .Where(method => method.Void()) .ZeroParameters() .Where(method => { var isMarkedExplicit = method.Has <ExplicitAttribute>(); return(!isMarkedExplicit || runContext.TargetMember == method); }); ClassExecution .CreateInstancePerTestClass(); }
public CustomConvention(RunContext runContext) { Classes .Where(type => type.IsInNamespace(GetType().Namespace)) .NameEndsWith("Tests"); Cases = new MethodFilter() .Where(method => method.Void()) .ZeroParameters() .Where(method => { var isMarkedExplicit = method.Has<ExplicitAttribute>(); return !isMarkedExplicit || runContext.TargetMember == method; }); ClassExecution .CreateInstancePerTestClass(); }
public CustomConvention() { Classes .Where(type => type.IsInNamespace(GetType().Namespace)) .NameEndsWith("Tests"); Cases = new MethodFilter() .Where(method => method.Void()) .Where(method => LifecycleMethods.All(x => x != method.Name)) .ZeroParameters(); ClassExecution .CreateInstancePerTestClass(); InstanceExecution .SetUpTearDown("FixtureSetUp", "FixtureTearDown"); CaseExecution .SetUpTearDown("SetUp", "TearDown"); }
static void TryInvoke(string method, Type type, object instance) { var lifecycleMethod = new MethodFilter() .Where(x => x.HasSignature(typeof(void), method)) .Filter(type) .SingleOrDefault(); if (lifecycleMethod == null) return; try { lifecycleMethod.Invoke(instance, null); } catch (TargetInvocationException exception) { throw new PreservedException(exception.InnerException); } }
public CustomConvention(RunContext runContext) { var desiredCategories = runContext.Options["include"].ToArray(); var shouldRunAll = !desiredCategories.Any(); Classes .Where(type => type.IsInNamespace(GetType().Namespace)) .NameEndsWith("Tests"); Cases = new MethodFilter() .Where(method => method.Void()) .ZeroParameters() .Where(method => shouldRunAll || MethodHasAnyDesiredCategory(method, desiredCategories)); if (!shouldRunAll) { Console.WriteLine("Categories: " + string.Join(", ", desiredCategories)); Console.WriteLine(); } }
private static bool CanApply(IMethodSymbol symbol, MethodFilter filter, Dictionary <string, List <MethodFilter> > rules) { if (filter.All) { return(true); } if (!CanApply(symbol, filter)) { return(false); } if (filter.ReturnsVoid.HasValue && filter.ReturnsVoid.Value != symbol.ReturnsVoid) { return(false); } if (!string.IsNullOrEmpty(filter.Rule) && !rules[filter.Rule].Any(o => CanApply(symbol, o, rules))) { return(false); } return(true); }
static void TryInvoke(string method, Type type, object instance) { var lifecycleMethod = new MethodFilter() .Where(x => x.HasSignature(typeof(void), method)) .Filter(type) .SingleOrDefault(); if (lifecycleMethod == null) { return; } try { lifecycleMethod.Invoke(instance, null); } catch (TargetInvocationException exception) { throw new PreservedException(exception.InnerException); } }
public void AddFilter(MethodFilter <Method> filter) { this.filters.Add(filter); }
public void AddFilter(MethodFilter <Method> filter) { this.underlying.AddFilter(filter); }