Example #1
0
        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;
 }
Example #3
0
        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 });
        }
        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());
        }