Asp.net core RC1 to RC2 integration testing: where did UseServices go?

Warren P

Related but not the same as this RC1 to RC2 integration test question, I am trying to figure out what happened to UseServices

//RC1: 
// TestServer = new TestServer(TestServer
//                .CreateBuilder()
//                 .UseStartup<Startup>());
//RC2: 
// TestServer=new TestServer(new WebHostBuilder().UseEnvironment....)

var builder2 = new WebHostBuilder()
 .UseEnvironment("Development")
/* RC2 port:
.UseServices(services =>
{
                // Change the application environment to the mvc project
                var env = new                TestApplicationEnvironment();
    env.ApplicationBasePath = Path.GetFullPath(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "..", "..", "src", "RamSoft.Fhir.Api"));
    env.ApplicationName = "RamSoft Patient Api Service";

    services.AddInstance<IApplicationEnvironment>(env);
})
*/
.UseStartup<RamSoft.Fhir.Api.Startup>();
TestServer = new TestServer(builder2);
Client = TestServer.CreateClient();

The TestApplicationEnvironment in my sample above appears to be a minimal mock object, like this:

 public class TestApplicationEnvironment : IApplicationEnvironment
    {
        public string ApplicationBasePath { get; set; }

        public string ApplicationName { get; set; }

        public string ApplicationVersion => PlatformServices.Default.Application.ApplicationVersion;

        public string Configuration => PlatformServices.Default.Application.Configuration;

        public FrameworkName RuntimeFramework => PlatformServices.Default.Application.RuntimeFramework;

        public object GetData(string name)
        {
            return PlatformServices.Default.Application.GetData(name);
        }

        public void SetData(string name, object value)
        {
            PlatformServices.Default.Application.SetData(name, value);
        }
    }

There is no documentation (docs.asp.net has not been updated yet) on this. Does anyone know how to make this code compile? The missing code shown above commented out would have set up some application level environment settings and provided it as an Application Environment. So far it seems this is gone, and may be replaced by IHostingEnvironment, but how to provide the mocked IHostingEnvironment to an integration test is of course not clear, with the decoupled nature of things, this may be provided by some mixin that is not present on my project.json, and so I have no idea how to proceed.

It may be that this code is no longer necessary for the test to pass, and if I figure out the solution, I will answer this myself.

At runtime with the code above commented out, I get an error that indicates that something required for the code to continue is missing, probably an issue with dependency inversion container not being able to resolve IConfiguration:

System.Exception was unhandled by user code
  HResult=-2146233088
  Message=Could not resolve a service of type 'Microsoft.Extensions.Configuration.IConfiguration' for the parameter 'configuration' of method 'Configure' on type 'X.Y.Api.Startup'.
  Source=Microsoft.AspNetCore.Hosting
  StackTrace:
       at Microsoft.AspNetCore.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
       at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
       at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
       at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder)
       at X.Y.IntegrationTests.TestServerFixture..ctor() in D:\....IntegrationTests\TestServerFixture.cs:line 68
  InnerException...
vcsjones

I think you're looking for ConfigureServices:

.ConfigureServices(services => {
    //Make your `env`...
    services.AddSingleton(env);
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

asp.net core 1.0 mvc RC2 tagBuilder method with HtmlEncoder() worked in RC1 not working RC2

From Dev

Issues after migration of Asp.Net Core RC1 to RC2

From Dev

Integration tests broken after migrating to ASP.NET Core RC2

From Dev

Integration tests broken after migrating to ASP.NET Core RC2

From Dev

ASP.NET Core 1 RC2 - database schema

From Dev

asp net core 1 RC2 AccountController injection

From Dev

ASP.NET Core 1 RC2 - database schema

From Dev

Why I'm getting this incompatibilities issues migrating from .net core rc1 to rc2

From Dev

ASP.NET Core Social Login RC1

From Dev

ASP.NET core RC1 to 1.0.0 migration errors

From Dev

Where is Notifications in OpenIdConnectOptions in .NET Core 1.0.0 RC2?

From Dev

xunit does not compile with ASP.NET Core RC2

From Dev

ASP.NET Core RC2 Area not published

From Dev

ASP.NET Core RC2 Seed Database

From Dev

Using swagger in asp.net core RC2

From Dev

Cookies in ASP.NET Core rc2

From Dev

Publish rc2 asp.net core application to Azure

From Dev

Url rewriting in ASP.NET Core RC2

From Dev

ASP.NET Core RC2 Configure Custom AppSettings

From Dev

ASP.NET Core RC2 as linux deamon

From Dev

Url rewriting in ASP.NET Core RC2

From Dev

Is ASP.NET Core RC2 Released?

From Dev

.NET Core v1 release compatible with ASP.NET CORE RC1?

From Dev

Microsoft.AspNet.Session not available in ASP.NET core 1.0 rc1 update2

From Dev

ASP.NET Core 1 RC2 web application entry point

From Dev

asp.net core 1 rc2: Creating a view component

From Dev

cannot add reference to .net core Class library asp.net core rc2

From Dev

.NET Core RC2 in Service Fabric

From Dev

Claims on signin in .NET Core RC2

Related Related

HotTag

Archive