Exemplo n.º 1
0
        public void Should_throw_configuration_exception_if_empty_list_of_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Globalization(Enumerable.Empty <string>()));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
Exemplo n.º 2
0
        public void Should_throw_configuration_exception_if_null_value_used_for_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Globalization(null));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
Exemplo n.º 3
0
        public void Should_throw_configuration_exception_if_default_culture_not_supported_globalization_configuration()
        {
            //Given
            var context = CreateContextRequest("/");

            //When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Globalization(new[] { "en-GB" }, defaultCulture: "quz-EC"));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
Exemplo n.º 4
0
        public DefaultXmlSerializerTests()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);
            environment.Xml(true);
            environment.Globalization(new[] { "en-US" });

            this.xmlSerializer = new DefaultXmlSerializer(environment);
        }
Exemplo n.º 5
0
        public DefaultJsonSerializerTests()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);
            environment.Json();
            environment.Globalization(new[] { "en-US" });

            this.jsonSerializer = new DefaultJsonSerializer(environment);
        }
Exemplo n.º 6
0
        private static INancyEnvironment GetTestingEnvironment()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            environment.Json();
            environment.Globalization(new []{"en-US"});

            return environment;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Globalization(new[] { "en-US" });
            diagnosticsEnvironment.Json(retainCasing: false);
            diagnosticsEnvironment.AddValue(ViewConfiguration.Default);
            diagnosticsEnvironment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            return(diagnosticsEnvironment);
        }
Exemplo n.º 8
0
        private NancyContext CreateContextRequest(string path, IDictionary <string, IEnumerable <string> > cultureHeaders = null)
        {
            var context = new NancyContext();
            var request = new Request("GET", new Url {
                Path = path, Scheme = "http"
            }, null, cultureHeaders);

            context.Request = request;
            var environment = new DefaultNancyEnvironment();

            environment.Globalization(new[] { "en-US" }, "en-US");
            context.Environment = environment;
            return(context);
        }
Exemplo n.º 9
0
        public void Should_return_first_supported_culture_for_default_culture_on_globalization_configuration()
        {
            //Given
            var context = CreateContextRequest("/");

            //When
            var environment = new DefaultNancyEnvironment();

            environment.Globalization(new[] { "en-US" }, defaultCulture: null);
            var culture = BuiltInCultureConventions.GlobalizationConfigurationCulture(context, environment.GetValue <GlobalizationConfiguration>());

            //Then
            culture.Name.ShouldEqual("en-US");
        }
        public void Should_throw_configuration_exception_if_null_value_used_for_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception = Record.Exception(() => environment.Globalization(null));

            //Then
            exception.ShouldBeOfType<ConfigurationException>();
        }
 private NancyContext CreateContextRequest(string path, IDictionary<string, IEnumerable<string>> cultureHeaders = null)
 {
     var context = new NancyContext();
     var request = new Request("GET", new Url { Path = path, Scheme = "http" }, null, cultureHeaders);
     context.Request = request;
     var environment = new DefaultNancyEnvironment();
     environment.Globalization(new[] { "en-US" }, "en-US");
     context.Environment = environment;
     return context;
 }
        public void Should_throw_configuration_exception_if_empty_list_of_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception = Record.Exception(() => environment.Globalization(Enumerable.Empty<string>()));

            //Then
            exception.ShouldBeOfType<ConfigurationException>();
        }
        public void Should_throw_configuration_exception_if_default_culture_not_supported_globalization_configuration()
        {
            //Given
            var context = CreateContextRequest("/");

            //When
            var environment = new DefaultNancyEnvironment();
            var exception = Record.Exception(() => environment.Globalization(new[] { "en-GB" }, defaultCulture: "quz-EC"));

            //Then
            exception.ShouldBeOfType<ConfigurationException>();
        }
        public void Should_return_first_supported_culture_for_default_culture_on_globalization_configuration()
        {
            //Given
            var context = CreateContextRequest("/");

            //When
            var environment = new DefaultNancyEnvironment();
            environment.Globalization(new[] { "en-US" }, defaultCulture: null);
            var culture = BuiltInCultureConventions.GlobalizationConfigurationCulture(context, environment.GetValue<GlobalizationConfiguration>());

            //Then
            culture.Name.ShouldEqual("en-US");
        }
Exemplo n.º 15
0
        private static INancyEnvironment GetTestingEnvironment()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            environment.Json();
            environment.Globalization(new []{"en-US"});

            return environment;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Globalization(new[] { "en-US" });
            diagnosticsEnvironment.Json(retainCasing: false);
            diagnosticsEnvironment.AddValue(ViewConfiguration.Default);
            diagnosticsEnvironment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            return diagnosticsEnvironment;
        }