public void MapPathThrowsWithNoWwwroot()
        {
            var env = new HostingEnvironment();

            env.Initialize(".", new WebApplicationOptions(), null);

            Assert.Throws<InvalidOperationException>(() => env.MapPath("file.txt"));
        }
        public void OverridesEnvironmentFromConfig()
        {
            var env = new HostingEnvironment();
            env.EnvironmentName = "SomeName";

            env.Initialize(".", new WebApplicationOptions() { Environment = "NewName" }, null);

            Assert.Equal("NewName", env.EnvironmentName);
        }
        public void SetsConfiguration()
        {
            var config = new ConfigurationBuilder().Build();
            var env = new HostingEnvironment();

            env.Initialize(".", new WebApplicationOptions(), config);

            Assert.Same(config, env.Configuration);
        }
        public void DefaultsToNullFileProvider()
        {
            var env = new HostingEnvironment();

            env.Initialize(Path.Combine("testroot", "wwwroot"), new WebApplicationOptions(), null);

            Assert.Null(env.WebRootPath);
            Assert.IsAssignableFrom<NullFileProvider>(env.WebRootFileProvider);
        }
        public void DefaultsToWwwrootSubdir()
        {
            var env = new HostingEnvironment();

            env.Initialize("testroot", new WebApplicationOptions(), null);

            Assert.Equal(Path.GetFullPath(Path.Combine("testroot","wwwroot")), env.WebRootPath);
            Assert.IsAssignableFrom<PhysicalFileProvider>(env.WebRootFileProvider);
        }
        public void SetsFullPathToWwwroot()
        {
            var env = new HostingEnvironment();

            env.Initialize(".", new WebApplicationOptions() {WebRoot = "testroot"}, null);

            Assert.Equal(Path.GetFullPath("testroot"), env.WebRootPath);
            Assert.IsAssignableFrom<PhysicalFileProvider>(env.WebRootFileProvider);
        }