public void BuildForUntranslatedControllerRoutesReturnsCorrectRouteSelector()
        {
            IRouteSelector routeSelector = new TranslatedRoutesRouteSelector()
            {
                Cultures  = new[] { UntranslatedRoutesRouteSelectorBuilderTest.Culture, UntranslatedRoutesRouteSelectorBuilderTest.Culture2 },
                Localizer = GetLocalizer(),
            };

            ApplicationModel applicationModel   = TestApplicationModel.Instance;
            ControllerModel  originalController = applicationModel.Controller3();

            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);
        }
Exemplo n.º 2
0
        public void IsPartiallyTranslatedForNonAttributeRoutedActionThrowsException()
        {
            ApplicationModel applicationModel = TestApplicationModel.Instance;
            ControllerModel  controller       = applicationModel.Controller3();
            ActionModel      action           = controller.Actions.First();

            ControllerModel translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);
            ActionModel translatedAction = translatedController.Actions.First();

            applicationModel.Controllers.Add(translatedController);

            bool isPartiallyLocalized = translatedAction.IsPartiallyTranslated(GetLocalizedRouteMarker());
        }
        public void BuildWithControllerSelectionBuildsCorrectProcessor()
        {
            DisableOriginalRouteProcessor routeProcessor = CreateRouteProcessor();

            routeProcessor.Cultures = new[]
            {
                DisableOriginalRouteProcessorBuilderTest.Culture, DisableOriginalRouteProcessorBuilderTest.Culture2,
            };

            ApplicationModel applicationModel   = TestApplicationModel.Instance;
            ControllerModel  originalController = applicationModel.Controller3();

            ControllerModel translatedController =
                originalController.CreateLocalizedControllerModel(GetLocalizedRouteMarker(),
                                                                  DisableOriginalRouteProcessorBuilderTest.Culture);

            foreach (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizedRouteMarker()).Selectors.Take(1))
            {
                translatedController.Selectors.Add(selectorModel);
            }

            applicationModel.Controllers.Add(translatedController);

            translatedController = originalController.CreateLocalizedControllerModel(GetLocalizedRouteMarker(),
                                                                                     DisableOriginalRouteProcessorBuilderTest.Culture2);

            foreach (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizedRouteMarker()).Selectors.Take(1))
            {
                translatedController.Selectors.Add(selectorModel);
            }

            applicationModel.Controllers.Add(translatedController);

            List <RouteSelection> routeSelections = new List <RouteSelection>()
            {
                new RouteSelection()
                {
                    ControllerModel = originalController,
                    ActionModels    = new List <ActionModel>(),
                },
            };

            routeProcessor.Process(routeSelections);

            Assert.IsTrue(originalController.Selectors.First().ActionConstraints.OfType <NeverAcceptActionContraint>().Any());
            Assert.IsFalse(originalController.Selectors.Last().ActionConstraints.OfType <NeverAcceptActionContraint>().Any());
            Assert.IsFalse(
                originalController.Actions.First().Selectors.First().ActionConstraints.OfType <NeverAcceptActionContraint>().Any());
        }
        public void BuildForUntranslatedControllerRoutesReturnsCorrectRouteSelector()
        {
            IRouteSelector routeSelector = new UntranslatedRoutesRouteSelector()
            {
                Culture   = TranslatedRoutesRouteSelectorBuilderTest.Culture,
                Localizer = GetLocalizer(),
            };

            ApplicationModel applicationModel = TestApplicationModel.Instance;

            ControllerModel translatedController = applicationModel.Controller3()
                                                   .CreateLocalizedControllerModel(GetLocalizer(), TranslatedRoutesRouteSelectorBuilderTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            ICollection <RouteSelection> routeSelections = routeSelector.Select(applicationModel);

            RouteSelection routeSelection =
                routeSelections.Single(selection => selection.ControllerModel.ControllerName == "Controller3");

            Assert.IsTrue(routeSelection.ActionModels.Count == 0);
        }
        public void BuildWithControllerSelectionMixBuildsCorrectTranslation()
        {
            CopyTemplateRouteProcessor routeProcessor = CreateRouteProcessor();

            routeProcessor.Culture = TranslateControllerRouteProcessorBuilderTest.Culture;

            ApplicationModel applicationModel = TestApplicationModel.Instance;

            List <RouteSelection> routeSelections = new List <RouteSelection>()
            {
                new RouteSelection()
                {
                    ControllerModel = applicationModel.Controller3(),
                    ActionModels    = new List <ActionModel>(),
                },
                new RouteSelection()
                {
                    ControllerModel = applicationModel.Controller1(),
                    ActionModels    = applicationModel.Controller1().Actions.Take(1).ToList(),
                },
            };

            routeProcessor.Process(routeSelections);

            ControllerModel translatedController =
                applicationModel.Controllers.Last(controller => controller.ControllerName == "Controller1");

            Assert.IsTrue(applicationModel.Controllers.Count(controller => controller.ControllerName == "Controller1") == 2);
            Assert.IsTrue(applicationModel.Controllers.Count(controller => controller.ControllerName == "Controller2") == 1);
            Assert.IsTrue(translatedController.Selectors.Count == 2);
            Assert.IsTrue(translatedController.Selectors.First().AttributeRouteModel.Template ==
                          $"[{TranslateControllerRouteProcessorBuilderTest.CultureKey}]/Controller1");
            Assert.IsTrue(translatedController.Selectors.Last().AttributeRouteModel.Template ==
                          $"[{TranslateControllerRouteProcessorBuilderTest.CultureKey}]/Controller11");
            Assert.IsTrue(translatedController.Actions.First().Selectors.Count == 2);
            Assert.IsTrue(translatedController.Actions.First().Selectors.First().AttributeRouteModel.Template == "Action1");
            Assert.IsTrue(translatedController.Actions.First().Selectors.Last().AttributeRouteModel.Template == "Action11");
            Assert.IsTrue(translatedController.Actions.Skip(1).All(action => action.Selectors.Count == 0));
        }