protected void Application_Start(object sender, EventArgs e)
        {
            var webFormsToWebFormsRoute = FeatureToggleRouteBuilder.WithUrl("test")
                                          .WithFeatureToogle((r) => r.HttpContext.Request.IsSecureConnection)
                                          .WithCurrentPageRoute("~/WebForm1.aspx")
                                          .WithExperimentalPageRoute("~/WebForm2.aspx")
                                          .Build();

            RouteTable.Routes.Add(webFormsToWebFormsRoute);

            var webFormsToMvcRoute = FeatureToggleRouteBuilder.WithUrl("offers/offer-{title}_{id}")
                                     .WithFeatureToogle((r) => r.HttpContext.Request.IsSecureConnection)
                                     .WithCurrentPageRoute("~/Pages/Offers/Details.aspx", true, null, new { id = @"\d+" })
                                     .WithExperimentalMvcRoute(
                defaults: new { controller = "Offers", action = "Details" },
                constraints: new { id = @"\d+" })
                                     .Build();

            RouteTable.Routes.Add("OfferDetails", webFormsToMvcRoute);

            var mvcToMvcRoute = FeatureToggleRouteBuilder.WithUrl("job/job-list")
                                .WithFeatureToogle((r) => r.HttpContext.Request.IsSecureConnection)
                                .WithCurrentMvcRoute(new { controller = "Offers", action = "List" })
                                .WithExperimentalMvcRoute(new { controller = "OffersV2", action = "List" })
                                .Build();

            RouteTable.Routes.Add("OfferList", mvcToMvcRoute);
        }
        public void FeatureToggleRouteBuilderTest_WebFormsToMvc()
        {
            var defaultsCurrent = new RouteValueDictionary()
            {
                { "culture", "en-US" }
            };
            var defaultsConstraints = new RouteValueDictionary()
            {
                { "id", @"\d+" }
            };
            var defaultDataTokens = new RouteValueDictionary()
            {
                { "route-name", "test" }
            };
            var experimentalDefaults = new RouteValueDictionary()
            {
                { "controller", "Home" }, { "action", "Index" }
            };

            var route = FeatureToggleRouteBuilder.WithUrl("test")
                        .WithFeatureToogle((r) => true)
                        .WithCurrentPageRoute("~/WebForms1.aspx", false, defaultsCurrent, defaultsConstraints, defaultDataTokens)
                        .WithExperimentalMvcRoute(experimentalDefaults)
                        .Build();

            Assert.That(route, Is.Not.Null);
            Assert.That(route, Is.InstanceOf <FeatureToggleRoute>());

            var ftRoute = (FeatureToggleRoute)route;

            Assert.That(ftRoute.RouteHandler, Is.Null);

            Assert.That(ftRoute.CurrentRouteProperties.Defaults, Is.EqualTo(defaultsCurrent));
            Assert.That(ftRoute.CurrentRouteProperties.Constraints, Is.EqualTo(defaultsConstraints));
            Assert.That(ftRoute.CurrentRouteProperties.DataTokens, Is.EqualTo(defaultDataTokens));
            Assert.That(ftRoute.CurrentRouteProperties.RouteHandler, Is.InstanceOf <PageRouteHandler>());
            var currentRouteHandler = (PageRouteHandler)ftRoute.CurrentRouteProperties.RouteHandler;

            Assert.That(currentRouteHandler.CheckPhysicalUrlAccess, Is.False);
            Assert.That(currentRouteHandler.VirtualPath, Is.EqualTo("~/WebForms1.aspx"));

            Assert.That(ftRoute.ExperimentalRouteProperties.Defaults, Is.EqualTo(experimentalDefaults));
            Assert.That(ftRoute.ExperimentalRouteProperties.Constraints, Is.Null);
            Assert.That(ftRoute.ExperimentalRouteProperties.DataTokens, Is.Null);
            Assert.That(ftRoute.ExperimentalRouteProperties.RouteHandler, Is.InstanceOf <MvcRouteHandler>());
        }
        public void FeatureToggleRouteBuilderTest_MvcToMvc()
        {
            var defaultsCurrent = new RouteValueDictionary()
            {
                { "culture", "en-US" }, { "controller", "Home" }, { "action", "Index" }
            };
            var defaultsConstraints = new RouteValueDictionary()
            {
                { "id", @"\d+" }
            };
            var defaultDataTokens = new RouteValueDictionary()
            {
                { "route-name", "test" }
            };
            var experimentalDefaults = new RouteValueDictionary()
            {
                { "controller", "HomeV2" }, { "action", "Index" }
            };

            var route = FeatureToggleRouteBuilder.WithUrl("test")
                        .WithFeatureToogle((r) => true)
                        .WithCurrentMvcRoute(defaultsCurrent, defaultsConstraints, defaultDataTokens)
                        .WithExperimentalMvcRoute(experimentalDefaults)
                        .Build();

            Assert.That(route, Is.Not.Null);
            Assert.That(route, Is.InstanceOf <FeatureToggleRoute>());

            var ftRoute = (FeatureToggleRoute)route;

            Assert.That(ftRoute.RouteHandler, Is.Null);

            Assert.That(ftRoute.CurrentRouteProperties.Defaults, Is.EqualTo(defaultsCurrent));
            Assert.That(ftRoute.CurrentRouteProperties.Constraints, Is.EqualTo(defaultsConstraints));
            Assert.That(ftRoute.CurrentRouteProperties.DataTokens, Is.EqualTo(defaultDataTokens));
            Assert.That(ftRoute.CurrentRouteProperties.RouteHandler, Is.InstanceOf <MvcRouteHandler>());

            Assert.That(ftRoute.ExperimentalRouteProperties.Defaults, Is.EqualTo(experimentalDefaults));
            Assert.That(ftRoute.ExperimentalRouteProperties.Constraints, Is.Null);
            Assert.That(ftRoute.ExperimentalRouteProperties.DataTokens, Is.Null);
            Assert.That(ftRoute.ExperimentalRouteProperties.RouteHandler, Is.InstanceOf <MvcRouteHandler>());
        }
 public void FeatureToggleRouteBuilderTest_WithFeatureToggleNull_Throws()
 {
     Assert.That(() => FeatureToggleRouteBuilder.WithUrl("test").WithFeatureToogle(null), Throws.InstanceOf <ArgumentNullException>());
 }
 public void FeatureToggleRouteBuilderTest_WithUrlNullOrEmpty_Throws()
 {
     Assert.That(() => FeatureToggleRouteBuilder.WithUrl(null), Throws.InstanceOf <ArgumentNullException>());
     Assert.That(() => FeatureToggleRouteBuilder.WithUrl(string.Empty), Throws.InstanceOf <ArgumentNullException>());
 }