public void Should_return_null_if_form_populated_with_invalid_culture(string cultureName) { //Given var context = PopulateForm(cultureName); //When var culture = BuiltInCultureConventions.FormCulture(context); //Then culture.ShouldBeNull(); }
public void Should_return_null_if_no_cookie_populated() { //Given var context = CreateContextRequest("/"); //When var culture = BuiltInCultureConventions.CookieCulture(context, context.Environment.GetValue <GlobalizationConfiguration>()); //Then culture.ShouldBeNull(); }
public void Should_return_null_if_no_cookie_populated() { //Given var context = CreateContextRequest("/"); //When var culture = BuiltInCultureConventions.CookieCulture(context); //Then culture.ShouldBeNull(); }
public void Should_return_culture_if_form_populated() { //Given var context = PopulateForm("en-GB"); //When var culture = BuiltInCultureConventions.FormCulture(context); //Then culture.Name.ShouldEqual("en-GB"); }
public void Should_return_culture_if_first_path_parameter_valid_culture(string path, string expected) { //Given var context = CreateContextRequest(path); //When var culture = BuiltInCultureConventions.PathCulture(context, new GlobalizationConfiguration(new[] { expected }, expected)); //Then culture.Name.ShouldEqual(expected); }
public void Should_culture_of_request_path_if_first_path_parameter_valid_culture(string path, string expectedPath) { //Given var context = CreateContextRequest(path); //When var culture = BuiltInCultureConventions.PathCulture(context, new GlobalizationConfiguration(new string[] { "en-GB" }, "en-GB")); //Then context.Request.Url.Path.ShouldEqual(expectedPath); }
public void Should_return_null_if_first_path_parameter_not_valid_culture(string path) { //Given var context = CreateContextRequest(path); //When var culture = BuiltInCultureConventions.PathCulture(context, context.Environment.GetValue <GlobalizationConfiguration>()); //Then culture.ShouldBeNull(); }
public void Should_return_culture_if_form_populated() { //Given var context = PopulateForm("en-GB"); //When var culture = BuiltInCultureConventions.FormCulture(context, new GlobalizationConfiguration(new[] { "en-GB" }, "en-GB")); //Then culture.Name.ShouldEqual("en-GB"); }
public void Should_return_culture_from_default_culture_on_globalization_configuration() { //Given var context = CreateContextRequest("/"); //When var culture = BuiltInCultureConventions.GlobalizationConfigurationCulture(context, context.Environment.GetValue <GlobalizationConfiguration>()); //Then culture.Name.ShouldEqual("en-US"); }
public void Should_culture_of_request_path_if_first_path_parameter_valid_culture(string path, string expectedPath) { //Given var context = CreateContextRequest(path); //When var culture = BuiltInCultureConventions.PathCulture(context); //Then context.Request.Url.Path.ShouldEqual(expectedPath); }
public void Should_return_null_if_first_path_parameter_not_valid_culture(string path) { //Given var context = CreateContextRequest(path); //When var culture = BuiltInCultureConventions.PathCulture(context); //Then culture.ShouldBeNull(); }
public void Should_return_culture_from_current_thread() { //Given var context = CreateContextRequest("/"); var expectedCultureName = Thread.CurrentThread.CurrentCulture.Name; //When var culture = BuiltInCultureConventions.ThreadCulture(context); //Then culture.Name.ShouldEqual(expectedCultureName); }
public void Should_return_culture_from_current_thread() { //Given var context = CreateContextRequest("/"); var expectedCultureName = Thread.CurrentThread.CurrentCulture.Name; //When var culture = BuiltInCultureConventions.ThreadCulture(context, context.Environment.GetValue <GlobalizationConfiguration>()); //Then culture.Name.ShouldEqual(expectedCultureName); }
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_return_valid_culture_if_header_populated() { //Given var headers = new Dictionary <string, IEnumerable <string> > { { "Accept-Language", new[] { "en-GB" } } }; var context = CreateContextRequest("/", headers); //When var culture = BuiltInCultureConventions.HeaderCulture(context); //Then culture.Name.ShouldEqual("en-GB"); }
public void Should_use_highest_weighted_header() { //Given var headers = new Dictionary <string, IEnumerable <string> > { { "Accept-Language", new[] { "en-GB;q=0.8", "de-DE;q=0.7", "nl;q=0.5", "es;q=0.4" } } }; var context = CreateContextRequest("/", headers); //When var culture = BuiltInCultureConventions.HeaderCulture(context); //Then culture.Name.ShouldEqual("en-GB"); }
public void Should_return_null_if_invalid_culture_in_header(string cultureName) { //Given var headers = new Dictionary <string, IEnumerable <string> > { { "Accept-Language", new[] { cultureName } } }; var context = CreateContextRequest("/", headers); //When var culture = BuiltInCultureConventions.HeaderCulture(context); //Then culture.ShouldBeNull(); }
public void Should_return_culture_if_session_populated() { //Given var context = CreateContextRequest("/"); var sessionValues = new Dictionary <string, object> { { "CurrentCulture", new CultureInfo("en-GB") } }; context.Request.Session = new Session(new Dictionary <string, object>(sessionValues)); //When var culture = BuiltInCultureConventions.SessionCulture(context); //Then culture.Name.ShouldEqual("en-GB"); }
public void Should_return_culture_if_cookie_populate() { // Given const string cookieName = "CurrentCulture"; const string cookieData = "en-GB"; var headers = new Dictionary <string, IEnumerable <string> > { { "cookie", new[] { string.Format("{0}={1}", cookieName, cookieData) } } }; var context = CreateContextRequest("/", headers); //When var culture = BuiltInCultureConventions.CookieCulture(context); // Then culture.Name.ShouldEqual("en-GB"); }
public void Should_return_null_if_invalid_culture_in_cookie(string cultureName) { // Given const string cookieName = "CurrentCulture"; string cookieData = cultureName; var headers = new Dictionary <string, IEnumerable <string> > { { "cookie", new[] { string.Format("{0}={1}", cookieName, cookieData) } } }; var context = CreateContextRequest("/", headers); //When var culture = BuiltInCultureConventions.CookieCulture(context); //Then culture.ShouldBeNull(); }
public void Should_throw_exception_if_invalid_session_value(string cultureName) { //Given var context = CreateContextRequest("/"); var sessionValues = new Dictionary <string, object> { { "CurrentCulture", cultureName } }; context.Request.Session = new Session(new Dictionary <string, object>(sessionValues)); //When var exception = Record.Exception(() => BuiltInCultureConventions.SessionCulture(context)); //Then exception.ShouldBeOfType <InvalidCastException>(); }