Exemplo n.º 1
0
        private async Task<List<ApplicationHealthModel>> CreateApplicationHealthModelTasksAsync(IList<Models.PathModel> paths)
        {
            var bearerToken = User.Identity.IsAuthenticated ? await bearerTokenRetriever.GetToken(HttpContext).ConfigureAwait(false) : null;

            var applicationHealthModels = new List<ApplicationHealthModel>();

            foreach (var path in paths)
            {
                logger.LogInformation($"{nameof(Action)}: Getting child Health for: {path.Path}");

                var applicationBaseUrl = await GetPathBaseUrlFromBodyRegionAsync(path.Path).ConfigureAwait(false);

                var applicationHealthModel = new ApplicationHealthModel
                {
                    Path = path.Path,
                    BearerToken = bearerToken,
                    HealthUrl = $"{applicationBaseUrl}/health",
                };

                applicationHealthModel.RetrievalTask = applicationHealthService.GetAsync(applicationHealthModel);

                applicationHealthModels.Add(applicationHealthModel);
            }

            return applicationHealthModels;
        }
Exemplo n.º 2
0
        public SitemapControllerTests()
        {
            defaultPathDataService = A.Fake <IPathDataService>();
            defaultLogger          = A.Fake <ILogger <SitemapController> >();
            defaultBaseUrlService  = A.Fake <IBaseUrlService>();

            var pathModels = new List <PathModel>
            {
                new PathModel
                {
                    SitemapURL = "http://SomeSitemapUrl.xyz",
                    IsOnline   = true,
                },
            };

            A.CallTo(() => defaultPathDataService.GetPaths()).Returns(pathModels);

            var user = A.Fake <ClaimsPrincipal>();

            A.CallTo(() => user.Identity.IsAuthenticated).Returns(true);

            defaultHttpContext = A.Fake <HttpContext>();
            defaultHttpContext.Request.Scheme = DummyScheme;
            defaultHttpContext.Request.Host   = new HostString(DummyHost);

            var fakeIdentity = new GenericIdentity("User");
            var principal    = new GenericPrincipal(fakeIdentity, null);

            A.CallTo(() => defaultHttpContext.User).Returns(principal);

            defaultUrlHelper = A.Fake <IUrlHelper>();
            A.CallTo(() => defaultUrlHelper.Action(A <UrlActionContext> .Ignored)).Returns(DummyHomeIndex);

            defaultTokenRetriever = A.Fake <IBearerTokenRetriever>();
            A.CallTo(() => defaultTokenRetriever.GetToken(A <HttpContext> .Ignored)).Returns("SomeToken");

            A.CallTo(() => defaultBaseUrlService.GetBaseUrl(A <HttpRequest> .Ignored, A <IUrlHelper> .Ignored))
            .Returns("http://SomeBaseUrl");

            defaultSitemapService = A.Fake <IApplicationSitemapService>();
            A.CallTo(() => defaultSitemapService.GetAsync(A <ApplicationSitemapModel> .Ignored))
            .Returns(Task.FromResult <IEnumerable <SitemapLocation> >(new List <SitemapLocation>()
            {
                new SitemapLocation
                {
                    Url      = "http://Sitemap.xml",
                    Priority = 1,
                },
            }));

            defaultController = new SitemapController(defaultPathDataService, defaultLogger, defaultTokenRetriever, defaultBaseUrlService, defaultSitemapService)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = defaultHttpContext,
                },
                Url = defaultUrlHelper,
            };
        }
        public RobotControllerTests()
        {
            defaultAppRegistryDataService = A.Fake <IAppRegistryDataService>();
            defaultLogger             = A.Fake <ILogger <RobotController> >();
            defaultWebHostEnvironment = A.Fake <IWebHostEnvironment>();
            defaultBaseUrlService     = A.Fake <IBaseUrlService>();

            var appRegistrationModels = new List <AppRegistrationModel>
            {
                new AppRegistrationModel
                {
                    RobotsURL = new Uri("http://SomeRobotUrl.xyz", UriKind.Absolute),
                    IsOnline  = true,
                },
            };

            A.CallTo(() => defaultAppRegistryDataService.GetAppRegistrationModels()).Returns(appRegistrationModels);

            var user = A.Fake <ClaimsPrincipal>();

            A.CallTo(() => user.Identity.IsAuthenticated).Returns(true);

            defaultHttpContext = A.Fake <HttpContext>();
            defaultHttpContext.Request.Scheme = DummyScheme;
            defaultHttpContext.Request.Host   = new HostString(DummyHost);

            var fakeIdentity = new GenericIdentity("User");
            var principal    = new GenericPrincipal(fakeIdentity, null);

            A.CallTo(() => defaultHttpContext.User).Returns(principal);

            defaultUrlHelper = A.Fake <IUrlHelper>();
            A.CallTo(() => defaultUrlHelper.Content(A <string> .Ignored)).Returns("DummyUrl");
            A.CallTo(() => defaultUrlHelper.RouteUrl(A <UrlRouteContext> .Ignored)).Returns(DummySitemapUrl);

            defaultTokenRetriever = A.Fake <IBearerTokenRetriever>();
            A.CallTo(() => defaultTokenRetriever.GetToken(A <HttpContext> .Ignored)).Returns("SomeToken");

            defaultApplicationRobotService = A.Fake <IApplicationRobotService>();
            A.CallTo(() => defaultApplicationRobotService.GetAsync(A <ApplicationRobotModel> .Ignored)).Returns("RetrievedValue: SomeValue");

            defaultShellRobotFileService = A.Fake <IShellRobotFileService>();
            A.CallTo(() => defaultShellRobotFileService.GetStaticFileText(A <string> .Ignored)).Returns("{Insertion}");

            defaultController = new RobotController(defaultAppRegistryDataService, defaultLogger, defaultWebHostEnvironment, defaultTokenRetriever, defaultApplicationRobotService, defaultShellRobotFileService, defaultBaseUrlService)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = defaultHttpContext,
                },
                Url = defaultUrlHelper,
            };
        }
