public async Task RouteAnUnknownIntentToTheDefaultHandler()
        {
            string defaultRouteUri = $"http://{string.Empty.GetRandom()}";

            var cmdProcessor = new Mock <ICommandProcessor>(MockBehavior.Loose);

            var routes = new RouteCollectionBuilder(defaultRouteUri)
                         .Add(string.Empty.GetRandom(), string.Empty.GetRandom())
                         .Add(string.Empty.GetRandom(), string.Empty.GetRandom())
                         .Add(string.Empty.GetRandom(), string.Empty.GetRandom())
                         .Build().AsJsonString();
            var routeCollection = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("intentRoutes", routes)
            };
            var config = new ConfigurationBuilder().AddInMemoryCollection(routeCollection).Build();

            var containerBuilder = new Autofac.ContainerBuilder();

            containerBuilder.RegisterInstance <ICommandProcessor>(cmdProcessor.Object);
            containerBuilder.RegisterInstance <IConfiguration>(config);
            var serviceProvider = new AutofacServiceProvider(containerBuilder.Build());

            var request = new UserRequestBuilder().Random().Build();
            var target  = new ConfigRouter.Engine(serviceProvider);
            var actual  = await target.HandleRequestAsync(request);

            cmdProcessor.Verify(p => p.ProcessAsync(defaultRouteUri, It.IsAny <UserRequest>()), Times.Once);
        }
Ejemplo n.º 2
0
        public void ThrowsADuplicateRouteExceptionIfAnotherRouteNamedDefaultIsAdded()
        {
            var target = new RouteCollectionBuilder(string.Empty.GetRandom());

            Assert.Throws <Exceptions.DuplicateRouteException>(() =>
                                                               target
                                                               .Add(string.Empty.GetRandom(), string.Empty.GetRandom())
                                                               .Add("default", string.Empty.GetRandom())
                                                               .Build());
        }
Ejemplo n.º 3
0
        public void ReturnACollectionWithARouteWithTheSpecifiedName()
        {
            string expectedName = string.Empty.GetRandom();
            string expectedUri  = $"http://{string.Empty.GetRandom()}";

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());
            var actual = target
                         .Add(expectedName, expectedUri)
                         .Build();

            Assert.Equal(1, actual.Count(c => c.IntentName == expectedName));
        }
Ejemplo n.º 4
0
        public void ReturnTheCorrectUriForARouteInTheMiddleOfALargeNumberOfRoutes()
        {
            var expectedCountPart1 = 99.GetRandom(3);
            var expectedCountPart2 = 99.GetRandom(3);
            var expectedCountPart3 = 99.GetRandom(3);

            string expectedName1 = string.Empty.GetRandom();
            string expectedName2 = string.Empty.GetRandom();

            string expectedUri1 = $"http://{string.Empty.GetRandom()}";
            string expectedUri2 = $"http://{string.Empty.GetRandom()}";

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());

            for (int i = 0; i < expectedCountPart1; i++)
            {
                target.Add(string.Empty.GetRandom(), string.Empty.GetRandom());
                target.Add(new Entities.IntentRoute()
                {
                    IntentName = string.Empty.GetRandom(), Uri = string.Empty.GetRandom()
                });
            }

            target.Add(new Entities.IntentRoute()
            {
                IntentName = expectedName1, Uri = expectedUri1
            });

            for (int i = 0; i < expectedCountPart2; i++)
            {
                target.Add(new Entities.IntentRoute()
                {
                    IntentName = string.Empty.GetRandom(), Uri = string.Empty.GetRandom()
                });
                target.Add(string.Empty.GetRandom(), string.Empty.GetRandom());
            }

            target.Add(expectedName2, expectedUri2);

            for (int i = 0; i < expectedCountPart2; i++)
            {
                target.Add(new Entities.IntentRoute()
                {
                    IntentName = string.Empty.GetRandom(), Uri = string.Empty.GetRandom()
                });
                target.Add(string.Empty.GetRandom(), string.Empty.GetRandom());
            }

            var actual = target.Build();

            Assert.Equal(expectedUri1, actual.Single(c => c.IntentName == expectedName1).Uri);
            Assert.Equal(expectedUri2, actual.Single(c => c.IntentName == expectedName2).Uri);
        }
Ejemplo n.º 5
0
        public void ReturnTheCorrectUriForTheRouteWithTheSpecifiedName()
        {
            string expectedName = string.Empty.GetRandom();
            string expectedUri  = $"http://{string.Empty.GetRandom()}";

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());
            var actual = target
                         .Add(expectedName, expectedUri)
                         .Build();

            var actualRoute = actual.Single(c => c.IntentName == expectedName);

            Assert.Equal(expectedUri, actualRoute.Uri);
        }
Ejemplo n.º 6
0
        public void ReturnACollectionWithTheCorrectNumberOfRoutes()
        {
            var expectedCount = 99.GetRandom(3);

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());

            for (int i = 0; i < expectedCount; i++)
            {
                target.Add(string.Empty.GetRandom(), string.Empty.GetRandom());
            }

            var actual = target.Build();

            Assert.Equal(expectedCount + 1, actual.Count());
        }
Ejemplo n.º 7
0
        public void ReturnACollectionWithARouteWithTheSpecifiedNameSubmittedAsObject()
        {
            string expectedName = string.Empty.GetRandom();
            string expectedUri  = $"http://{string.Empty.GetRandom()}";
            var    newRoute     = new Entities.IntentRoute()
            {
                IntentName = expectedName, Uri = expectedUri
            };

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());
            var actual = target
                         .Add(newRoute)
                         .Build();

            Assert.Equal(1, actual.Count(c => c.IntentName == expectedName));
        }
