コード例 #1
0
        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()));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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/\".");
        }
コード例 #4
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.Equal(registry["my-assembly"], part);
            Assert.Equal(registry["MY-aSSembly"], part);
        }
コード例 #5
0
 public ResourceRouteHandler(ApplicationPartRegistry partRegistry)
 {
     _partRegistry = partRegistry;
 }
コード例 #6
0
        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"));
        }
コード例 #7
0
 public ResourceRouteHandler(ApplicationPartRegistry partRegistry) {
     _partRegistry = partRegistry;
 }
コード例 #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)));
        }