예제 #1
0
        public void Setup()
        {
            RouteCollection routeTable = new RouteCollection();
            RouteConfig.RegisterRoutes(routeTable);
            MVCRouteConfiguration.Initialize(routeTable, typeof(HomeController).Assembly);
            routeGeneration = new MVCRouteGenerator();
            // Generate all routes
            var allReference = new RelativeReference("all.routes", 0)
                {
                    Type = Reference.TypeEnum.Generated
                };
            routeGeneration.Compile(ref allReference);
            allControllers = allReference.Content;
            allControllers.ShouldNotBeEmpty();

            // Generate home routes
            var homeReference = new RelativeReference("home.routes", 0)
            {
                Type = Reference.TypeEnum.Generated
            };
            routeGeneration.Compile(ref homeReference);
            homeController = homeReference.Content;
            homeController.ShouldNotBeEmpty();

            // Generate auth routes
            var authReference = new RelativeReference("auth.routes", 0)
            {
                Type = Reference.TypeEnum.Generated
            };
            routeGeneration.Compile(ref authReference);
            authController = authReference.Content;
            authController.ShouldNotBeEmpty();

            Url = RouteHelper.GetUrlHelper(routeTable);
        }
예제 #2
0
        // recursive function
        private void Parse(DirectoryInfo rootDirectory, String relativePath, RelativeReference relativeReference, ref Dictionary<SystemReference, IList<RelativeReference>> references)
        {
            String currentPath = Path.Combine(rootDirectory.FullName, relativePath);
            SystemReference systemReference = null;
            var modifiedPath = Regex.Replace(relativeReference.ReferenceName, "^~/", "/");
            var referenceIsAbsolutePath = !string.IsNullOrEmpty(relativeReference.ReferenceName) &&
                                          (modifiedPath[0] == '/');
            var filePath = referenceIsAbsolutePath
                               ? Path.Combine(rootDirectory.FullName, modifiedPath.Substring(1))
                               : Path.Combine(currentPath, relativeReference.ReferenceName);
            var fileReference = new FileInfo(filePath);

            // Doesn't really exist, just create the system reference and return
            if (relativeReference.Type == Reference.TypeEnum.Generated)
            {
                systemReference = new SystemReference(rootDirectory, fileReference, relativeReference.ReferenceName) { Type = relativeReference.Type };
                relativeReference.UpdateFromSystemReference(systemReference);
                if (!references.ContainsKey(systemReference))
                {
                    references.Add(systemReference, new List<RelativeReference>());
                }
                return;
            }

            if (fileReference.Exists)
            {
                systemReference = new SystemReference(rootDirectory, fileReference, relativeReference.ReferenceName) { Type = relativeReference.Type };
            }

            if (systemReference == null)
            {
                throw new FileNotFoundException(String.Format("Unable to find the file: '{0}' in the current path: '{1}'.", relativeReference.Name, filePath));
            }

            relativeReference.UpdateFromSystemReference(systemReference);
            // We check for library references here rather than below, because we have the actual file path now
            if (relativeReference.Type == Reference.TypeEnum.Library)
            {
                if (!references.ContainsKey(systemReference))
                {
                    references.Add(systemReference, new List<RelativeReference>());
                }
                return;
            }

            var newRelativeReferences = GetReferences(systemReference, ref references);
            foreach (var reference in newRelativeReferences)
            {
                Parse(rootDirectory, systemReference.Path, reference, ref references);
            }
        }