Repository: dotnet/aspnetcore
File: src/SignalR/server/SignalR/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs (C#)

Code before:
        {
            var connectionHandlerTask = await client.ConnectAsync(connectionHandler).DefaultTimeout();
            var res = await client.InvokeAsync(nameof(ServicesHub.SingleService)).DefaultTimeout();
            Assert.Equal("An unexpected error occurred invoking 'SingleService' on the server. InvalidOperationException: No service for type 'Microsoft.AspNetCore.SignalR.Tests.Service1' has been registered.", res.Error);
        }
    }

    [Fact]
    public async Task HubMethodCanInjectService()
    {
        var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
        {
            provider.AddSingleton<Service1>();
        });
        var connectionHandler = serviceProvider.GetService<HubConnectionHandler<ServicesHub>>();

        using (var client = new TestClient())
        {
            var connectionHandlerTask = await client.ConnectAsync(connectionHandler).DefaultTimeout();
            var res = await client.InvokeAsync(nameof(ServicesHub.SingleService)).DefaultTimeout();
            Assert.True(Assert.IsType<bool>(res.Result));
        }
    }
    
    [Fact]
    public async Task HubMethodCanInjectServiceWithNullParameter()
    {
        var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
        {
            provider.AddSingleton<Service1>();
        });
        var connectionHandler = serviceProvider.GetService<HubConnectionHandler<ServicesHub>>();

        using (var client = new TestClient())
        {
            var connectionHandlerTask = await client.ConnectAsync(connectionHandler).DefaultTimeout();
            var res = await client.InvokeAsync(nameof(ServicesHub.ServiceWithStringAttribute),(string)null ).DefaultTimeout();
            Assert.Equal(115L, res.Result);
        }
    }

    [Fact]
    public async Task HubMethodCanInjectMultipleServices()
    {
        var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
        {
            provider.AddSingleton<Service1>();
            provider.AddSingleton<Service2>();
            provider.AddSingleton<Service3>();
        });
        var connectionHandler = serviceProvider.GetService<HubConnectionHandler<ServicesHub>>();

Review comment (suggestion):
```suggestion
    // Regression test for https://github.com/dotnet/aspnetcore/issues/61491
    [Fact]
```

Code after:
        {
            var connectionHandlerTask = await client.ConnectAsync(connectionHandler).DefaultTimeout();
            var res = await client.InvokeAsync(nameof(ServicesHub.SingleService)).DefaultTimeout();
            Assert.Equal("An unexpected error occurred invoking 'SingleService' on the server. InvalidOperationException: No service for type 'Microsoft.AspNetCore.SignalR.Tests.Service1' has been registered.", res.Error);
        }
    }

    [Fact]
    public async Task HubMethodCanInjectService()
    {
        var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
        {
            provider.AddSingleton<Service1>();
        });
        var connectionHandler = serviceProvider.GetService<HubConnectionHandler<ServicesHub>>();

        using (var client = new TestClient())
        {
            var connectionHandlerTask = await client.ConnectAsync(connectionHandler).DefaultTimeout();
            var res = await client.InvokeAsync(nameof(ServicesHub.SingleService)).DefaultTimeout();
            Assert.True(Assert.IsType<bool>(res.Result));
        }
    }
    
    // Regression test for https://github.com/dotnet/aspnetcore/issues/61491
    [Fact]
    public async Task HubMethodCanInjectServiceWithNullParameter()
    {
        var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
        {
            provider.AddSingleton<Service1>();
        });
        var connectionHandler = serviceProvider.GetService<HubConnectionHandler<ServicesHub>>();

        using (var client = new TestClient())
        {
            var connectionHandlerTask = await client.ConnectAsync(connectionHandler).DefaultTimeout();
            var res = await client.InvokeAsync(nameof(ServicesHub.ServiceWithStringAttribute),(string)null ).DefaultTimeout();
            Assert.Equal(115L, res.Result);
        }
    }

    [Fact]
    public async Task HubMethodCanInjectMultipleServices()
    {
        var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
        {
            provider.AddSingleton<Service1>();
            provider.AddSingleton<Service2>();
            provider.AddSingleton<Service3>();
        });