Exemplo n.º 1
0
        public void opImplicit_AcceptLanguage_stringEmpty()
        {
            AcceptLanguage obj = string.Empty;

            Assert.Equal(1, obj.Languages.Count);
            Assert.Equal <Language>("*", obj.Languages[0]);
        }
Exemplo n.º 2
0
        public void op_FromString_string()
        {
            const string expected = "en";
            var          actual   = AcceptLanguage.FromString(expected).Languages[0];

            Assert.Equal <Language>(expected, actual);
        }
Exemplo n.º 3
0
        public void op_Negotiate_HttpRequestBase_Type()
        {
            var obj = AcceptLanguage.FromString("da, en-gb;q=0.8, en;q=0.7");

            var request = new Mock <HttpRequestBase>(MockBehavior.Strict);

            request
            .SetupGet(x => x.Path)
            .Returns("/test")
            .Verifiable();
            request
            .SetupGet(x => x.RawUrl)
            .Returns("http://example.com/test")
            .Verifiable();

            const string expected = "/test.en";

            // ReSharper disable PossibleNullReferenceException
            var actual = (obj.Negotiate(request.Object, typeof(DummyController)) as SeeOtherResult).Location;

            // ReSharper restore PossibleNullReferenceException
            Assert.Equal(expected, actual);

            request.VerifyAll();
        }
Exemplo n.º 4
0
        public void opImplicit_AcceptLanguage_string()
        {
            const string expected = "en";

            AcceptLanguage obj = expected;

            Assert.Equal(1, obj.Languages.Count);
            Assert.Equal <Language>(expected, obj.Languages[0]);
        }
Exemplo n.º 5
0
        public void opImplicit_AcceptLanguage_stringNull()
        {
            AcceptLanguage obj = null as string;

            // ReSharper disable PossibleNullReferenceException
            Assert.Equal(1, obj.Languages.Count);

            // ReSharper restore PossibleNullReferenceException
            Assert.Equal <Language>("*", obj.Languages[0]);
        }
Exemplo n.º 6
0
        public void op_FromString_stringAcceptLanguage()
        {
            const string value = "da, en-gb;q=0.8, en;q=0.7";
            var          obj   = AcceptLanguage.FromString(value);

            Assert.Equal(3, obj.Languages.Count);

            Assert.Equal <Language>("da", obj.Languages[0]);
            Assert.Equal <Language>("en-gb", obj.Languages[1]);
            Assert.Equal <Language>("en", obj.Languages[2]);
        }
Exemplo n.º 7
0
        public void op_FromString_stringAcceptLanguageDisordered()
        {
            const string value = "*, en, en-gb;q=0.4, en-us";
            var          obj   = AcceptLanguage.FromString(value);

            Assert.Equal(4, obj.Languages.Count);

            Assert.Equal <Language>("en-us", obj.Languages[0]);
            Assert.Equal <Language>("en", obj.Languages[1]);
            Assert.Equal <Language>("en-gb", obj.Languages[2]);
            Assert.Equal <Language>("*", obj.Languages[3]);
        }
Exemplo n.º 8
0
        public ActionResult LanguageNegotiation()
        {
            AcceptLanguage accept = Request.Headers["Accept-Language"];

            return(accept.Negotiate(Request, GetType()));
        }