public static void Initialize()
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Initializing the URL rewriter."))
            {

                if (StateAccess.IsInitialized && ProjectionState.IsInitialized)
                {
                    string url = new ProjectionMapper().GetInternalPath(HttpContext.Current.Request.Url.ToString());

                    HttpContext.Current.Items["OriginalUrl"] = HttpContext.Current.Request.Url.ToString();

                    if (url != null && url != String.Empty)
                    {
                        //HttpContext.Current.Server.Execute(url, true);
                        HttpContext.Current.RewritePath(url, false); // Pass false parameter to ensure the form post back path is correct.
                    }
                }
                else
                    new SetupChecker().Check();
            }
        }
        public void Test_GetCommandName_XmlProjection()
        {
            string fullApplicationUrl = "http://localhost/MockApplication";
            string applicationPath = "/MockApplication";

            string action = "Index";
            string typeName = "TestUser";

            string original = fullApplicationUrl + "/" + action + "-" + typeName + ".xml.aspx?TestKey=TestValue&TestKey2=TestValue2";

            string expected = action + "-" + typeName;

            ProjectionMapper mapper = new ProjectionMapper();
            mapper.ApplicationPath = applicationPath;
            mapper.Converter = new MockUrlConverter();
            mapper.FileMapper = new MockFileMapper(this);
            mapper.FileExistenceChecker = new MockFileExistenceChecker(this, false);

            string cmd = mapper.GetCommandName(original);

            Assert.AreEqual(expected, cmd, "Result doesn't match expected.");
        }
        public void Test_GetDynamicID()
        {
            Guid expectedID = new Guid("2a7ecbc7-b22c-4bca-908f-955f7a59ef51");

            string originalUrl = "http://localhost/MockApplication/Edit-UserRole/" + expectedID.ToString() + "/Administrator.aspx";

            ProjectionMapper mapper = new ProjectionMapper();
            mapper.Converter = new MockUrlConverter();

            string shortPath = mapper.GetShortPath(originalUrl);

            Guid foundID = mapper.GetDynamicID(originalUrl);

            Assert.AreEqual(expectedID.ToString(), foundID.ToString(), "ID doesn't match expected.");
        }
        public void Test_GetInternalPath_Skip()
        {
            string fullApplicationUrl = "http://localhost/MockApplication";
            string applicationPath = "/MockApplication";

            string original = fullApplicationUrl + "/Admin/Setup.aspx";

            string expected = "";

            ProjectionMapper mapper = new ProjectionMapper();
            mapper.ApplicationPath = applicationPath;
            mapper.Converter = new MockUrlConverter();
            mapper.FileMapper = new MockFileMapper(this);
            mapper.FileExistenceChecker = new MockFileExistenceChecker(this, true);

            string generated = mapper.GetInternalPath(original);

            Assert.AreEqual(expected.ToLower(), generated.ToLower(), "Result doesn't match expected.");
        }
        public void Test_GetInternalPath_ProjectionName_KeepExistingQueryStrings()
        {
            string fullApplicationUrl = "http://localhost/MockApplication";
            string applicationPath = "/MockApplication";

            string original = fullApplicationUrl + "/Settings.aspx?TestKey=TestValue";

            string expected = applicationPath + "/Projector.aspx?n=Settings&f=Html&TestKey=TestValue";

            // Create the mock settings projection
            ProjectionInfo info = new ProjectionInfo();
            info.Name = "Settings";
            ProjectionState.Projections.Add(info);

            ProjectionMapper mapper = new ProjectionMapper();
            mapper.ApplicationPath = applicationPath;
            mapper.Converter = new MockUrlConverter();
            mapper.FileMapper = new MockFileMapper(this);
            mapper.FileExistenceChecker = new MockFileExistenceChecker(this, false);

            string generated = mapper.GetInternalPath(original);

            Assert.AreEqual(expected.ToLower(), generated.ToLower(), "Result doesn't match expected.");
        }
        public void Test_GetInternalPath_Action_Type_KeepOriginalQueryStrings()
        {
            string fullApplicationUrl = "http://localhost/MockApplication";
            string applicationPath = "/MockApplication";

            string action = "Edit";
            string typeName = "TestUser";

            string original = fullApplicationUrl + "/" + action + "-" + typeName + ".aspx?TestKey=TestValue";

            string expected = applicationPath + "/Projector.aspx?a=" + action + "&t=" + typeName + "&f=Html&TestKey=TestValue";

            ProjectionMapper mapper = new ProjectionMapper();
            mapper.ApplicationPath = applicationPath;
            mapper.Converter = new MockUrlConverter();
            mapper.FileMapper = new MockFileMapper(this);
            mapper.FileExistenceChecker = new MockFileExistenceChecker(this, false);

            string generated = mapper.GetInternalPath(original);

            Assert.AreEqual(expected.ToLower(), generated.ToLower(), "Result doesn't match expected.");
        }
        public void Test_GetInternalPath_Action_Type_ID_Key()
        {
            string entityName = "TestUsername";
            string entityID = "A1FC7BA3-3832-467f-8989-058BF420D1D9";

            string fullApplicationUrl = "http://localhost/MockApplication";
            string applicationPath = "/MockApplication";

            string action = "Edit";
            string typeName = "TestUser";

            string original = fullApplicationUrl + "/" + action + "-" + typeName + "/" + entityID + "/K--" + entityName + ".aspx";

            string expected = applicationPath + "/Projector.aspx?a=" + action + "&t=" + typeName + "&f=Html&" + typeName + "-ID=" + entityID + "&" + typeName + "-UniqueKey=" + entityName;

            ProjectionMapper mapper = new ProjectionMapper();
            mapper.Converter = new MockUrlConverter();
            mapper.FileMapper = new MockFileMapper(this);
            mapper.FileExistenceChecker = new MockFileExistenceChecker(this, false);

            string generated = mapper.GetInternalPath(original);

            Assert.AreEqual(expected.ToLower(), generated.ToLower(), "Result doesn't match expected.");
        }
        public void Test_GetFormat_Xslt()
        {
            ProjectionMapper mapper = new ProjectionMapper();

            string fileName = "TestPage.xslt.aspx";

            ProjectionFormat format = mapper.GetFormat(fileName);

            Assert.AreEqual(ProjectionFormat.Xslt, format, "Doesn't match what is expected.");
        }