Esempio n. 1
0
        public async Task DetectFeaturesAsync_FindsNoFeatures()
        {
            // Arrange
            var source      = @"
using Microsoft.AspNetCore.Builder;

namespace Microsoft.AspNetCore.Analyzers.TestFiles.CompilationFeatureDetectorTest
{
    public class StartupWithNoFeatures
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapFallbackToFile(""index.html"");
            });
        }
    }
}";
            var compilation = TestCompilation.Create(source);
            var symbols     = new StartupSymbols(compilation);

            var type = (INamedTypeSymbol)compilation.GetSymbolsWithName("StartupWithNoFeatures").Single();

            Assert.True(StartupFacts.IsStartupClass(symbols, type));

            // Act
            var features = await CompilationFeatureDetector.DetectFeaturesAsync(compilation);

            // Assert
            Assert.Empty(features);
        }
Esempio n. 2
0
        public async Task DetectFeaturesAsync_FindsSignalR(string source)
        {
            // Arrange
            var compilation = await CreateCompilationAsync(source);

            var symbols = new StartupSymbols(compilation);

            var type = (INamedTypeSymbol)compilation.GetSymbolsWithName(source).Single();

            Assert.True(StartupFacts.IsStartupClass(symbols, type));

            // Act
            var features = await CompilationFeatureDetector.DetectFeaturesAsync(compilation);

            // Assert
            Assert.Collection(features, f => Assert.Equal(WellKnownFeatures.SignalR, f));
        }
Esempio n. 3
0
        public async Task DetectFeaturesAsync_FindsNoFeatures()
        {
            // Arrange
            var compilation = await CreateCompilationAsync(nameof(StartupWithNoFeatures));

            var symbols = new StartupSymbols(compilation);

            var type = (INamedTypeSymbol)compilation.GetSymbolsWithName(nameof(StartupWithNoFeatures)).Single();

            Assert.True(StartupFacts.IsStartupClass(symbols, type));

            // Act
            var features = await CompilationFeatureDetector.DetectFeaturesAsync(compilation);

            // Assert
            Assert.Empty(features);
        }
Esempio n. 4
0
        public async Task DetectFeatureAsync_StartupWithMapHub_FindsSignalR()
        {
            var source      = @"
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.SignalR;

namespace Microsoft.AspNetCore.Analyzers.TestFiles.CompilationFeatureDetectorTest
{
    public class StartupWithMapHub
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<MyHub>("" / test"");
            });
        }
    }

    public class MyHub : Hub
    {
    }
}
";
            var compilation = TestCompilation.Create(source);
            var symbols     = new StartupSymbols(compilation);

            var type = (INamedTypeSymbol)compilation.GetSymbolsWithName("StartupWithMapHub").Single();

            Assert.True(StartupFacts.IsStartupClass(symbols, type));

            // Act
            var features = await CompilationFeatureDetector.DetectFeaturesAsync(compilation);

            // Assert
            Assert.Collection(features, f => Assert.Equal(WellKnownFeatures.SignalR, f));
        }