// For testing purpose
        internal static VirtualPathFactoryManager CreateFromLambda(string virtualPath, Func <string, Type, object> createInstanceMethod)
        {
            // Create a VirtualPathFactoryManager that knows about a single path/factory
            var virtualPathFactoryManager = new VirtualPathFactoryManager(null);
            var factory = new DictionaryBasedVirtualPathFactory();

            factory.RegisterPath(virtualPath, () => createInstanceMethod(virtualPath, typeof(object)));
            virtualPathFactoryManager.RegisterVirtualPathFactoryInternal(factory);
            return(virtualPathFactoryManager);
        }
예제 #2
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)));
        }
        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
            Assert.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.Equal(registry[assembly], part);
        }
예제 #5
0
        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.AreEqual(registry["my-assembly"], part);
            Assert.AreEqual(registry["MY-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");

            Assert.Throws <InvalidOperationException>(() => registry.Register(newPart, myFunc),
                                                      "An application module is already registered for virtual path \"~/mymodule/\".");
        }
        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.True(dictionary.Exists("~/mymodule/Page1"));
            Assert.Equal(dictionary.CreateInstance("~/mymodule/Page1"), "foo");
            Assert.False(dictionary.Exists("~/mymodule/Page2"));
            Assert.False(dictionary.Exists("~/mymodule/Page3"));
        }