Ejemplo n.º 1
0
        public void op_ContentNegotiation_CultureInfo()
        {
            var culture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                const string location = "/test.fr";

                var headers = new NameValueCollection();
                headers["Accept"] = "*/*, text/*, text/html";

                var request = new Mock<HttpRequestBase>(MockBehavior.Strict);
                request
                    .SetupGet(x => x.Headers)
                    .Returns(headers)
                    .Verifiable();
                request
                    .SetupGet(x => x.Path)
                    .Returns(location)
                    .Verifiable();
                request
                    .SetupGet(x => x.RawUrl)
                    .Returns(location)
                    .Verifiable();

                var context = new Mock<HttpContextBase>(MockBehavior.Strict);
                context
                    .SetupGet(x => x.Request)
                    .Returns(request.Object)
                    .Verifiable();

                var controller = new DerivedLanguageController();
                controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

                var result = (SeeOtherResult)controller.ContentNegotiation(new CultureInfo("fr"));

                Assert.Equal(location + ".html", result.Location);

                request.VerifyAll();
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = culture;
            }
        }
        public void op_LanguageNegotiation()
        {
            var culture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                const string location = "/test";

                var headers = new NameValueCollection();
                headers["Accept-Language"] = "da, en-gb;q=0.8, en;q=0.7";

                var request = new Mock <HttpRequestBase>(MockBehavior.Strict);
                request
                .SetupGet(x => x.Headers)
                .Returns(headers)
                .Verifiable();
                request
                .SetupGet(x => x.Path)
                .Returns(location)
                .Verifiable();
                request
                .SetupGet(x => x.RawUrl)
                .Returns(location)
                .Verifiable();

                var context = new Mock <HttpContextBase>(MockBehavior.Strict);
                context
                .SetupGet(x => x.Request)
                .Returns(request.Object)
                .Verifiable();

                var controller = new DerivedLanguageController();
                controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

                var result = (SeeOtherResult)controller.LanguageNegotiation();

                Assert.Equal(location + ".en", result.Location);

                request.VerifyAll();
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = culture;
            }
        }