Exemple #1
0
        public void Combine_EmptyTemplates(string left, string right, string expected)
        {
            // Arrange & Act
            var combined = AttributeRouteModel.CombineTemplates(left, right);

            // Assert
            Assert.Equal(expected, combined);
        }
Exemple #2
0
        public void Combine_RightOverridesReflectedAttributeRouteModel(
            AttributeRouteModel left,
            AttributeRouteModel right)
        {
            // Arrange
            var expectedTemplate = AttributeRouteModel.CombineTemplates(null, right.Template);

            // Act
            var combined = AttributeRouteModel.CombineAttributeRouteModel(left, right);

            // Assert
            Assert.NotNull(combined);
            Assert.Equal(expectedTemplate, combined.Template);
            Assert.Equal(combined.Order, right.Order);
        }
        internal static PageConventionCollection AddAreaFolderRouteInternal(this PageConventionCollection conventions,
                                                                            string areaName, string folderPath, string folderRoute, bool isAdmin)
        {
            conventions.AddAreaFolderRouteModelConvention(areaName, folderPath, model =>
            {
                if (isAdmin != (model.ViewEnginePath.Contains("/Admin/") || model.Properties.ContainsKey("Admin")))
                {
                    return;
                }

                var areaFolder = areaName + folderPath;

                foreach (var selector in model.Selectors.ToArray())
                {
                    var route = selector.AttributeRouteModel;

                    if (route.Template.StartsWith(areaFolder, StringComparison.Ordinal) || (route.Template == areaName && folderPath == "/"))
                    {
                        route.SuppressLinkGeneration = true;

                        string template;

                        if (route.Template == areaName && folderPath == "/")
                        {
                            template = folderRoute;
                        }
                        else
                        {
                            var cleanSubTemplate = route.Template.Substring(areaFolder.Length).TrimStart('/');
                            template             = AttributeRouteModel.CombineTemplates(folderRoute, cleanSubTemplate);
                        }

                        model.Selectors.Add(new SelectorModel
                        {
                            AttributeRouteModel = new AttributeRouteModel
                            {
                                Template = template
                            }
                        });
                    }
                }
            });

            return(conventions);
        }