Esempio n. 1
0
        public async Task CanGenerateAllProxies(string language, Type type, int index)
        {
            output.WriteLine($"{language}: {type.FullName}");

            var project     = context.GetProject(language);
            var compilation = await context.GetCompilationAsync(language, new CancellationTokenSource(AsyncTimeoutMilliseconds).Token).ConfigureAwait(false);

            var document = await new ProxyGenerator().GenerateProxyAsync(context.Workspace, project,
                                                                         new CancellationTokenSource(AsyncTimeoutMilliseconds).Token,
                                                                         compilation.GetTypeByMetadataName(type.FullName))
                           .ConfigureAwait(false);

            var syntax = await document.GetSyntaxRootAsync(new CancellationTokenSource(AsyncTimeoutMilliseconds).Token).ConfigureAwait(false);

            document = project.AddDocument("proxy." + (language == LanguageNames.CSharp ? "cs" : "vb"), syntax);

            await AssertCode.NoErrorsAsync(document);
        }
        public async Task WhenParameterNameMatchesMethodNameParameterIsRenamed()
        {
            var(workspace, project) = CreateWorkspaceAndProject(LanguageNames.VisualBasic);
            var compilation = await project.GetCompilationAsync(TimeoutToken(5));

            Assert.False(compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error),
                         string.Join(Environment.NewLine, compilation.GetDiagnostics().Select(d => d.GetMessage())));

            var document = await new ProxyGenerator().GenerateProxyAsync(workspace, project, TimeoutToken(5),
                                                                         new[]
            {
                compilation.GetTypeByMetadataName(typeof(ICodeGenerator).FullName),
                compilation.GetTypeByMetadataName(typeof(ICustomFormatter).FullName),
            });

            var syntax = await document.GetSyntaxRootAsync();

            document = project.AddDocument("proxy.vb", syntax, filePath: Path.GetTempFileName());

            await AssertCode.NoErrorsAsync(document);
        }