private static SwaggerServiceDiscoveryProvider CreateProvider(Service service = null)
        {
            IServiceDiscoveryProviderFactory     serviceDiscovery     = Substitute.For <IServiceDiscoveryProviderFactory>();
            IServiceProviderConfigurationCreator configurationCreator = Substitute.For <IServiceProviderConfigurationCreator>();
            IOptionsMonitor <FileConfiguration>  options  = Substitute.For <IOptionsMonitor <FileConfiguration> >();
            IHttpContextAccessor      httpContextAccessor = Substitute.For <IHttpContextAccessor>();
            IOptions <SwaggerOptions> swaggerOptions      = Substitute.For <IOptions <SwaggerOptions> >();

            options.CurrentValue.Returns(new FileConfiguration());

            IServiceDiscoveryProvider serviceProvider = Substitute.For <IServiceDiscoveryProvider>();

            serviceProvider.Get().Returns(new List <Service>()
            {
                service
            });
            var response = new OkResponse <IServiceDiscoveryProvider>(serviceProvider);

            serviceDiscovery.Get(Arg.Any <ServiceProviderConfiguration>(), Arg.Any <DownstreamRoute>()).Returns(response);

            var provider = new SwaggerServiceDiscoveryProvider(
                serviceDiscovery, configurationCreator, options, httpContextAccessor, swaggerOptions);

            return(provider);
        }
        public async Task ReturnUriFromUrlDefinition()
        {
            SwaggerServiceDiscoveryProvider provider = CreateProvider();

            Uri uri = await provider.GetSwaggerUriAsync(
                new SwaggerEndPointConfig()
            {
                Url = "http://localhost:5000/swagger"
            },
                new Configuration.ReRouteOptions());

            uri.AbsoluteUri.Should().Be("http://localhost:5000/swagger");
        }
        public async Task ReturnUriFromServiceDiscoveryWhenRouteDoesntExist()
        {
            SwaggerServiceDiscoveryProvider provider = CreateProvider(CreateService("Projects", "localhost", 5000));

            Uri uri = await provider.GetSwaggerUriAsync(
                new SwaggerEndPointConfig()
            {
                Service = new SwaggerService()
                {
                    Name = "Projects", Path = "/swagger/v1/json"
                }
            }, null);

            uri.AbsoluteUri.Should().Be("http://localhost:5000/swagger/v1/json");
        }
        public async Task UseCorrectSchemeByPort(int port, string expectedScheme)
        {
            SwaggerServiceDiscoveryProvider provider = CreateProvider(CreateService("Projects", "localhost", port, null));

            Uri uri = await provider.GetSwaggerUriAsync(
                new SwaggerEndPointConfig()
            {
                Service = new SwaggerService()
                {
                    Name = "Projects", Path = "/swagger/v1/json"
                }
            },
                new Configuration.ReRouteOptions());

            uri.Scheme.Should().Be(expectedScheme);
        }