Exemplo n.º 4
0
        private async Task <List <ApplicationSitemapModel> > CreateApplicationSitemapModelTasksAsync(IList <Models.PathModel> paths)
        {
            var bearerToken = User.Identity.IsAuthenticated ? await bearerTokenRetriever.GetToken(HttpContext).ConfigureAwait(false) : null;

            var applicationSitemapModels = new List <ApplicationSitemapModel>();

            foreach (var path in paths)
            {
                logger.LogInformation($"{nameof(Action)}: Getting child Sitemap for: {path.Path}");

                var applicationSitemapModel = new ApplicationSitemapModel
                {
                    Path        = path.Path,
                    BearerToken = bearerToken,
                    SitemapUrl  = path.SitemapURL,
                };

                applicationSitemapModel.RetrievalTask = sitemapService.GetAsync(applicationSitemapModel);

                applicationSitemapModels.Add(applicationSitemapModel);
            }

            return(applicationSitemapModels);
        }
Exemplo n.º 5
0
        private async Task <List <ApplicationRobotModel> > CreateApplicationRobotModelTasksAsync(IEnumerable <AppRegistrationModel> appRegistrationModel)
        {
            var bearerToken = User.Identity.IsAuthenticated ? await bearerTokenRetriever.GetToken(HttpContext).ConfigureAwait(false) : null;

            var applicationRobotModels = new List <ApplicationRobotModel>();

            foreach (var path in appRegistrationModel)
            {
                logger.LogInformation($"{nameof(Action)}: Getting child robots.txt for: {path.Path}");

                var applicationRobotModel = new ApplicationRobotModel
                {
                    Path        = path.Path,
                    RobotsURL   = path.RobotsURL.ToString(),
                    BearerToken = bearerToken,
                };

                applicationRobotModel.RetrievalTask = applicationRobotService.GetAsync(applicationRobotModel);

                applicationRobotModels.Add(applicationRobotModel);
            }

            return(applicationRobotModels);
        }