ConfigureEnvironment() public method

Configures an INancyEnvironment instance.
public ConfigureEnvironment ( Action configuration ) : INancyEnvironment
configuration Action The configuration to apply to the environment.
return INancyEnvironment
        public void Should_retrieve_default_configurations_from_default_configuration_providers(int numberOfDefaultConfigurationProviders)
        {
            // Given
            var providers = Enumerable
                .Range(1, numberOfDefaultConfigurationProviders)
                .Select(x => A.Fake<INancyDefaultConfigurationProvider>())
                .ToArray();

            var config = new DefaultNancyEnvironmentConfigurator(this.factory, providers);

            // When
            config.ConfigureEnvironment(env => { });

            // Then
            foreach (var provider in providers)
            {
                A.CallTo(() => provider.GetDefaultConfiguration()).MustHaveHappened(Repeated.Exactly.Once);
            }
        }
        public void Should_not_throw_exception_when_default_configuration_provider_returns_null()
        {
            // Given
            var provider = A.Fake<INancyDefaultConfigurationProvider>();
            A.CallTo(() => provider.GetDefaultConfiguration()).Returns(null);

            var config = new DefaultNancyEnvironmentConfigurator(this.factory, new[] { provider });

            // When, Then
            Assert.DoesNotThrow(() =>
            {
                config.ConfigureEnvironment(env => { });
            });
        }
        public void Should_only_add_default_configurations_that_have_not_been_defined_by_user_code()
        {
            // Given
            var key = typeof(object).FullName;

            var env = A.Fake<INancyEnvironment>();
            A.CallTo(() => env.ContainsKey(key)).Returns(true);

            var fact = A.Fake<INancyEnvironmentFactory>();
            A.CallTo(() => fact.CreateEnvironment()).Returns(env);

            var provider = A.Fake<INancyDefaultConfigurationProvider>();
            A.CallTo(() => provider.GetDefaultConfiguration()).Returns(new object());

            var config = new DefaultNancyEnvironmentConfigurator(fact, new[] { provider });

            // When
            config.ConfigureEnvironment(x => { });

            // Then
            A.CallTo(() => env.AddValue(A<string>.That.Matches(x => x.Equals(key)), A<object>._)).MustNotHaveHappened();
        }
        public void Should_get_key_from_configuration_provider_for_default_configuration_object(Type type)
        {
            // Given
            var expectedKey = string.Concat("the-expected-key-", type.Name);
            var env = new DefaultNancyEnvironment();

            var fact = A.Fake<INancyEnvironmentFactory>();
            A.CallTo(() => fact.CreateEnvironment()).Returns(env);

            var provider = A.Fake<INancyDefaultConfigurationProvider>();
            A.CallTo(() => provider.GetDefaultConfiguration()).ReturnsLazily(() => Activator.CreateInstance(type));
            A.CallTo(() => provider.Key).Returns(expectedKey);

            var config = new DefaultNancyEnvironmentConfigurator(fact, new[] { provider });

            // When
            config.ConfigureEnvironment(x => { });

            // Then
            env.ContainsKey(expectedKey).ShouldBeTrue();
        }