Example #1
0
        public static TestServer Create(IServiceProvider provider, Action <IApplicationBuilder> app)
        {
            var appEnv = provider.GetRequiredService <IApplicationEnvironment>();

            var hostingEnv = new HostingEnvironment()
            {
                EnvironmentName = DefaultEnvironmentName,
                WebRoot         = HostingUtilities.GetWebRoot(appEnv.ApplicationBasePath),
            };

            var collection = new ServiceCollection();

            collection.Add(HostingServices.GetDefaultServices());
            collection.AddInstance <IHostingEnvironment>(hostingEnv);

            var appServices = collection.BuildServiceProvider(provider);

            var config = new Configuration();

            return(new TestServer(config, appServices, app));
        }
Example #2
0
        public void ReadWebRootFromProjectJson()
        {
            var root = HostingUtilities.GetWebRoot(".");

            Assert.True(root.EndsWith("testroot"));
        }