public void AddTranslation_ConfigurationValidateCultureIsFalse_IgnoresNotAcceptedCulture()
        {
            // Arrange
            Configuration.ValidateCulture = false;

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Home", "Home", new { controller = "Home", action = "Index" }, null);

            // Act
            routeCollection.AddTranslation("Start", "de", "Home", "Index");
        }
        public void AddTranslation_ConfigurationAddCultureAsRoutePrefixIsTrue_AddsPrefixToTranslatedRoutes()
        {
            // Arrange
            Configuration.AcceptedCultures.Add("de");

            Configuration.AddCultureAsRoutePrefix = true;

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Welcome", "Welcome", new { controller = "Home", action = "Index" }, null);

            // Act
            routeCollection.AddTranslation("Willkommen", "de", "Home", "Index");

            // Assert
            Assert.IsTrue(routeCollection.Count == 2);

            Assert.IsTrue(((TranslationRoute)routeCollection[0]).Url == "en/Welcome");
            Assert.IsTrue(((TranslationRoute)routeCollection[1]).Url == "de/Willkommen");
        }
        public void AddTranslation_ConfigurationValidateURLIsFalse_IgnoresDifferentNumberOfURLPlaceholders()
        {
            // Arrange
            Configuration.AcceptedCultures.Add("de");

            Configuration.ValidateURL = false;

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Book", "Book/{chapter}/{page}", new { controller = "Home", action = "Book" }, null);

            // Act
            routeCollection.AddTranslation("Buch/{chapter}/", "de", "Home", "Book");
        }
        public void AddTranslation_TwoRoutesForTheSameActionExists_ReplacesRoutesCorrect()
        {
            // Arrange
            Configuration.AcceptedCultures.Add("de");

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Home1", "Home1", new { controller = "Home", action = "Index" }, null);
            routeCollection.MapRoute("Home2", "Home2", new { controller = "Home", action = "Index" }, null);

            // Act
            routeCollection.AddTranslation("Start1", "de", "Home", "Index");

            TranslationRoute translationRouteRootFirst = (TranslationRoute)routeCollection[0];
            TranslationRoute translationRouteFirst = (TranslationRoute)routeCollection[1];

            routeCollection.AddTranslation("Start2", "de", "Home", "Index");

            // Assert
            Assert.IsTrue(routeCollection.Count == 4);

            Assert.AreSame(translationRouteRootFirst, routeCollection[0]);
            Assert.AreSame(translationRouteFirst, routeCollection[1]);
            Assert.IsInstanceOfType(routeCollection[2], typeof(TranslationRoute));
            Assert.IsTrue(((TranslationRoute)routeCollection[2]).Url == "Home2");
            Assert.IsInstanceOfType(routeCollection[3], typeof(TranslationRoute));
            Assert.IsTrue(((TranslationRoute)routeCollection[3]).Url == "Start2");
        }
        public void AddTranslation_ThreeRoutesExist_RootRouteContainsTranslatedRoute()
        {
            // Arrange
            Configuration.AcceptedCultures.Add("de");

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Home", "Home", new { controller = "Home", action = "Index" }, null);
            routeCollection.MapRoute("Book", "Book/{chapter}/{page}", new { controller = "Home", action = "Book" }, null);
            routeCollection.MapRoute("Product", "Product/{category}/{id}", new { controller = "Home", action = "Product" }, null);

            // Act
            routeCollection.AddTranslation("Buch/{chapter}/{page}", "de", "Home", "Book");

            // Assert
            Assert.IsTrue(
                ((TranslationRoute)routeCollection[1]).TranslatedRoutes.Values.Contains((TranslationRoute)routeCollection[2]));
        }
        public void AddTranslation_ThreeRoutesExist_ReplacesTranslatedRoute()
        {
            // Arrange
            Configuration.AcceptedCultures.Add("de");

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Home", "Home", new { controller = "Home", action = "Index" }, null);
            routeCollection.MapRoute("Book", "Book/{chapter}/{page}", new { controller = "Home", action = "Book" }, null);
            routeCollection.MapRoute("Product", "Product/{category}/{id}", new { controller = "Home", action = "Product" }, null);

            RouteBase route1 = routeCollection[0];
            RouteBase routeToTranslate = routeCollection[1];
            RouteBase route3 = routeCollection[2];

            // Act
            routeCollection.AddTranslation("Buch/{chapter}/{page}", "de", "Home", "Book");

            // Assert
            Assert.IsTrue(routeCollection.Count == 4);
            Assert.AreSame(route1, routeCollection[0]);
            Assert.AreNotSame(routeToTranslate, routeCollection[1]);
            Assert.IsInstanceOfType(routeCollection[1], typeof(TranslationRoute));
            Assert.IsTrue(((TranslationRoute)routeCollection[1]).Url == "Book/{chapter}/{page}");
            Assert.IsInstanceOfType(routeCollection[2], typeof(TranslationRoute));
            Assert.IsTrue(((TranslationRoute)routeCollection[2]).Url == "Buch/{chapter}/{page}");
            Assert.AreSame(route3, routeCollection[3]);
        }
        public void AddTranslation_NotAcceptedCulture_ThrowsInvalidOperationException()
        {
            // Arrange
            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Home", "Home", new { controller = "Home", action = "Index" }, null);

            // Act
            routeCollection.AddTranslation("Start", "de", "Home", "Index");
        }
        public void AddTranslation_MissingRoute_ThrowsInvalidOperationException()
        {
            // Arrange
            RouteCollection routeCollection = new RouteCollection();

            // Act
            routeCollection.AddTranslation("Start", "de", "Home", "Index");
        }
        public void AddTranslation_DifferentURLPlaceholders_ThrowsInvalidOperationException()
        {
            // Arrange
            Configuration.AcceptedCultures.Add("de");

            RouteCollection routeCollection = new RouteCollection();
            routeCollection.MapRoute("Book", "Book/{chapter}/{page}", new { controller = "Home", action = "Book" }, null);

            // Act
            routeCollection.AddTranslation("Buch/{page}/{chapter}", "de", "Home", "Book");
        }