public void BuildWithControllerActionsSelectionBuildsCorrectTranslation2() { TranslateActionRouteProcessor routeProcessor = CreateRouteProcessor(); routeProcessor.Culture = TranslateControllerRouteProcessorBuilderTest.Culture; routeProcessor.Template = "template"; ApplicationModel applicationModel = TestApplicationModel.Instance; List <RouteSelection> routeSelections = new List <RouteSelection>() { new RouteSelection() { ControllerModel = applicationModel.Controller2(), ActionModels = applicationModel.Controller2().Actions.Take(1).ToList(), }, }; routeProcessor.Process(routeSelections); ControllerModel translatedController = applicationModel.Controllers.Last(controller => controller.ControllerName == "Controller2"); Assert.IsTrue(applicationModel.Controllers.Count(controller => controller.ControllerName == "Controller2") == 2); Assert.IsTrue(translatedController.Selectors.Count == 0); Assert.IsTrue(translatedController.Actions.First().Selectors.Count == 1); Assert.IsTrue(translatedController.Actions.First().Selectors.First().AttributeRouteModel.Template == $"[{TranslateControllerRouteProcessorBuilderTest.CultureKey}]/template"); }
public void BuildWithMultipleSelectionBuildsThrowsException() { TranslateActionRouteProcessor routeProcessor = CreateRouteProcessor(); routeProcessor.Culture = TranslateControllerRouteProcessorBuilderTest.Culture; routeProcessor.Template = "template"; ApplicationModel applicationModel = TestApplicationModel.Instance; List <RouteSelection> routeSelections = new List <RouteSelection>() { new RouteSelection() { ControllerModel = applicationModel.Controller1(), ActionModels = applicationModel.Controller1().Actions.Take(1).ToList(), }, new RouteSelection() { ControllerModel = applicationModel.Controller2(), ActionModels = applicationModel.Controller2().Actions.Take(1).ToList(), }, }; routeProcessor.Process(routeSelections); }
public void SelectWithFilteredNoTranslatedOptionReturnsCorrectSelection2() { ApplicationModel applicationModel = TestApplicationModel.Instance; StaticRouteSelector routeSelector = new StaticRouteSelector(); routeSelector.RouteSelection.Add(new RouteSelection() { ControllerModel = applicationModel.Controller4(), ActionModels = applicationModel.Controller4().Actions, }); routeSelector.RouteSelection.Add(new RouteSelection() { ControllerModel = applicationModel.Controller2(), ActionModels = applicationModel.Controller2().Actions, }); ControllerModel translatedController = applicationModel.Controller4() .CreateLocalizedControllerModel(GetLocalizer(), TranslatedRoutesRouteSelectorBuilderTest.Culture); foreach (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizer()).Selectors) { translatedController.Selectors.Add(selectorModel); } applicationModel.Controllers.Add(translatedController); ControllerModel translatedController2 = applicationModel.Controller2() .CreateLocalizedControllerModel(GetLocalizer(), FilterRouteSelectorTest.Culture); for (int i = 0; i < translatedController2.Actions.Count; i++) { foreach (SelectorModel selectorModel in translatedController2.GetOriginalModel(GetLocalizer()).Actions[i].Selectors) { translatedController2.Actions[i].Selectors.Add(selectorModel); } } applicationModel.Controllers.Add(translatedController2); FilterRouteSelector filterRouteSelector = new FilterRouteSelector(routeSelector) { Controller = "Controller4", Action = "Action1", Localizer = GetLocalizer(), Cultures = new[] { FilterRouteSelectorTest.Culture }, FilterControllerOrActionWhenNoTranslatedRouteLeft = true, }; ICollection <RouteSelection> routeSelections = filterRouteSelector.Select(applicationModel); Assert.IsTrue(routeSelections.Count == 2); Assert.IsTrue(routeSelections.First().ActionModels.Count == 0); Assert.IsTrue(routeSelections.Last().ControllerModel.ControllerName == "Controller2"); Assert.IsTrue(routeSelections.Last().ActionModels.Count == 2); Assert.IsTrue(routeSelections.Last().ActionModels.First().ActionName == "Action1"); Assert.IsTrue(routeSelections.Last().ActionModels.Last().ActionName == "Action2"); }
public void BuildForUntranslatedActionRoutesReturnsCorrectRouteSelector() { IRouteSelector routeSelector = new TranslatedRoutesRouteSelector() { Cultures = new[] { UntranslatedRoutesRouteSelectorBuilderTest.Culture, UntranslatedRoutesRouteSelectorBuilderTest.Culture2 }, Localizer = GetLocalizer(), }; ApplicationModel applicationModel = TestApplicationModel.Instance; ControllerModel originalController = applicationModel.Controller2(); ControllerModel translatedController = originalController .CreateLocalizedControllerModel(GetLocalizer(), UntranslatedRoutesRouteSelectorBuilderTest.Culture); applicationModel.Controllers.Add(translatedController); translatedController = originalController .CreateLocalizedControllerModel(GetLocalizer(), UntranslatedRoutesRouteSelectorBuilderTest.Culture2); applicationModel.Controllers.Add(translatedController); ICollection <RouteSelection> routeSelections = routeSelector.Select(applicationModel); Assert.IsTrue(routeSelections.Count == 0); }
public void BuildWithActionsSelectionBuildsCorrectProcessor() { DisableOriginalRouteProcessor routeProcessor = CreateRouteProcessor(); routeProcessor.Cultures = new[] { DisableOriginalRouteProcessorBuilderTest.Culture, DisableOriginalRouteProcessorBuilderTest.Culture2, }; ApplicationModel applicationModel = TestApplicationModel.Instance; ControllerModel originalController = applicationModel.Controller2(); ControllerModel translatedController = originalController.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), DisableOriginalRouteProcessorBuilderTest.Culture); foreach (ActionModel translatedAction in translatedController.Actions.Take(1)) { foreach (SelectorModel selectorModel in translatedAction.GetOriginalModel(GetLocalizedRouteMarker()).Selectors.Take(1)) { translatedAction.Selectors.Add(selectorModel); } } applicationModel.Controllers.Add(translatedController); translatedController = originalController.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), DisableOriginalRouteProcessorBuilderTest.Culture2); foreach (ActionModel translatedAction in translatedController.Actions.Take(1)) { foreach (SelectorModel selectorModel in translatedAction.GetOriginalModel(GetLocalizedRouteMarker()).Selectors) { translatedAction.Selectors.Add(selectorModel); } } applicationModel.Controllers.Add(translatedController); List <RouteSelection> routeSelections = new List <RouteSelection>() { new RouteSelection() { ControllerModel = originalController, ActionModels = originalController.Actions.Take(1).ToList(), }, }; routeProcessor.Process(routeSelections); Assert.IsFalse(originalController.Selectors.First().ActionConstraints.OfType <NeverAcceptActionContraint>().Any()); Assert.IsTrue(originalController.Actions.First() .Selectors.First() .ActionConstraints.OfType <NeverAcceptActionContraint>() .Any()); Assert.IsFalse(originalController.Actions.Last() .Selectors.First() .ActionConstraints.OfType <NeverAcceptActionContraint>() .Any()); }
public void IsPartiallyTranslatedForNonAttributeRoutedControllerThrowsException() { ApplicationModel applicationModel = TestApplicationModel.Instance; ControllerModel controller = applicationModel.Controller2(); ControllerModel translatedController = controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture); applicationModel.Controllers.Add(translatedController); bool isPartiallyLocalized = translatedController.IsPartiallyTranslated(GetLocalizedRouteMarker()); }
public void SelectWithFilteredNoUntranslatedOptionReturnsCorrectSelection1() { ApplicationModel applicationModel = TestApplicationModel.Instance; StaticRouteSelector routeSelector = new StaticRouteSelector(); routeSelector.RouteSelection.Add(new RouteSelection() { ControllerModel = applicationModel.Controller4(), ActionModels = applicationModel.Controller4().Actions, }); routeSelector.RouteSelection.Add(new RouteSelection() { ControllerModel = applicationModel.Controller2(), ActionModels = applicationModel.Controller2().Actions, }); FilterRouteSelector filterRouteSelector = new FilterRouteSelector(routeSelector) { Controller = "Controller4", Action = "Action1", ActionArguments = new[] { typeof(int) }, Localizer = GetLocalizer(), Cultures = new[] { FilterRouteSelectorTest.Culture }, FilterControllerOrActionWhenNoUntranslatedRouteLeft = true, }; ICollection <RouteSelection> routeSelections = filterRouteSelector.Select(applicationModel); Assert.IsTrue(routeSelections.Count == 2); Assert.IsTrue(routeSelections.First().ActionModels.Count == 1); Assert.IsTrue(routeSelections.First().ActionModels.Single().Parameters.Count == 0); Assert.IsTrue(routeSelections.Last().ControllerModel.ControllerName == "Controller2"); Assert.IsTrue(routeSelections.Last().ActionModels.Count == 2); Assert.IsTrue(routeSelections.Last().ActionModels.First().ActionName == "Action1"); Assert.IsTrue(routeSelections.Last().ActionModels.Last().ActionName == "Action2"); }
public void BuildForUntranslatedActionRoutesReturnsCorrectRouteSelector() { IRouteSelector routeSelector = new UntranslatedRoutesRouteSelector() { Culture = TranslatedRoutesRouteSelectorBuilderTest.Culture, Localizer = GetLocalizer(), }; ApplicationModel applicationModel = TestApplicationModel.Instance; ControllerModel translatedController = applicationModel.Controller2() .CreateLocalizedControllerModel(GetLocalizer(), TranslatedRoutesRouteSelectorBuilderTest.Culture); applicationModel.Controllers.Add(translatedController); ICollection <RouteSelection> routeSelections = routeSelector.Select(applicationModel); RouteSelection routeSelection = routeSelections.Single(selection => selection.ControllerModel.ControllerName == "Controller2"); Assert.IsTrue(routeSelection.ActionModels.Count == 2); }