public void DefaultsTheEnvironmentNameToDevelopment()
        {
            var target = new DefaultHostingEnvironmentBuilder();
            var result = target.Build();

            Assert.AreEqual("Development", result.EnvironmentName);
        }
        public void SetsTheEnvironmentNameAsExpected()
        {
            var expected = "MyEnvironment";

            var target = new DefaultHostingEnvironmentBuilder();

            target.SetEnvironmentName(expected);

            var result = target.Build();

            Assert.AreEqual(expected, result.EnvironmentName);
        }
Пример #3
0
        /// <summary>
        /// Configures the environment.
        /// </summary>
        /// <param name="serviceCollection">The service collection to configure.</param>
        protected virtual void ConfigureHostingEnvironmentImpl(IServiceCollection serviceCollection)
        {
            var builder = new DefaultHostingEnvironmentBuilder();

            hostingEnvironmentConfigurationCallback?.Invoke(builder);

            var environment = builder.Build();

            if (environment == null)
            {
                throw new BuildException("The environment was not built.");
            }

            serviceCollection.Add(new ServiceDescriptor(typeof(IHostingEnvironment), environment));
        }
        public void UsesTheEnvironmentNameVariableIfNotConfigured()
        {
            var expected = "MyEnvironmentVariable2";

            try
            {
                Environment.SetEnvironmentVariable(DefaultHostingEnvironmentBuilder.EnvironmentNameVariable, expected);

                var target = new DefaultHostingEnvironmentBuilder();
                var result = target.Build();

                Assert.AreEqual(expected, result.EnvironmentName);
            }
            finally
            {
                Environment.SetEnvironmentVariable(DefaultHostingEnvironmentBuilder.EnvironmentNameVariable, null);
            }
        }
        public void ThrowsAnExceptionWhenTheEnvironmentNameIsNull()
        {
            var target = new DefaultHostingEnvironmentBuilder();

            Assert.Throws <ArgumentNullException>(() => target.SetEnvironmentName(null));
        }