Beispiel #1
0
        public void NameIsInsertedInRouteDataTokens()
        {
            //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.GetPortalAliasByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                  HTTPAlias = "www.foo.com"
                                                                              } });
            TestablePortalAliasController.SetTestableInstance(mockPac.Object);

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

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

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

            Assert.AreEqual("folder-route0-instance0", route.DataTokens["Name"]);
        }
        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"
                                                                                } });
            TestablePortalAliasController.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"]);
        }
Beispiel #3
0
        public void VirtualDirOnlyMakesRouteWithNoWildcardPrefix()
        {
            //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.GetPortalAliasByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                  HTTPAlias = "www.foo.com/vdir"
                                                                              } });
            TestablePortalAliasController.SetTestableInstance(mockPac.Object);

            var mockGlobals = new Mock <IGlobals>();

            mockGlobals.Setup(x => x.ApplicationPath).Returns("/vdir");
            TestableGlobals.SetTestableInstance(mockGlobals.Object);

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

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

            //Assert
            Assert.AreEqual(1, routeCollection.Count);
            var route = (Route)routeCollection[0];

            StringAssert.DoesNotStartWith("{", route.Url);
        }
Beispiel #4
0
        public void SimpleDomainMakes1Route()
        {
            //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.GetPortalAliasByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                  HTTPAlias = "www.foo.com"
                                                                              } });
            TestablePortalAliasController.SetTestableInstance(mockPac.Object);

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

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

            //Assert
            Assert.AreEqual(1, routeCollection.Count);
        }
Beispiel #5
0
        public void ParentPortalOnVirtualDirReturnsAnEmptyPrefix()
        {
            //Arrange
            var mockPortalController = new Mock <IPortalController>();
            var portals = new ArrayList {
                new PortalInfo {
                    PortalID = 1
                }
            };

            mockPortalController.Setup(x => x.GetPortals()).Returns(portals);
            TestablePortalController.SetTestableInstance(mockPortalController.Object);

            var mockPortalAliasController = new Mock <IPortalAliasController>();

            mockPortalAliasController.Setup(x => x.GetPortalAliasesByPortalId(It.IsAny <int>())).Returns(new[]
                                                                                                         { new PortalAliasInfo {
                                                                                                               HTTPAlias = "valid.lvh.me/vdir"
                                                                                                           } });
            TestablePortalAliasController.SetTestableInstance(mockPortalAliasController.Object);

            var mockGlobals = new Mock <IGlobals>();

            mockGlobals.Setup(x => x.ApplicationPath).Returns("/vdir");
            TestableGlobals.SetTestableInstance(mockGlobals.Object);

            //Act
            List <int> prefixes = new PortalAliasRouteManager().GetRoutePrefixCounts().ToList();

            //Assert
            CollectionAssert.AreEquivalent(new[] { 0 }, prefixes);
        }
Beispiel #6
0
        public void PrefixCountsCacheCanBeCleared()
        {
            //Arrange
            var mockPortalController = new Mock <IPortalController>();
            var portals = new ArrayList {
                new PortalInfo {
                    PortalID = 1
                }
            };

            mockPortalController.Setup(x => x.GetPortals()).Returns(portals);
            TestablePortalController.SetTestableInstance(mockPortalController.Object);

            var mockPortalAliasController = new Mock <IPortalAliasController>();

            mockPortalAliasController.Setup(x => x.GetPortalAliasesByPortalId(It.IsAny <int>())).Returns(new[] { new PortalAliasInfo {
                                                                                                                     HTTPAlias = "valid.lvh.me"
                                                                                                                 } });
            TestablePortalAliasController.SetTestableInstance(mockPortalAliasController.Object);

            var mockGlobals = new Mock <IGlobals>();

            mockGlobals.Setup(x => x.ApplicationPath).Returns("");
            TestableGlobals.SetTestableInstance(mockGlobals.Object);

            //Act
            var parm = new PortalAliasRouteManager();

            parm.GetRoutePrefixCounts();
            parm.ClearCachedData();
            parm.GetRoutePrefixCounts();

            //Assert
            mockPortalController.Verify(x => x.GetPortals(), Times.Exactly(2));
        }
Beispiel #7
0
        public void VirtualDirWithChild()
        {
            //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.GetPortalAliasByPortalId(0)).Returns(new[] { new PortalAliasInfo {
                                                                                  HTTPAlias = "www.foo.com/vdir"
                                                                              }, new PortalAliasInfo {
                                                                                  HTTPAlias = "www.foo.com/vdir/child"
                                                                              } });
            TestablePortalAliasController.SetTestableInstance(mockPac.Object);

            var mockGlobals = new Mock <IGlobals>();

            mockGlobals.Setup(x => x.ApplicationPath).Returns("/vdir");
            TestableGlobals.SetTestableInstance(mockGlobals.Object);

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

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

            //Assert
            Assert.AreEqual(2, routeCollection.Count);
            var urls = routeCollection.Cast <Route>().Select(x => x.Url).ToList();

            Assert.AreEqual(1, urls.Count(x => x.Contains("{prefix0}")));
            //if 2 urls and only 1 has prefix 0 then the other has no prefixesed wcon
        }