public void RegisterRoutesIsCalledOnAllServiceRouteMappersEvenWhenSomeThrowExceptions()
        {
            FakeServiceRouteMapper.RegistrationCalls = 0;
            var assembly = new Mock <IAssembly>();

            assembly.Setup(x => x.GetTypes()).Returns(new[]
            {
                typeof(ExceptionOnRegisterServiceRouteMapper),
                typeof(ExceptionOnCreateInstanceServiceRouteMapper),
                typeof(FakeServiceRouteMapper)
            });
            var al = new Mock <IAssemblyLocator>();

            al.Setup(x => x.Assemblies).Returns(new[] { assembly.Object });
            var tl = new TypeLocator {
                AssemblyLocator = al.Object
            };
            var srm = new ServicesRoutingManager(new RouteCollection())
            {
                TypeLocator = tl
            };

            srm.RegisterRoutes();

            Assert.AreEqual(1, FakeServiceRouteMapper.RegistrationCalls);
        }
        public void TwoRoutesOnTheSameFolderHaveSimilarNames()
        {
            //Arrange
            var portalInfo = new ArrayList {
                new PortalInfo {
                    PortalID = 0
                }
            };

            _mockPortalController.Setup(x => x.GetPortals()).Returns(portalInfo);
            var mockPac = new Mock <IPortalAliasController>();

            mockPac.Setup(x => x.GetPortalAliasesByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                    HTTPAlias = "www.foo.com"
                                                                                } });
            PortalAliasController.SetTestableInstance(mockPac.Object);

            var routeCollection = new RouteCollection();
            var srm             = new ServicesRoutingManager(routeCollection);

            //Act
            srm.MapHttpRoute("folder", "default", "url", new[] { "foo" });
            srm.MapHttpRoute("folder", "another", "alt/url", new[] { "foo" });

            //Assert
            var route = (Route)routeCollection[0];

            Assert.AreEqual("folder-default-0", route.DataTokens["Name"]);
            route = (Route)routeCollection[1];
            Assert.AreEqual("folder-another-0", route.DataTokens["Name"]);
        }
        public void NameIsInsertedInRouteDataTokens()
        {
            // Arrange
            var portalInfo = new ArrayList {
                new PortalInfo {
                    PortalID = 0
                }
            };

            this.mockPortalController.Setup(x => x.GetPortals()).Returns(portalInfo);

            this.mockPortalAliasService.Setup(x => x.GetPortalAliasesByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                                        HTTPAlias = "www.foo.com"
                                                                                                    } });
            this.mockPortalAliasService.As <IPortalAliasController>().Setup(x => x.GetPortalAliasesByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                                                                      HTTPAlias = "www.foo.com"
                                                                                                                                  } });

            var routeCollection = new RouteCollection();
            var srm             = new ServicesRoutingManager(routeCollection);

            // Act
            srm.MapHttpRoute("folder", "default", "url", new[] { "foo" });

            // Assert
            var route = (Route)routeCollection[0];

            Assert.AreEqual("folder-default-0", route.DataTokens["Name"]);
        }
        public void RoutesShouldHaveBackwardCompability()
        {
            // Arrange
            var portalInfo = new ArrayList {
                new PortalInfo {
                    PortalID = 0
                }
            };

            this._mockPortalController.Setup(x => x.GetPortals()).Returns(portalInfo);
            var mockPac = new Mock <IPortalAliasController>();

            mockPac.Setup(x => x.GetPortalAliasesByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                    HTTPAlias = "www.foo.com"
                                                                                } });
            PortalAliasController.SetTestableInstance(mockPac.Object);

            var routeCollection = new RouteCollection();
            var srm             = new ServicesRoutingManager(routeCollection);

            // Act
            srm.MapHttpRoute("folder", "default", "url", new[] { "foo" });

            // Assert
            var route = (Route)routeCollection[0];

            Assert.AreEqual("folder-default-0", route.DataTokens["Name"]);
            route = (Route)routeCollection[1];
            Assert.AreEqual("folder-default-0-old", route.DataTokens["Name"]);
            Assert.IsTrue(route.Url.StartsWith("DesktopModules"));
        }
        public void UrlCanStartWithSlash()
        {
            //Arrange
            _mockPortalController.Setup(x => x.GetPortals()).Returns(new ArrayList());

            //Act
            var srm = new ServicesRoutingManager(new RouteCollection());

            //Assert
            Assert.DoesNotThrow(() => srm.MapHttpRoute("name", "default", "/url", null, new[] { "foo" }));
        }
        public void NameSpaceRequiredOnMapRouteCalls([ValueSource("_emptyStringArrays")] string[] namespaces)
        {
            var srm = new ServicesRoutingManager(new RouteCollection());

            Assert.Throws <ArgumentException>(() => srm.MapHttpRoute("usm", "default", "url", null, namespaces));
        }
        public void UniqueNameRequiredOnMapRouteCalls(string uniqueName)
        {
            var srm = new ServicesRoutingManager(new RouteCollection());

            Assert.Throws <ArgumentException>(() => srm.MapHttpRoute(uniqueName, "default", "url", null, new[] { "foo" }));
        }
        public void RegisterRoutesIsCalledOnAllServiceRouteMappersEvenWhenSomeThrowExceptions()
        {
            FakeServiceRouteMapper.RegistrationCalls = 0;
            var assembly = new Mock<IAssembly>();
            assembly.Setup(x => x.GetTypes()).Returns(new[]
                                                          {
                                                              typeof (ExceptionOnRegisterServiceRouteMapper),
                                                              typeof (ExceptionOnCreateInstanceServiceRouteMapper),
                                                              typeof (FakeServiceRouteMapper)
                                                          });
            var al = new Mock<IAssemblyLocator>();
            al.Setup(x => x.Assemblies).Returns(new[] {assembly.Object});
            var tl = new TypeLocator {AssemblyLocator = al.Object};
            var srm = new ServicesRoutingManager(new RouteCollection()) {TypeLocator = tl};

            srm.RegisterRoutes();

            Assert.AreEqual(1, FakeServiceRouteMapper.RegistrationCalls);
        }
        public void NameSpaceRequiredOnMapRouteCalls([ValueSource("_emptyStringArrays")] string[] namespaces)
        {
            var srm = new ServicesRoutingManager(new RouteCollection());

            Assert.Throws<ArgumentException>(() => srm.MapHttpRoute("usm", "default", "url", null, namespaces));
        }
        public void TwoRoutesOnTheSameFolderHaveSimilarNames()
        {
            //Arrange
            var portalInfo = new ArrayList { new PortalInfo { PortalID = 0 } };
            _mockPortalController.Setup(x => x.GetPortals()).Returns(portalInfo);
            var mockPac = new Mock<IPortalAliasController>();
            mockPac.Setup(x => x.GetPortalAliasesByPortalId(0)).Returns(new[] { new PortalAliasInfo { HTTPAlias = "www.foo.com" } });
            PortalAliasController.SetTestableInstance(mockPac.Object);

            var routeCollection = new RouteCollection();
            var srm = new ServicesRoutingManager(routeCollection);

            //Act
            srm.MapHttpRoute("folder", "default", "url", new[] { "foo" });
            srm.MapHttpRoute("folder", "another", "alt/url", new[] { "foo" });

            //Assert
            var route = (Route)routeCollection[0];
            Assert.AreEqual("folder-default-0", route.DataTokens["Name"]);
            route = (Route)routeCollection[1];
            Assert.AreEqual("folder-another-0", route.DataTokens["Name"]);
        }
        public void UrlCanStartWithSlash()
        {
            //Arrange
            _mockPortalController.Setup(x => x.GetPortals()).Returns(new ArrayList());
            
            //Act
            var srm = new ServicesRoutingManager(new RouteCollection());

            //Assert
            Assert.DoesNotThrow(() => srm.MapHttpRoute("name", "default", "/url", null, new[] { "foo" }));
        }
        public void UniqueNameRequiredOnMapRouteCalls(string uniqueName)
        {
            var srm = new ServicesRoutingManager(new RouteCollection());

            Assert.Throws<ArgumentException>(() => srm.MapHttpRoute(uniqueName, "default", "url", null, new[] { "foo" }));
        }