public void BuildWithControllerActionsSelectionBuildsCorrectTranslation2()
        {
            CopyTemplateRouteProcessor routeProcessor = CreateRouteProcessor();

            routeProcessor.Culture = TranslateControllerRouteProcessorBuilderTest.Culture;

            ApplicationModel applicationModel = TestApplicationModel.Instance;

            List <RouteSelection> routeSelections = new List <RouteSelection>()
            {
                new RouteSelection()
                {
                    ControllerModel = applicationModel.Controller1(),
                    ActionModels    = applicationModel.Controller1().Actions.Skip(1).Take(2).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(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.Skip(1).First().Selectors.Count == 1);
            Assert.IsTrue(translatedController.Actions.Skip(2).First().Selectors.Count == 1);
            Assert.IsTrue(translatedController.Actions.Skip(1).First().Selectors.First().AttributeRouteModel.Template ==
                          "Action2");
            Assert.IsTrue(
                translatedController.Actions.Skip(1).First().Selectors.Last().AttributeRouteModel.Template == "Action2");
        }
        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 BuildForTranslatedControllerAndUntranslatedActionRoutesReturnsCorrectRouteSelector()
        {
            IRouteSelector routeSelector = new UntranslatedRoutesRouteSelector()
            {
                Culture   = TranslatedRoutesRouteSelectorBuilderTest.Culture,
                Localizer = GetLocalizer(),
            };

            ApplicationModel applicationModel = TestApplicationModel.Instance;

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

            foreach (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizer()).Selectors)
            {
                translatedController.Selectors.Add(selectorModel);
            }

            applicationModel.Controllers.Add(translatedController);

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

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

            Assert.IsTrue(routeSelection.ActionModels.Count == 3);
        }
        public void BuildForUntranslatedControllerAndUntranslatedActionsRoutesReturnsCorrectRouteSelector()
        {
            IRouteSelector routeSelector = new TranslatedRoutesRouteSelector()
            {
                Cultures  = new[] { UntranslatedRoutesRouteSelectorBuilderTest.Culture, UntranslatedRoutesRouteSelectorBuilderTest.Culture2 },
                Localizer = GetLocalizer(),
            };

            ApplicationModel applicationModel = TestApplicationModel.Instance;
            ControllerModel  controllerModel  = applicationModel.Controller1();

            ControllerModel translatedController = controllerModel
                                                   .CreateLocalizedControllerModel(GetLocalizer(),
                                                                                   UntranslatedRoutesRouteSelectorBuilderTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            translatedController = controllerModel
                                   .CreateLocalizedControllerModel(GetLocalizer(),
                                                                   UntranslatedRoutesRouteSelectorBuilderTest.Culture2);

            applicationModel.Controllers.Add(translatedController);

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

            Assert.IsTrue(routeSelections.Count == 0);
        }
Esempio n. 5
0
        public void BuildWithControllerSelectionBuildsCorrectTranslation()
        {
            TranslateControllerRouteProcessor routeProcessor = CreateRouteProcessor();

            routeProcessor.Culture  = TranslateControllerRouteProcessorBuilderTest.Culture;
            routeProcessor.Template = "template";

            ApplicationModel applicationModel = TestApplicationModel.Instance;

            List <RouteSelection> routeSelections = new List <RouteSelection>()
            {
                new RouteSelection()
                {
                    ControllerModel = applicationModel.Controller1(),
                },
            };

            routeProcessor.Process(routeSelections);
            routeProcessor.Process(routeSelections);

            Assert.IsTrue(applicationModel.Controllers.Count(controller => controller.ControllerName == "Controller1") == 2);
            Assert.IsTrue(
                applicationModel.Controllers.Last(controller => controller.ControllerName == "Controller1")
                .Selectors.First()
                .AttributeRouteModel.Template == $"[{TranslateControllerRouteProcessorBuilderTest.CultureKey}]/template");
            Assert.IsTrue(
                applicationModel.Controllers.Last(controller => controller.ControllerName == "Controller1")
                .Selectors.Last()
                .AttributeRouteModel.Template == $"[{TranslateControllerRouteProcessorBuilderTest.CultureKey}]/template");
            Assert.IsTrue(applicationModel.Controllers.Last(controller => controller.ControllerName == "Controller1")
                          .Actions.All(action => action.Selectors.Count == 0));
        }
Esempio n. 6
0
        public void TryGetLocalizedModelForOriginalControllerIfMissingReturnsNull()
        {
            ApplicationModel applicationModel = TestApplicationModel.Instance;
            ControllerModel  controller       = applicationModel.Controller1();

            ControllerModel translatedController =
                controller.TryGetLocalizedModelFor(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

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

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

            ControllerModel translatedController = originalController
                                                   .CreateLocalizedControllerModel(GetLocalizer(),
                                                                                   UntranslatedRoutesRouteSelectorBuilderTest.Culture);

            foreach (ActionModel translatedAction in translatedController.Actions.Take(2))
            {
                foreach (SelectorModel selectorModel in translatedAction.GetOriginalModel(GetLocalizer()).Selectors)
                {
                    translatedAction.Selectors.Add(selectorModel);
                }
            }

            foreach (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizer()).Selectors)
            {
                translatedController.Selectors.Add(selectorModel);
            }

            applicationModel.Controllers.Add(translatedController);

            translatedController = originalController
                                   .CreateLocalizedControllerModel(GetLocalizer(),
                                                                   UntranslatedRoutesRouteSelectorBuilderTest.Culture2);

            foreach (ActionModel translatedAction in translatedController.Actions.Skip(1).Take(2))
            {
                foreach (SelectorModel selectorModel in translatedAction.GetOriginalModel(GetLocalizer()).Selectors)
                {
                    translatedAction.Selectors.Add(selectorModel);
                }
            }

            foreach (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizer()).Selectors)
            {
                translatedController.Selectors.Add(selectorModel);
            }

            applicationModel.Controllers.Add(translatedController);

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

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

            Assert.IsTrue(routeSelection.ActionModels.Count == 1);
        }
Esempio n. 8
0
        public void IsPartiallyTranslatedForOriginalControllerThrowsException()
        {
            ApplicationModel applicationModel     = TestApplicationModel.Instance;
            ControllerModel  controller           = applicationModel.Controller1();
            ControllerModel  translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            bool isPartiallyLocalized = controller.IsPartiallyTranslated(GetLocalizedRouteMarker());
        }
Esempio n. 9
0
        public void TryGetLocalizedModelForLocalizedControllerThrowsException()
        {
            ApplicationModel applicationModel     = TestApplicationModel.Instance;
            ControllerModel  controller           = applicationModel.Controller1();
            ControllerModel  translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            ControllerModel translatedController2 =
                translatedController.TryGetLocalizedModelFor(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);
        }
Esempio n. 10
0
        public void IsPartiallyTranslatedForNotLocalizedControllerReturnsFalse()
        {
            ApplicationModel applicationModel     = TestApplicationModel.Instance;
            ControllerModel  controller           = applicationModel.Controller1();
            ControllerModel  translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            bool isPartiallyLocalized = translatedController.IsPartiallyTranslated(GetLocalizedRouteMarker());

            Assert.IsFalse(isPartiallyLocalized);
        }
Esempio n. 11
0
        public void IsCompletelyTranslatedForOriginalActionThrowsException()
        {
            ApplicationModel applicationModel = TestApplicationModel.Instance;
            ControllerModel  controller       = applicationModel.Controller1();
            ActionModel      action           = controller.Actions.First();

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

            applicationModel.Controllers.Add(translatedController);

            bool isCompletelyLocalized = action.IsCompletelyTranslated(GetLocalizedRouteMarker());
        }
Esempio n. 12
0
        public void GetLocalizedModelForOriginalControllerReturnsLocalizedController()
        {
            ApplicationModel applicationModel     = TestApplicationModel.Instance;
            ControllerModel  controller           = applicationModel.Controller1();
            ControllerModel  translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            ControllerModel translatedController2 =
                controller.GetLocalizedModelFor(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            Assert.AreSame(translatedController, translatedController2);
        }
Esempio n. 13
0
        public void TryGetLocalizedModelForOriginalActionReturnsLocalizedAction()
        {
            ApplicationModel applicationModel = TestApplicationModel.Instance;
            ControllerModel  controller       = applicationModel.Controller1();
            ActionModel      action           = controller.Actions.First();

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

            applicationModel.Controllers.Add(translatedController);

            ActionModel translatedAction2 =
                action.TryGetLocalizedModelFor(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            Assert.AreSame(translatedAction, translatedAction2);
        }
Esempio n. 14
0
        public void IsPartiallyTranslatedForPartiallyLocalizedControllerReturnsTrue()
        {
            ApplicationModel applicationModel     = TestApplicationModel.Instance;
            ControllerModel  controller           = applicationModel.Controller1();
            ControllerModel  translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            applicationModel.Controllers.Add(translatedController);

            foreach (SelectorModel selectorModel in controller.Selectors.Take(1))
            {
                translatedController.Selectors.Add(new SelectorModel(selectorModel));
            }

            bool isPartiallyLocalized = translatedController.IsPartiallyTranslated(GetLocalizedRouteMarker());

            Assert.IsTrue(isPartiallyLocalized);
        }
        public void BuildWithControllerWithoutActionsSelectionThrowsException()
        {
            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(),
                },
            };

            routeProcessor.Process(routeSelections);
        }
Esempio n. 16
0
        public void IsCompletelyTranslatedForCompletelyLocalizedActionReturnsTrue()
        {
            ApplicationModel applicationModel = TestApplicationModel.Instance;
            ControllerModel  controller       = applicationModel.Controller1();
            ActionModel      action           = controller.Actions.First();

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

            applicationModel.Controllers.Add(translatedController);

            foreach (SelectorModel selectorModel in action.Selectors)
            {
                translatedAction.Selectors.Add(new SelectorModel(selectorModel));
            }

            bool isCompletelyLocalized = translatedAction.IsCompletelyTranslated(GetLocalizedRouteMarker());

            Assert.IsTrue(isCompletelyLocalized);
        }
        public void BuildWithControllerActionsSelectionBuildsCorrectProcessor()
        {
            DisableOriginalRouteProcessor routeProcessor = CreateRouteProcessor();

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

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

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

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

            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 (SelectorModel selectorModel in translatedController.GetOriginalModel(GetLocalizedRouteMarker()).Selectors)
            {
                translatedController.Selectors.Add(selectorModel);
            }

            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.First()
                           .Selectors.Last()
                           .ActionConstraints.OfType <NeverAcceptActionContraint>()
                           .Any());
        }