Esempio n. 1
0
        public void IsCompletelyTranslatedForOriginalControllerThrowsException()
        {
            ApplicationModel applicationModel     = TestApplicationModel.Instance;
            ControllerModel  controller           = applicationModel.Controller1();
            ControllerModel  translatedController =
                controller.CreateLocalizedControllerModel(GetLocalizedRouteMarker(), ModelExtensionTest.Culture);

            applicationModel.Controllers.Add(translatedController);

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

            applicationModel.Controllers.Add(translatedController);

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

            Assert.IsFalse(isCompletelyLocalized);
        }
        public override void Process(ICollection <RouteSelection> routeSelections)
        {
            // Expect single ControllerModel with ActionModels selection
            routeSelections.ThrowIfNotSingleControllerWithActionsSelection(RouteTranslationConfiguration.Localizer);

            RouteSelection            routeSelection          = routeSelections.Single();
            ControllerModel           originalControllerModel = routeSelection.ControllerModel;
            ICollection <ActionModel> originalActionModels    = routeSelection.ActionModels;

            // Expect original ControllerModel & attribute routed action routes
            originalControllerModel.ThrowIfNotOriginalModel(RouteTranslationConfiguration.Localizer);
            originalActionModels.ThrowIfNotPartOfModel(originalControllerModel);
            originalActionModels.ThrowIfNotModelsWithAttributeRoutes(RouteTranslationConfiguration.Localizer);

            ControllerModel translatedControllerModel = EnsureAndGetLocalizedControllerModel(originalControllerModel, Culture);

            if (originalControllerModel.HasAttributeRoutes() &&
                !translatedControllerModel.IsCompletelyTranslated(RouteTranslationConfiguration.Localizer))
            {
                Logger.LogWarning("Action was translated before Controller. Don't forget to translate on controller level.");
            }

            IList <ActionModel> translatedActionModels = originalActionModels
                                                         .Select(action => action.GetLocalizedModelFor(RouteTranslationConfiguration.Localizer, Culture))
                                                         .ToList();

            System.Threading.Thread.Sleep(5000);

            // Expect at least one untranslated attribute route with the same template for each ActionModel
            translatedActionModels.ThrowIfAnyCompletelyTranslated(RouteTranslationConfiguration.Localizer);
            originalActionModels.ThrowIfAnyUntranslatedTemplateDiffer(RouteTranslationConfiguration.Localizer, Culture);

            // Translate
            foreach (var originalActionModel in originalActionModels.Select((model, index) => new
            {
                Model = model,
                Index = index,
            }))
            {
                ActionModel translatedActionModel = translatedActionModels[originalActionModel.Index];

                TranslateActionRoute(translatedActionModel,
                                     originalActionModel.Model.Selectors[translatedActionModel.Selectors.Count], Template, Culture);
            }
        }
Esempio n. 4
0
        public void IsCompletelyTranslatedForCompletelyLocalizedControllerReturnsTrue()
        {
            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)
            {
                translatedController.Selectors.Add(new SelectorModel(selectorModel));
            }

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

            Assert.IsTrue(isCompletelyLocalized);
        }