示例#1
0
    public async Task StartupAnalyzer_FindsStartupMethods_StartupSignatures_MoreVariety()
    {
        // Arrange
        var source = @"
using System.Text;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Analyzers.TestFiles.StartupAnalyzerTest
{
    public class StartupSignatures_MoreVariety
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }

        public void ConfigureServices(IServiceCollection services, StringBuilder s) // Ignored
        {
        }

        public void Configure(StringBuilder s) // Ignored,
        {
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
        }

        public void ConfigureProduction(IWebHostEnvironment env, IApplicationBuilder app)
        {
        }

        private void Configure(IApplicationBuilder app)  // Ignored
        {
        }
    }
}
";

        // Act
        await VerifyAnalyzerAsync(source, DiagnosticResult.EmptyDiagnosticResults);

        // Assert
        Assert.Collection(
            ConfigureServicesMethods.OrderBy(m => m.Name),
            m => Assert.Equal("ConfigureServices", m.Name));

        Assert.Collection(
            ConfigureMethods.OrderBy(m => m.Name),
            m => Assert.Equal("Configure", m.Name),
            m => Assert.Equal("ConfigureProduction", m.Name));
    }
        public async Task StartupAnalyzer_FindsStartupMethods_StartupSignatures_MoreVariety()
        {
            // Arrange
            var source = ReadSource("StartupSignatures_MoreVariety");

            // Act
            var diagnostics = await Runner.GetDiagnosticsAsync(source.Source);

            // Assert
            Assert.Empty(diagnostics);

            Assert.Collection(
                ConfigureServicesMethods.OrderBy(m => m.Name),
                m => Assert.Equal("ConfigureServices", m.Name));

            Assert.Collection(
                ConfigureMethods.OrderBy(m => m.Name),
                m => Assert.Equal("Configure", m.Name),
                m => Assert.Equal("ConfigureProduction", m.Name));
        }