public ApplicationPartRegistry(DictionaryBasedVirtualPathFactory pathFactory)
 {
     _applicationParts       = new ConcurrentDictionary <IResourceAssembly, ApplicationPart>();
     _registeredVirtualPaths = new ConcurrentDictionary <string, bool>(
         StringComparer.OrdinalIgnoreCase
         );
     _virtualPathFactory = pathFactory;
 }
        public void RegisterThrowsIfAssemblyAlreadyRegistered() {
            // Arrange
            var part = new ApplicationPart(BuildAssembly(), "~/mymodule");
            var dictionary = new DictionaryBasedVirtualPathFactory();
            var registry = new ApplicationPartRegistry(dictionary);
            Func<object> myFunc = () => "foo";

            // Act
            registry.Register(part, myFunc);

            // Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => registry.Register(part, myFunc),
                String.Format("The assembly \"{0}\" is already registered.", part.Assembly.ToString()));
        }
        public void ApplicationPartRegistryLooksUpPartsByAssembly() {
            // Arrange
            var assembly = BuildAssembly();
            var part = new ApplicationPart(assembly, "~/mymodule");
            var dictionary = new DictionaryBasedVirtualPathFactory();
            var registry = new ApplicationPartRegistry(dictionary);
            Func<object> myFunc = () => "foo";

            // Act
            registry.Register(part, myFunc);

            // Assert
            Assert.AreEqual(registry[assembly], part);
        }
        public void RegisterThrowsIfPathAlreadyRegistered() {
            // Arrange
            var part = new ApplicationPart(BuildAssembly(), "~/mymodule");
            var dictionary = new DictionaryBasedVirtualPathFactory();
            var registry = new ApplicationPartRegistry(dictionary);
            Func<object> myFunc = () => "foo";

            // Act
            registry.Register(part, myFunc);

            // Assert
            var newPart = new ApplicationPart(BuildAssembly("different-assembly"), "~/mymodule");
            ExceptionAssert.Throws<InvalidOperationException>(() => registry.Register(newPart, myFunc),
                "An application module is already registered for virtual path \"~/mymodule/\".");
        }
        public void ApplicationPartRegistryLooksUpPartsByName()
        {
            // Arrange
            var part = new ApplicationPart(BuildAssembly(), "~/mymodule");
            var dictionary = new DictionaryBasedVirtualPathFactory();
            var registry = new ApplicationPartRegistry(dictionary);
            Func<object> myFunc = () => "foo";

            // Act
            registry.Register(part, myFunc);

            // Assert
            Assert.Equal(registry["my-assembly"], part);
            Assert.Equal(registry["MY-aSSembly"], part);
        }
 public ApplicationPartRegistry(DictionaryBasedVirtualPathFactory pathFactory)
 {
     _applicationParts = new ConcurrentDictionary<IResourceAssembly, ApplicationPart>();
     _registeredVirtualPaths = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
     _virtualPathFactory = pathFactory;
 }
        public void RegisterCreatesRoutesForValidPages() {
            // Arrange
            var part = new ApplicationPart(BuildAssembly(), "~/mymodule");
            var dictionary = new DictionaryBasedVirtualPathFactory();
            var registry = new ApplicationPartRegistry(dictionary);
            Func<object> myFunc = () => "foo";

            // Act
            registry.Register(part, myFunc);

            // Assert
            Assert.IsTrue(dictionary.Exists("~/mymodule/Page1"));
            Assert.AreEqual(dictionary.CreateInstance("~/mymodule/Page1"), "foo");
            Assert.IsFalse(dictionary.Exists("~/mymodule/Page2"));
            Assert.IsFalse(dictionary.Exists("~/mymodule/Page3"));
        }
Ejemplo n.º 8
0
        private static void InitApplicationParts() {
            // Register the virtual path factory
            var virtualPathFactory = new DictionaryBasedVirtualPathFactory();
            VirtualPathFactoryManager.RegisterVirtualPathFactory(virtualPathFactory);

            // Intantiate the part registry
            _partRegistry = new ApplicationPartRegistry(virtualPathFactory);

            // Register the resource route
            RouteTable.Routes.Add(new Route(ResourceRoute, new ResourceRouteHandler(_partRegistry)));
        }