public IEnumerable <TestCase> GenerateTestCases( MethodPair methods, ParameterListPair parameters, UniqueIdentifier uniqueIdentifier) { var testCases = ImmutableList.CreateBuilder <TestCase>(); var asyncParameters = methods.AsyncMethod.GetParameters(); for (var i = 0; i < asyncParameters.Length; i++) { if (asyncParameters[i].ParameterType == typeof(CancellationToken)) { // Check if the type is annotated as nullable testCases.Add(new CanceledTestCase( methods.AsyncMethod, asyncParameters[i], new ParameterList(parameters.AsyncParameters.Parameters.SetItem( i, Parameter.Default(parameters.AsyncParameters.Parameters[i].Name !, async(writer, variableName) => { await writer.WriteLineAsync($" using var { variableName }Source = new CancellationTokenSource();").ConfigureAwait(false); await writer.WriteLineAsync($" var { variableName } = { variableName }Source.Token;").ConfigureAwait(false); await writer.WriteLineAsync($" { variableName }Source.Cancel();").ConfigureAwait(false); }))), _knownNamespaces, _optionsResolver, uniqueIdentifier)); } } return(testCases.ToImmutable()); }
public EquivalenceTestCase( MethodPair methods, ParameterListPair parameters, KnownNamespaces knownNamespaces, OptionsResolver optionsResolver, UniqueIdentifier uniqueIdentifier) { _methods = methods; _parameters = parameters; _uniqueIdentifier = uniqueIdentifier; _knownNamespaces = knownNamespaces; _optionsResolver = optionsResolver; }
public IEnumerable <TestCase> GenerateTestCases( MethodPair methods, ParameterListPair parameters, UniqueIdentifier uniqueIdentifier) { // For now only build a single test case, later we can add variations to the parameters var testCase = new EquivalenceTestCase( methods, parameters, _knownNamespaces, _optionsResolver, uniqueIdentifier); return(new[] { testCase }); }
private static void AddMethodPairsToList(List <MethodPair> methodPairs, Type @interface, Type target) { var implementationMapping = target.GetInterfaceMap(@interface); var array = new MethodPair[implementationMapping.InterfaceMethods.Length]; for (int i = 0; i < implementationMapping.InterfaceMethods.Length; i++) { array[i] = new MethodPair(implementationMapping.InterfaceMethods[i], implementationMapping.TargetMethods[i]); } methodPairs.AddRange(array); foreach (Type subInterface in @interface.GetInterfaces()) { AddMethodPairsToList(methodPairs, subInterface, target); } }
public object Call(string method, params object[] parameters) { // Verify the existence of the method: if (!_methods.ContainsKey(method)) { throw new Exception(string.Format("Method {0} does not exist.", method)); } // Get the MethodPair index: Type[] types = new Type[parameters.Length]; for (int index = 0; index < parameters.Length; index++) { types[index] = parameters[index].GetType(); } MethodPair mp = new MethodPair(method, types); // Invoke the method: object instance = _bases[_methods[method]]; MethodInfo mi = (MethodInfo)_methodInfo[mp]; return(mi.Invoke(instance, parameters)); }
public IEnumerable <TestCase> GenerateTestCases( MethodPair methods, ParameterListPair parameters, UniqueIdentifier uniqueIdentifier) { var testCases = ImmutableList.CreateBuilder <TestCase>(); var asyncParameters = methods.AsyncMethod.GetParameters(); // Validate throws if parameter is null test cases for (var i = 0; i < asyncParameters.Length; i++) { if (!asyncParameters[i].ParameterType.IsValueType) { // Check if the type is annotated as nullable var contextualParameter = asyncParameters[i].ToContextualParameter(); if (contextualParameter.Nullability == Nullability.NotNullable) { var parameterType = asyncParameters[i].ParameterType; testCases.Add(new NullParameterTestCase( methods.AsyncMethod, asyncParameters[i], new ParameterList(parameters.AsyncParameters.Parameters.SetItem( i, Parameter.Default(parameters.AsyncParameters.Parameters[i].Name, async(writer, variableName) => { await writer.WriteLineAsync($" { TypeHelper.FormatCSharpTypeName(parameterType, _knownNamespaces.Namespaces) } { variableName } = null!;").ConfigureAwait(false); }))), _knownNamespaces, _optionsResolver, uniqueIdentifier)); } } } return(testCases.ToImmutable()); }