public void ShouldReturnNullForMalformedHeader(string header)
        {
            var parser = new LanguageHeaderParser();
            var result = parser.Parse(header);

            Assert.That(result, Is.Null);
        }
        public void ShouldReturnNullWithNoHeader()
        {
            var parser = new LanguageHeaderParser();
            var result = parser.Parse("");

            Assert.That(result, Is.Null);
        }
Beispiel #3
0
        /// <summary>
        /// Pass in a language header, get a language code that complies with the language rules you specified
        /// </summary>
        /// <param name="languageHeader">String, the language header passed in with a request</param>
        /// <returns></returns>
        public String GetLanguageCode(String languageHeader)
        {
            if (String.IsNullOrEmpty(languageHeader))
            {
                return(DefaultLanguage);
            }
            var languages = HeaderParser.Parse(languageHeader);

            return((languages != null && languages.Any()) ? ProcessLanguages(languages) : DefaultLanguage);
        }
        public void ShouldParseOutHeader()
        {
            const string header = "en-US,en;q=0.8,de;q=0.6,de-DE;q=0.4";

            var expected = new List <Language>
            {
                new Language("en-us", 1.0d),
                new Language("en", 0.8d),
                new Language("de", 0.6d),
                new Language("de-de", 0.4d)
            };

            var parser = new LanguageHeaderParser();

            var result = parser.Parse(header);

            for (var i = 0; i < result.Count; i++)
            {
                Assert.That(new LanguageComparer().Equals(result[i], expected[i]));
            }
        }