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 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 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"));
        }
        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/\".");
        }