/// <summary>
        /// Generate WebAPI Links compatible with DNN Services Framework
        /// </summary>
        /// <param name="urlHelper">The UrlHelper</param>
        /// <param name="moduleFolderName">ModuleFolderName for the route</param>
        /// <param name="routeName">RouteName for the route</param>
        /// <param name="routeValues">Values to be passed to the route</param>
        /// <param name="portalAliasInfo">The PortalAlias to use in the Url </param>
        /// <returns>a url</returns>
        public static string DnnLink(this UrlHelper urlHelper, string moduleFolderName, string routeName, object routeValues, PortalAliasInfo portalAliasInfo)
        {
            var parm = new PortalAliasRouteManager();
            var fullName = parm.GetRouteName(moduleFolderName, routeName, PortalController.Instance.GetCurrentPortalSettings().PortalAlias);
            HttpRouteValueDictionary allRouteValues = parm.GetAllRouteValues(portalAliasInfo, routeValues);

            return urlHelper.Link(fullName, allRouteValues);
        }
Пример #2
0
        /// <summary>
        /// Generate WebAPI Links compatible with Hotcakes Commerce Services Framework
        /// </summary>
        /// <param name="urlHelper">The UrlHelper</param>
        /// <param name="moduleFolderName">ModuleFolderName for the route</param>
        /// <param name="routeName">RouteName for the route</param>
        /// <param name="routeValues">Values to be passed to the route</param>
        /// <param name="portalAliasInfo">The PortalAlias to use in the Url </param>
        /// <returns>a url</returns>
        public static string DnnLink(this UrlHelper urlHelper, string moduleFolderName, string routeName, object routeValues, PortalAliasInfo portalAliasInfo)
        {
            var parm     = new PortalAliasRouteManager();
            var fullName = parm.GetRouteName(moduleFolderName, routeName, PortalController.Instance.GetCurrentPortalSettings().PortalAlias);
            HttpRouteValueDictionary allRouteValues = parm.GetAllRouteValues(portalAliasInfo, routeValues);

            return(urlHelper.Link(fullName, allRouteValues));
        }
        public void GetRouteUrl(string moduleFolderName, string url, int count, string expected)
        {
            //Arrange


            //Act
            string result = new PortalAliasRouteManager().GetRouteUrl(moduleFolderName, url, count);

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void ParentPortalOnVirtualDirReturnsAnEmptyPrefix()
        {
            //Arrange
            var mockPortalController = new Mock<IPortalController>();
            var portals = new ArrayList {new PortalInfo {PortalID = 1}};
            mockPortalController.Setup(x => x.GetPortals()).Returns(portals);
            PortalController.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"}});
            PortalAliasController.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);
        }
        public void GetAllRouteValuesExtractsChildPortalParams()
        {
            //Arrange
            

            //Act
            var result =
                new PortalAliasRouteManager().GetAllRouteValues(new PortalAliasInfo {HTTPAlias = "ce.lvh.me/child"},
                                                                   null);

            //Assert
            var expected = new Dictionary<string, object> { { "prefix0", "child" } };
            CollectionAssert.AreEquivalent(expected, result);
        }
        public void GetAllRouteValuesExtractsManyChildPortalParamsAndPreservesRouteValues()
        {
            //Arrange


            //Act
            var result =
                new PortalAliasRouteManager().GetAllRouteValues(new PortalAliasInfo { HTTPAlias = "ce.lvh.me/child0/child1/child2/child3" },
                                                                   new {value1 = 1, value2 = 2});

            //Assert
            var expected = new Dictionary<string, object> { { "prefix0", "child0" }, { "prefix1", "child1" }, { "prefix2", "child2" }, { "prefix3", "child3" }, { "value1", 1}, {"value2", 2} };
            CollectionAssert.AreEquivalent(expected, result);
        }
        public void GetAllRouteValuesPreservesPassedInRouteValues()
        {
            //Arrange
            

            //Act
            var result = new PortalAliasRouteManager().GetAllRouteValues(new PortalAliasInfo {HTTPAlias = ""},
                                                               new {value1 = 1, value2 = 2});

            //Assert
            var expected = new Dictionary<string, object> {{"value1", 1}, {"value2", 2}};
            CollectionAssert.AreEquivalent(expected, result);
        }
        public void GetRouteNameWithPortalAliasInfoHashesNameInCorrectFormat(string moduleFolderName, string routeName, string httpAlias, string expected)
        {
            //Arrange


            //Act
            var result = new PortalAliasRouteManager().GetRouteName(moduleFolderName, routeName, new PortalAliasInfo {HTTPAlias = httpAlias});

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void GetRouteNameHashesNameInCorrectFormat(string moduleFolderName, string routeName, int count, string expected)
        {
            //Arrange
            

            //Act
            var result = new PortalAliasRouteManager().GetRouteName(moduleFolderName, routeName, count);

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void PrefixCountsCacheCanBeCleared()
        {
            //Arrange
            var mockPortalController = new Mock<IPortalController>();
            var portals = new ArrayList { new PortalInfo { PortalID = 1 } };
            mockPortalController.Setup(x => x.GetPortals()).Returns(portals);
            PortalController.SetTestableInstance(mockPortalController.Object);

            var mockPortalAliasController = new Mock<IPortalAliasController>();
            mockPortalAliasController.Setup(x => x.GetPortalAliasesByPortalId(It.IsAny<int>())).Returns(new[] { new PortalAliasInfo { HTTPAlias = "valid.lvh.me" } });
            PortalAliasController.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));
        }
        public void VirtralDirWithChildPortalHasABlankAndASinglePrefix()
        {
            //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"},
                    new PortalAliasInfo {HTTPAlias = "valid.lvh.me/vdir/child"}
                });
            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.AreEqual(new[] {1, 0}, prefixes);
        }