Example #1
0
 public RequestProcessor(
     ILogger <RequestProcessor> logger,
     ISimpleServiceCaller simpleServiceCaller)
 {
     _logger = logger;
     _simpleServiceCaller = simpleServiceCaller;
 }
        public SimpleServiceCallerIntegrationTests()
        {
            var context = new HostBuilderContext(new Dictionary <object, object>());

            context.Configuration =
                new ConfigurationBuilder()
                .AddInMemoryCollection(new Dictionary <string, string> {
                ["SERVICE_URI_PACKAGE"] = PackageUri
            })
                .AddEnvironmentVariables()
                .Build();
            context.HostingEnvironment =
                Mock.Of <Microsoft.Extensions.Hosting.IHostEnvironment>(e => e.EnvironmentName == "Test");

            var serviceCollection = new ServiceCollection();

            ServiceStartup.ConfigureServices(context, serviceCollection);
            serviceCollection.AddLogging(builder => builder.AddDebug());

            _testServer =
                new TestServer(
                    new WebHostBuilder()
                    .UseTestServer()
                    .Configure(builder =>
            {
                builder.Run(ctx => _handleHttpRequest(ctx));
            })
                    .ConfigureServices(builder =>
            {
                builder.AddControllers();
            }));
            _testServer.AllowSynchronousIO = true;

            serviceCollection.Replace(
                ServiceDescriptor.Transient <HttpMessageHandlerBuilder, TestServerMessageHandlerBuilder>(
                    sp => new TestServerMessageHandlerBuilder(_testServer)));
            var serviceProvider = serviceCollection.BuildServiceProvider();

            _caller = serviceProvider.GetService <ISimpleServiceCaller>();
        }