本文整理汇总了C#中RouteCollection.AddTranslation方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.AddTranslation方法的具体用法?C# RouteCollection.AddTranslation怎么用?C# RouteCollection.AddTranslation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.AddTranslation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTranslation_ConfigurationValidateCultureIsFalse_IgnoresNotAcceptedCulture
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");
}
示例2: AddTranslation_ConfigurationAddCultureAsRoutePrefixIsTrue_AddsPrefixToTranslatedRoutes
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");
}
示例3: AddTranslation_ConfigurationValidateURLIsFalse_IgnoresDifferentNumberOfURLPlaceholders
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");
}
示例4: AddTranslation_TwoRoutesForTheSameActionExists_ReplacesRoutesCorrect
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");
}
示例5: AddTranslation_ThreeRoutesExist_RootRouteContainsTranslatedRoute
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]));
}
示例6: AddTranslation_ThreeRoutesExist_ReplacesTranslatedRoute
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]);
}
示例7: AddTranslation_NotAcceptedCulture_ThrowsInvalidOperationException
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");
}
示例8: AddTranslation_MissingRoute_ThrowsInvalidOperationException
public void AddTranslation_MissingRoute_ThrowsInvalidOperationException()
{
// Arrange
RouteCollection routeCollection = new RouteCollection();
// Act
routeCollection.AddTranslation("Start", "de", "Home", "Index");
}
示例9: AddTranslation_DifferentURLPlaceholders_ThrowsInvalidOperationException
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");
}