Ejemplo n.º 8
0
        public void ThrowsADuplicateRouteExceptionIfADuplicateNameIsSubmittedUsingObject()
        {
            string expectedName = string.Empty.GetRandom();

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());

            Assert.Throws <Exceptions.DuplicateRouteException>(() =>
                                                               target
                                                               .Add(expectedName, string.Empty.GetRandom())
                                                               .Add(string.Empty.GetRandom(), string.Empty.GetRandom())
                                                               .Add(new Entities.IntentRoute()
            {
                IntentName = expectedName, Uri = string.Empty.GetRandom()
            })
                                                               .Build());
        }
Ejemplo n.º 9
0
        public void ReturnACollectionWithTheCorrectNumberOfRoutesSubmittedInDifferentWays()
        {
            var halfExpectedCount = 99.GetRandom(3);

            var target = new RouteCollectionBuilder(string.Empty.GetRandom());

            for (int i = 0; i < halfExpectedCount; i++)
            {
                target.Add(string.Empty.GetRandom(), string.Empty.GetRandom());
                target.Add(new Entities.IntentRoute()
                {
                    IntentName = string.Empty.GetRandom(), Uri = string.Empty.GetRandom()
                });
            }

            var actual = target.Build();

            Assert.Equal((halfExpectedCount * 2) + 1, actual.Count());
        }
        public async Task RouteAnKnownIntentToTheProperHandler()
        {
            string intentName = string.Empty.GetRandom();
            string routeUri   = $"http://{string.Empty.GetRandom()}";

            var cmdProcessor = new Mock <ICommandProcessor>(MockBehavior.Loose);

            var containerBuilder = new Autofac.ContainerBuilder();

            containerBuilder.RegisterInstance <ICommandProcessor>(cmdProcessor.Object);
            var serviceProvider = new AutofacServiceProvider(containerBuilder.Build());

            var routes  = new RouteCollectionBuilder(string.Empty.GetRandom()).Add(intentName, routeUri).Build();
            var intent  = new IntentBuilder().Random().AddName(intentName);
            var request = new UserRequestBuilder().Random().AddIntent(intent).Build();

            var target = new SoftRouter.Engine(serviceProvider, routes);
            var actual = await target.HandleRequestAsync(request);

            cmdProcessor.Verify(p => p.ProcessAsync(routeUri, It.IsAny <UserRequest>()), Times.Once);
        }
Ejemplo n.º 11
0
        public void Configuration(IAppBuilder app)
        {
            var httpConfig = new HttpConfiguration();

            ConfigureWebApi(httpConfig);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Trace(LogEventLevel.Debug)
                         .WriteTo.LiterateConsole(LogEventLevel.Debug)
                         .WriteTo.DocSet("XtricateTestSqlDb", "StorageTests", LogEventLevel.Information)
                         .Enrich.WithProperty("App", "SampleApp")
                         .Enrich.FromLogContext()
                         .CreateLogger();

            Log.Debug("started");

            app.UseDashboard(
                options: new DashboardOptions
            {
                MenuRoutes = new[] { "/products", "/vuejspoc" }
            },
                routes: new RouteCollectionBuilder(
                    new Dictionary <string, IRequestDispatcher>
            {
                {
                    "/products",
                    new TemplateRequestDispatcher(
                        x => new ProductIndex {
                        Culture = CultureInfo.GetCultureInfo("de-DE")
                    })
                },
                {
                    "/products/(?<PageId>\\d+)",
                    new TemplateRequestDispatcher(x => new ProductDetails
                    {
                        Culture    = CultureInfo.GetCultureInfo("de-DE"),
                        Parameters = new Dictionary <string, string>
                        {
                            { "id", x.Groups["PageId"].Value }
                        }
                    })
                },
                {
                    "/vuejspoc",
                    new TemplateRequestDispatcher(
                        x => new VueJsPoc())
                },
                {
                    @"/_ts/(?<ScriptName>\S+)",
                    new ResourceRequestDispatcher(x => new ResourceDispatcher("application/typescript",
                                                                              RouteCollectionBuilder.GetPagesFolderNamespace(typeof(Root)) + "." +
                                                                              x.Groups["ScriptName"].Value + ".ts")) // , typeof (Root).Assembly
                },
                //{
                //    @"/_js/(?<ScriptName>\S+)",
                //    new ResourceRequestDispatcher(x => new ResourceDispatcher("application/javascript",
                //        RouteCollectionBuilder.GetPagesFolderNamespace(typeof (Root)) + "." +
                //        x.Groups["ScriptName"].Value + ".js")) // , typeof (Root).Assembly
                //},
                {
                    "/js-treegrid", new ResourceCollectionDispatcher(
                        "application/javascript",
                        RouteCollectionBuilder.GetResourcesFolderNamespace(typeof(Root), "js"),
                        typeof(Root).Assembly, "jquery.treegrid.min.js", "jquery.treegrid.bootstrap3.js")
                },
                {
                    "/css-treegrid", new ResourceCollectionDispatcher(
                        "text/css",
                        RouteCollectionBuilder.GetResourcesFolderNamespace(typeof(Root), "css"),
                        typeof(Root).Assembly, "jquery.treegrid.css")
                }
            }).Routes);
            app.UseWebApi(httpConfig);
        }